void appendElementWithText( DOMNode* cur, DOMNode* reply,
                            const char* name, const char* text,
                            int indentLevel, bool indent,
                            attrVect* attribute ) {

   MC2String indentStr( indentLevel*3, ' ' );
   indentStr.insert( 0, "\n" );   
   DOMDocument* doc = XMLTool::getOwner( reply );
   DOMElement* textElement = doc->createElement( X( name ) );
   if ( text != NULL ) {
      textElement->appendChild( doc->createTextNode( X( text ) ) );
   }

   if ( attribute != NULL ) {
      for ( uint32 i = 0 ; i < attribute->size() ; ++i ) {
         textElement->setAttribute( X( (*attribute)[ i ].first ), 
                                    X( (*attribute)[ i ].second ) );
      }
   }

   // Add textElement to cur
   if ( indent ) {
      cur->appendChild( doc->createTextNode( X( indentStr.c_str() ) ) );
   }
   cur->appendChild( textElement );
}
Exemplo n.º 2
0
void MeaXMLNode::Dump() const
{
    static int indent = 0;

    CString indentStr(_T(' '), indent);

    TRACE(_T("%sNode Type: "), (LPCTSTR)indentStr);
    switch (m_type) {
    case Unknown:
        TRACE(_T("Unknown\n"));
        break;
    case Element:
        TRACE(_T("Element - %s\n"), m_data);
        break;
    case Data:
        TRACE(_T("Data - '%s'\n"), m_data);
        break;
    }

    for (NodeIter_c iter = GetChildIter(); !AtEnd(iter); ++iter) {
        indent += 4;
        (*iter)->Dump();
        indent -= 4;
    }
}
void 
appendStatusNodes( DOMNode* out, 
                   DOMDocument* reply,
                   int indentLevel,
                   bool indent,
                   const char* const code,
                   const char* const message,
                   const char* extendedCode,
                   const char* uri ) {

   MC2String indentStr( indentLevel*3, ' ' );
   indentStr.insert( 0, "\n" );
   XStr XindentStr( indentStr.c_str() );

   // Fill in status_code and status_message in out

   DOMElement* status_code = reply->createElement( X( "status_code" ) );
   status_code->appendChild( reply->createTextNode( X( code ) ) );
   if ( indent ) {
      // Newline
      out->appendChild( reply->createTextNode( XindentStr.XMLStr() ) );
   }
   out->appendChild( status_code );


   DOMElement* status_message = reply->
      createElement( X( "status_message" ) );

   status_message->appendChild( reply->createTextNode( X( message ) ) );
   if ( indent ) {
      // Newline
      out->appendChild( reply->createTextNode( XindentStr.XMLStr() ) );
   }
   out->appendChild( status_message );

   if ( extendedCode != NULL ) {
      DOMElement* status_code_extended = reply->createElement( 
         X( "status_code_extended" ) );
      status_code_extended->appendChild( 
         reply->createTextNode( X( extendedCode ) ) );
      if ( indent ) {
         // Newline
         out->appendChild( reply->createTextNode( XindentStr.XMLStr() ) );
      }
      out->appendChild( status_code_extended );
   }

   if ( uri != NULL && *uri ) {
      DOMElement* status_uri = reply->createElement( X( "status_uri" ) );
      status_uri->setAttribute( X( "href" ), X( uri ) );
      if ( indent ) {
         // Newline
         out->appendChild( reply->createTextNode( XindentStr.XMLStr() ) );
      }
      out->appendChild( status_uri );
   }
}
Exemplo n.º 4
0
void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const
{
    s += "[";
    if (prettyIndent)
        s += "\n";

    for (unsigned int i = 0; i < values.size(); i++) {
        if (prettyIndent)
            indentStr(prettyIndent, indentLevel, s);
        s += values[i].write(prettyIndent, indentLevel + 1);
        if (i != (values.size() - 1)) {
            s += ",";
        }
        if (prettyIndent)
            s += "\n";
    }

    if (prettyIndent)
        indentStr(prettyIndent, indentLevel - 1, s);
    s += "]";
}
Exemplo n.º 5
0
void XMLreader::print(int indent) const {
    std::string indentStr(indent, ' ');
    pcout << indentStr << "[" << name << "]" << std::endl;
    std::string text = getFirstText();
    if (!text.empty()) {
        pcout << indentStr << "  " << text << std::endl;
    }
    std::vector<XMLreader*> const& children = data_map.begin()->second.children;
    for (pluint iNode=0; iNode<children.size(); ++iNode) {
        children[iNode]->print(indent+2);
    }
}
void appendElement( DOMNode* cur, DOMDocument* reply,
                    const char* name, 
                    int indentLevel, bool indent ) {
   MC2String indentStr( indentLevel*3, ' ' );
   indentStr.insert( 0, "\n" );   

   DOMElement* textElement = reply->createElement( X( name ) );

   // Add textElement to cur
   if ( indent ) {
      cur->appendChild( reply->createTextNode( X( indentStr.c_str() ) ) );
   }
   cur->appendChild( textElement );
}
Exemplo n.º 7
0
void UniValue::writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const
{
    s += "{";
    if (prettyIndent)
        s += "\n";

    for (unsigned int i = 0; i < keys.size(); i++) {
        if (prettyIndent)
            indentStr(prettyIndent, indentLevel, s);
        s += "\"" + json_escape(keys[i]) + "\":";
        if (prettyIndent)
            s += " ";
        s += values.at(i).write(prettyIndent, indentLevel + 1);
        if (i != (values.size() - 1))
            s += ",";
        if (prettyIndent)
            s += "\n";
    }

    if (prettyIndent)
        indentStr(prettyIndent, indentLevel - 1, s);
    s += "}";
}
Exemplo n.º 8
0
void SourceEdit::keyPressEvent(QKeyEvent * event)
{
    QTextEdit::keyPressEvent(event);
    if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
    {
        QTextCursor cursor = this->textCursor();
        QTextBlock prevBlock = cursor.block().previous();
        if (prevBlock.isValid()) {
            QString text = prevBlock.text();
            QString indentStr("");
            for (int n = 0; text[n].isSpace(); n++)
                indentStr += text[n];

            // increase indent
            text = text.trimmed();
            QRegExp rx("^(if|else|while|for).*");
            if (text.endsWith('{') || rx.exactMatch(text))
                indentStr += '\t';
            cursor.insertText(indentStr);
        }
    }
    else if (event->key() == Qt::Key_BraceRight)
    {
        // decrease indent
        QTextCursor cursor = this->textCursor();
        cursor.movePosition(QTextCursor::Left);
        if (cursor.block().text().endsWith("\t}"))
            cursor.deletePreviousChar();
    }
    else if (event->key() == Qt::Key_BraceLeft)
    {
        // decrease indent
        QTextCursor cursor = this->textCursor();
        cursor.movePosition(QTextCursor::Left);
        if (cursor.block().text().endsWith("\t{"))
            cursor.deletePreviousChar();		
    }
}
bool
XMLParserThread::xmlParseSMSFormatRequest( DOMNode* cur, 
                                           DOMNode* out,
                                           DOMDocument* reply,
                                           bool indent )
try {
   bool ok = true;
   int indentLevel = 1;

   MC2String indentStr( indentLevel*3, ' ' );
   indentStr.insert( 0, "\n" );
   XStr XindentStr( indentStr.c_str() );

   bool smsMessage = false;
   bool routeMessage = false;
   bool wayfinderRouteSMS = false;
   bool wayfinderDestinationSMS = false;
   bool wayfinderFavouriteSMS = false;
   char* smsMessageText = NULL;
   char* phoneModelName = NULL;
   char* phoneManufacturerName = NULL;
   uint32 routeID = 0;
   uint32 routeCreateTime = 0;
   StringTable::languageCode language = StringTable::ENGLISH;
   char* signature = NULL;
   char* originString = NULL;
   char* originLocationString = NULL;
   char* destinationString = NULL;
   char* destinationLocationString = NULL;
   CellularPhoneModel* model = NULL; // For routeMessage
   bool wapLink = false; // For routeMessage
   int32 wayfinderSMSVersion = MAX_INT32;
   int32 wayfinderOriginLat = MAX_INT32;
   int32 wayfinderOriginLon = MAX_INT32;
   int32 wayfinderDestinationLat = MAX_INT32;
   int32 wayfinderDestinationLon = MAX_INT32;
   MC2String wayfinderOriginDescription;
   MC2String wayfinderDestinationDescription;
   MC2String errorCode = "-1";
   MC2String errorMessage = "Failed to handle request.";
   int32 wayfinderFavouriteLat;
   int32 wayfinderFavouriteLon;
   MC2String wayfinderFavouriteName;
   MC2String wayfinderFavouriteShortName;
   MC2String wayfinderFavouriteDescription;
   MC2String wayfinderFavouriteCategory;
   MC2String wayfinderFavouriteMapIconName;
   // Create sms_format_reply element
   DOMElement* sms_format_reply = 
      reply->createElement( X( "sms_format_reply" ) );
   // Transaction ID
   sms_format_reply->setAttribute( 
      X( "transaction_id" ), cur->getAttributes()->getNamedItem( 
         X( "transaction_id" ) )->getNodeValue() );
   out->appendChild( sms_format_reply );
   if ( indent ) {
      // Newline
      out->insertBefore( reply->createTextNode( XindentStr.XMLStr() ), 
                         sms_format_reply );
   }
   
   // Look for Wayfinder sms version
   DOMNamedNodeMap* attributes = cur->getAttributes();
   DOMNode* attribute;
   for ( uint32 i = 0 ; i < attributes->getLength() ; i++ ) {
      attribute = attributes->item( i );
      if ( XMLString::equals( attribute->getNodeName(),
                              "wayfinder_sms_version" ) ) {
         MC2String tmpStr = 
            XMLUtility::transcodefrom( attribute->getNodeValue() );
         wayfinderSMSVersion = atoi( tmpStr.c_str() );
      }
   }

   XMLSMSCommon::InviteData inviteData; // for invite_sms

   XMLSMSCommon::PlaceSMSData placeData; // for place_sms

   for ( DOMNode* child = cur->getFirstChild();
         child != NULL && ok; 
         child = child->getNextSibling() ) {
      if ( child->getNodeType() != DOMNode::ELEMENT_NODE ) {
         continue;
      }
      // See if the element is a known type
      if ( XMLString::equals( child->getNodeName(), "smsmessage" ) ) {
         smsMessageText = XMLUtility::getChildTextValue( child );
         smsMessage = true;
      } else if ( XMLString::equals( child->getNodeName(),
                                     "phone_manufacturer" ) ) {
         phoneManufacturerName = 
            XMLUtility::getChildTextValue( child );
      } else if ( XMLString::equals( child->getNodeName(),
                                     "phone_model" ) ) {
         phoneModelName = XMLUtility::getChildTextValue( child );
      } else if ( XMLString::equals( child->getNodeName(),
                                     "route_sms_message" ) ) {
         routeMessage = 
            xmlParseSendSMSRequestRouteSMSMessage( child, model, wapLink );
      } else if ( XMLString::equals( child->getNodeName(),
                                     "route_message_data" ) ) {
         routeMessage = 
            XMLSMSCommon::
            xmlParseSendSMSRequestRouteMessageData( child, 
                                                    routeID,
                                                    routeCreateTime,
                                                    language,
                                                    signature,
                                                    originString,
                                                    originLocationString,
                                                    destinationString,
                                                    destinationLocationString );

      } else if( XMLString::equals( child->getNodeName(),
                                    "wayfinder_route_sms" ) ) {
         wayfinderRouteSMS = 
            XMLSMSCommon::
            xmlParseWayfinderSMS( child, signature,
                                  wayfinderOriginLat,
                                  wayfinderOriginLon,
                                  wayfinderOriginDescription,
                                  wayfinderDestinationLat,
                                  wayfinderDestinationLon,
                                  wayfinderDestinationDescription,
                                  errorCode, errorMessage );
         if ( ! wayfinderRouteSMS ) {
            ok = false;
            // errorCode and errorMessage is set by 
            // xmlParseWayfinderSMS
            mc2log << warn << "XMLParserThread::"
                   << "xmlParseSendSMSRequest failed to parse "
                   << "wayfinder_route_sms." << endl;
         }              
      } else if ( XMLString::equals( child->getNodeName(),
                                     "wayfinder_destination_sms" ) ) {
         wayfinderDestinationSMS = 
            XMLSMSCommon::
            xmlParseWayfinderSMS( child, signature,
                                  wayfinderOriginLat, wayfinderOriginLon,
                                  wayfinderOriginDescription,
                                  wayfinderDestinationLat, 
                                  wayfinderDestinationLon,
                                  wayfinderDestinationDescription, 
                                  errorCode, errorMessage );
         if ( ! wayfinderDestinationSMS ) {
            ok = false;
            // errorCode and errorMessage is set by 
            // xmlParseWayfinderSMS
            mc2log << warn << "XMLParserThread::"
                   << "xmlParseSendSMSRequest failed to parse "
                   << "wayfinder_destination_sms." << endl;
         } 
      } else if( XMLString::equals( child->getNodeName(),
                                    "wayfinder_favourite_sms" ) ) {
         wayfinderFavouriteSMS = 
            XMLSMSCommon::
            xmlParseWayfinderFavouriteSMS( child, signature,
                                           wayfinderFavouriteLat,
                                           wayfinderFavouriteLon,
                                           wayfinderFavouriteName,
                                           wayfinderFavouriteShortName,
                                           wayfinderFavouriteDescription,
                                           wayfinderFavouriteCategory,
                                           wayfinderFavouriteMapIconName,
                                           errorCode, errorMessage );
         if( ! wayfinderFavouriteSMS ) {
            // errorCode and errorMessage is set by 
            // xmlParseWayfinderFavouriteSMS
            mc2log << warn << "XMLParserThread::"
                   << "xmlParseSMSFormatRequest failed to parse "
                   << "wayfinder_favourite_sms." << endl;
         }
      } else if ( XMLString::equals( child->getNodeName(),
                                     "invite_sms" ) ) {
         XMLTool::getAttribValue( inviteData.m_type, "type", child );
         XMLTool::getNodeValue( inviteData.m_name, "name", child );
      } else if ( XMLString::equals( child->getNodeName(),
                                     "place_sms" ) ) {
         ok = parsePlaceSMS( placeData, child, errorCode, errorMessage );
      } else {
         mc2log << warn << "XMLParserThread::"
            "xmlParseSMSFormatRequest "
            "odd Element in sms_format_request element: "
                << child->getNodeName() << endl;
      }
   }

   
   // Handle request
   if ( ok ) {
      // The smses
      StringVector* smsVector = new StringVector();

      if ( smsMessage ) {
         // ExpandStringItemVector?
         ok = false;
         errorMessage = "Formating of smsmessage is not yet supported.";
      } else if ( routeMessage ) {
         if ( !wapLink ) {
            ok = handleRouteMessage( this, 
                                     routeID, routeCreateTime, 
                                     language,
                                     smsVector, model, signature, 
                                     errorMessage );
         } else {
            ok = handleWAPLinkSMS( this,
                                   routeID, routeCreateTime,
                                   language, smsVector,
                                   model, signature,
                                   errorMessage );
         }
         
         if ( ok ) {
            mc2log << info << "XMLParserThread::xmlParseSMSFormatRequest ";
            if ( !wapLink ) {
               mc2log << "routeID " << routeID << " routeCreateTime "
                      << routeCreateTime;
            } else {
               mc2log << "wapLink true";
            }
            mc2log << " signature " << signature << " model " 
                   << model->getName() 
                   << " nbrSMSes " << smsVector->getSize() << endl;

            // Add smses
            XMLSMSCommon::appendSMSList( sms_format_reply, reply, smsVector,
                                         indentLevel + 1, indent );
         } // Not ok handled below

      } else if ( wayfinderDestinationSMS || wayfinderRouteSMS ) {
         // Make sms data
         WayfinderSMSRequest* wayReq = new WayfinderSMSRequest( 
            getNextRequestID() );
         MC2Coordinate origin( wayfinderOriginLat, wayfinderOriginLon );
         MC2Coordinate dest( wayfinderDestinationLat,
                             wayfinderDestinationLon );
         wayReq->addMessage( 
            "DUMMY", "NO_WAY",
            origin,
            wayfinderOriginDescription.c_str(),
            dest,
            wayfinderDestinationDescription.c_str(),
            signature, wayfinderSMSVersion );
         smsVector->addLast( StringUtility::newStrDup( const_cast<char*>( 
            wayReq->getLastDestinationMessage() ) ) );
         // Add sms
         XMLSMSCommon::appendSMSList( sms_format_reply, reply, smsVector,
                                      indentLevel + 1, indent );

         delete wayReq;
      } else if( wayfinderFavouriteSMS ) {
         // Make sms data
         WayfinderSMSRequest* wayReq = new WayfinderSMSRequest(
            getNextRequestID() );
         
         MC2Coordinate coord( wayfinderFavouriteLat, wayfinderFavouriteLon );

         wayReq->addFavouriteMessage( "DUMMY", "NO_WAY",
                                      coord,
                                      wayfinderFavouriteName,
                                      wayfinderFavouriteShortName,
                                      wayfinderFavouriteDescription,
                                      wayfinderFavouriteCategory,
                                      wayfinderFavouriteMapIconName,
                                      signature,
                                      wayfinderSMSVersion );
         smsVector->addLast( StringUtility::newStrDup( const_cast<char*>( 
            wayReq->getLastDestinationMessage() ) ) );
         // Add sms
         XMLSMSCommon::appendSMSList( sms_format_reply, reply, smsVector,
                                      indentLevel + 1, indent );
         delete wayReq;
      } else if ( !inviteData.m_type.empty() ) { 
         XMLSMSCommon::
            composeInviteSMS( sms_format_reply, reply, indentLevel + 1, indent,
                              getCurrentUser(), inviteData );
      } else if ( ! placeData.m_type.empty() ) {
         XMLSMSCommon::
            composePlaceSMS( *this,
                             sms_format_reply, reply, indentLevel + 1, indent,
                             getCurrentUser(), placeData );
      } else {
         // Couldn't get all needed indata
         ok = false;
         errorMessage = "Couldn't get all needed indata.";
      }

      if ( ok ) {
         mc2log << info << "SMSFormat: OK " << smsVector->getSize()
                << " SMSes ";
         if ( smsVector->getSize() > 0 ) {
            mc2log << "Last " << smsVector->getElementAt( 0 );
         }
         mc2log << endl;
      } // Error printed below

      smsVector->deleteAllObjs();
      delete smsVector;

   } // Not ok handled below

   if ( ! ok ) {
      mc2log << info << "SMSFormat: Error " << errorCode << ","
             << errorMessage << endl;
      // Error 
      XMLServerUtility::
         appendStatusNodes( sms_format_reply, reply, indentLevel + 1, indent,
                            errorCode.c_str(), errorMessage.c_str() );
      // Error handled
      ok = true;
   }

   if ( indent ) {
      // Newline and indent before end sms_format_reply tag   
      sms_format_reply->appendChild( 
         reply->createTextNode( XindentStr.XMLStr() ) );
   }
 
   delete [] smsMessageText;
   delete [] phoneModelName;
   delete [] phoneManufacturerName;
   delete [] signature;
   delete [] originString;
   delete [] originLocationString;
   delete [] destinationString;
   delete [] destinationLocationString;
   delete model;

   return ok;
} catch ( const XMLTool::Exception& e ) {
   
   return false;
}
Exemplo n.º 10
0
//
// appendWithWrap(QString &message)  - append a msg to the current text
//
// Word wrap is performed to wrap messages and indent them according to
// the indentation configured
//
void
MsgDialog::appendWithWrap(QString &s)
{
  QFontMetrics fm( font() );
  int i = 0;
  int a = 0;
  int lastSpace = 0;
  int linew = 0;
  int lastw = 0;
  bool doBreak = FALSE;
  bool bWrap = FALSE;
  int indentw = 0;
  QString indentStr("                                         ");

  if (!m_pEdit) return;

#ifdef DEBUGMSG
//  qDebug("appendWithWrap() '%s'", s.ascii() );
#endif
  while( i<int(s.length()) ) 
  {
    doBreak = FALSE;
    if ( s[i] != '\n' )
    {
      linew += fm.width( s[i] );
      if (lastSpace > a)
      {
        if ( (linew + indentw + 10) >= m_pEdit->contentsRect().width())
        {
          doBreak = TRUE;
          if (lastSpace > a)
          {
            i = lastSpace;
            linew = lastw;
          }
          else
            i = QMAX(a, i-1);
        }
      }
    }
//printf("doBreak %d, a %d, i %d\n", doBreak, a, i); 
    if (doBreak)
    {
       QString newstring = s.mid(a, i - a);

       linew = 0;
       lastSpace = a;
       if (bWrap)
         newstring.insert(0,indentStr.left(m_nIndent));
//printf("Adding '%s'\n", newstring.ascii());
       if (m_bUseIndexing)
       {
          QString index("");
          index.sprintf("%05d: ", m_nIndex);
          newstring.insert(0, index);
       }
       m_pEdit->append(newstring);
       bWrap = TRUE;
       indentw = m_nIndent * fm.width(s[32]); 
       a=i+1;
    }

    if (s[i].isSpace())
    {
       lastSpace = i;
       lastw = linew;
    }
    if (lastSpace <= a)
      lastw = linew;

    i++;
  }

  // add remainder of line
  QString newstring = s.mid(a, i - a);
  if (bWrap)
     newstring.insert(0,indentStr.left(m_nIndent));
  if (m_bUseIndexing)
  {
     QString index("");
     index.sprintf("%05d: ", m_nIndex);
     newstring.insert(0, index);
  }
  m_pEdit->append(newstring);
//printf("Adding '%s'\n", newstring.ascii());

} // end appendWithWrap