Ejemplo n.º 1
0
void CXercesUtils::DumpTree (DOMNode *tree, std::string &tmp)
{
  tabs+="\t";
  if (tree != NULL)
    {
		if (tree->getNodeType () != DOMNode::ELEMENT_NODE)
			goto leave;
		DOMElement*  e = (DOMElement* ) tree;
		std::string el_name =  XMLString::transcode(tree->getNodeName());

		std::string el_value;
		if(e->getTextContent () && e->getChildElementCount() == (XMLSize_t) 0)
			el_value = XMLString::transcode(e->getTextContent ());

		tmp+=  tabs + "<"+  el_name + ">" + el_value +  "\n";

      for (DOMNode* child = tree->getFirstChild();
           child != NULL; child = child->getNextSibling())
      {
    	  DumpTree(child, tmp);
      }
		tmp+=  tabs + "</" + el_name + ">\n";
    }
  leave:
  tabs+=tabs.substr(1);
 }
Ejemplo n.º 2
0
void Parameters::readFile(string str){
  file = str;
  XMLPlatformUtils::Initialize();
  XercesDOMParser parser;
  parser.setValidationScheme(XercesDOMParser::Val_Always);
  HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase();
  parser.setErrorHandler(&errHandler);
  parser.parse(str.c_str());
  DOMDocument * doc = parser.getDocument();
  DOMElement* elementRoot = doc->getDocumentElement();

  // Extract floats
  DOMElement* floatRoot = (DOMElement *) 
    elementRoot->getElementsByTagName(XMLString::transcode("real"))->item(0);
  DOMElement* child = floatRoot->getFirstElementChild();
  do{
    saveReal(XMLString::transcode(child->getNodeName()),  
		    atof(XMLString::transcode(child->getTextContent())));
    child = child->getNextElementSibling();
  }while(child != NULL);

  // Extract integers
  DOMElement* intRoot = (DOMElement *) 
    elementRoot->getElementsByTagName(XMLString::transcode("integer"))->item(0);
  child = intRoot->getFirstElementChild();
  do{
    saveInteger(
		    XMLString::transcode(child->getNodeName()),  
		    atoi(XMLString::transcode(child->getTextContent())));
    child = child->getNextElementSibling();
  }while(child != NULL);
}
Ejemplo n.º 3
0
// to check the value of child node
string cap::parread(const char* parentTag, int parentIndex,const char* childTag,  int childIndex)
{

	
	XMLCh* temp=XMLString::transcode(parentTag);
	DOMNodeList* list = doc->getElementsByTagName(temp);
    XMLString::release(&temp);
 
    DOMElement* parent =dynamic_cast<DOMElement*>(list->item(parentIndex));
    DOMElement* child =dynamic_cast<DOMElement*>(parent->getElementsByTagName(XMLString::transcode(childTag))->item(childIndex));
     
    string value;
    if (child) {
        char* temp2 = XMLString::transcode(child->getTextContent());
		//cout<<"its :"<<child->getTextContent()<<endl;
        value = temp2;
        XMLString::release(&temp2);
    }
    else {
        value = "NO VALUE";
    }
	
	
	return value;

}
Ejemplo n.º 4
0
void DeltaApplyEngine::TextNode_Update( XID_t nodeXID, DOMNode *operationNode ) {
	vddprintf(("        update xid=%d\n",(int)nodeXID));
	DOMNode* upNode = xiddoc->getXidMap().getNodeWithXID( nodeXID );
	if (upNode==NULL) THROW_AWAY(("node with XID=%d not found",(int)nodeXID));
	
	DOMNodeList *opNodes = operationNode->getChildNodes();
	vddprintf(("opNodes->length() = %d\n", opNodes->getLength()));
	XyStrDeltaApply *xytext = new XyStrDeltaApply(xiddoc, upNode, 1);
	xytext->setApplyAnnotations(applyAnnotations);
	for (int i = opNodes->getLength() - 1; i >= 0; i--) {
		DOMElement *op = (DOMElement *) opNodes->item(i);
		char *optype = XMLString::transcode(op->getLocalName());
		XMLCh pos_attr[4];
		XMLCh len_attr[4];
		XMLString::transcode("pos", pos_attr, 3);
		XMLString::transcode("len", len_attr, 3);
		vddprintf(("item %d = %s\n", i, optype));
		// Replace operation
		if (strcmp(optype, "tr") == 0) {
			char *pos = XMLString::transcode(op->getAttribute(pos_attr));
			char *len = XMLString::transcode(op->getAttribute(len_attr));
			xytext->replace(atoi(pos), atoi(len), op->getTextContent());
			XMLString::release(&pos);
			XMLString::release(&len);
		}
		// Delete operation
		else if (strcmp(optype, "td") == 0) {
			char *pos = XMLString::transcode(op->getAttribute(pos_attr));
			char *len = XMLString::transcode(op->getAttribute(len_attr));
			xytext->remove(atoi(pos), atoi(len));
			XMLString::release(&pos);
			XMLString::release(&len);
		}
		// Insert operation
		else if (strcmp(optype, "ti") == 0) {
			char *pos = XMLString::transcode(op->getAttribute(pos_attr));
			xytext->insert(atoi(pos), op->getTextContent());
			XMLString::release(&pos);
		}
		XMLString::release(&optype);
	}
	xytext->complete();
	delete xytext;
}
AdditionalInformationType::AdditionalInformationType(const DOMElement &e, Flags f, Container *c)
    : AdditionalInformationTypeBase(e, f, c)
{
    xsd::cxx::xml::dom::parser<char> p(e, true, false, true);
    for (; p.more_content(); p.next_content(false))
    {
        const DOMElement &i(p.cur_element());
        const xsd::cxx::xml::qualified_name<char> n(xsd::cxx::xml::dom::name<char>(i));
        if(n.name() == "OtherInformation" && n.namespace_() == "http://uri.etsi.org/02231/v2#")
        {
            DOMElement *elem = i.getFirstElementChild();
            const xsd::cxx::xml::qualified_name<char> n2(xsd::cxx::xml::dom::name<char>(*elem));
            if(n2.name() == "MimeType")// && n.namespace_() == "http://uri.etsi.org/02231/v2/additionaltypes#")
                mimeType_ = xsd::cxx::xml::transcode<char>(elem->getTextContent());
            if(n2.name() == "SchemeTerritory")
                schemeTerritory_ = xsd::cxx::xml::transcode<char>(elem->getTextContent());
        }
    }
}
Ejemplo n.º 6
0
// Look at Xerces XSModel to parse XSD into tree SCMPrint
void CXercesUtils::NagivateParseTree(xercesc::DOMElement* p, std::string tabs)
{
	string name;
	short age;
	tabs+="    ";
	for (DOMNode* n = p->getFirstChild ();	n != 0;	n = n->getNextSibling ())
	{
		if (n->getNodeType () != DOMNode::ELEMENT_NODE)
			continue;
		DOMElement*  e = (DOMElement* ) n;
		std::string el_name =  XMLString::transcode(n->getNodeName());

		std::string el_value;
		if(e->getTextContent () && e->getChildElementCount() == (XMLSize_t) 0)
			el_value = XMLString::transcode(e->getTextContent ());

		std::cerr <<  tabs.c_str() << el_name.c_str()<< "=" << el_value.c_str()<< endl;
		//DOMNode* node = n->getFirstChild ();

		NagivateParseTree((DOMElement*) n,tabs);
	}
	tabs=tabs.substr(1);

}
Ejemplo n.º 7
0
string XmlDomDocument::getChildValue(const char* parentTag, int parentIndex, const char* childTag, int childIndex)
{
	XMLCh* temp = XMLString::transcode(parentTag);
	DOMNodeList* list = m_doc->getElementsByTagName(temp);
	XMLString::release(&temp);

	DOMElement* parent = dynamic_cast<DOMElement*>(list->item(parentIndex));
	DOMElement* child = 
        dynamic_cast<DOMElement*>(parent->getElementsByTagName(XMLString::transcode(childTag))->item(childIndex));
	string value;
	if (child) {
		char* temp2 = XMLString::transcode(child->getTextContent());
		value = temp2;
        XMLString::release(&temp2);
	}
	else {
		value = "";
	}
	return value;
}
Ejemplo n.º 8
0
XERCES_CPP_NAMESPACE_USE 

std::vector<DgFileTile> DgFileTile::getTiles(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDocument,
   const std::string& filename,
   unsigned int& height,
   unsigned int& width)
{
   std::vector<DgFileTile> tiles;
   DOMElement* pRoot = pDocument->getDocumentElement();
   if (pRoot == NULL || !XMLString::equals(pRoot->getNodeName(), X("isd")))
   {
      return tiles;
   }

   DOMNodeList* pTilList = pRoot->getElementsByTagName(X("TIL"));
   if (pTilList == NULL || pTilList->getLength() != 1)
   {
      return tiles;
   }
   DOMNode* pTil = pTilList->item(0);
   if (pTil == NULL || pTil->getNodeType() != DOMNode::ELEMENT_NODE)
   {
      return tiles;
   }
   DOMElement* pTilElement = static_cast<DOMElement*>(pTil);
   DOMNodeList* pTilesList = pTilElement->getElementsByTagName(X("TILE"));
   if (pTilesList == NULL)
   {
      return tiles;
   }
   height = 0;
   width = 0;
   bool error = false;
   QFileInfo fileInfo(QString::fromStdString(filename));
   QDir fileDir = fileInfo.dir();
   for (unsigned int i = 0; i < pTilesList->getLength(); ++i)
   {
      DgFileTile curTile;
      DOMNode* pNode = pTilesList->item(i);
      if (pNode == NULL || pNode->getNodeType() != DOMNode::ELEMENT_NODE)
      {
         continue;
      }
      DOMElement* pElement = static_cast<DOMElement*>(pNode);
      DOMElement* pChildElement = pElement->getFirstElementChild();
      while (pChildElement != NULL)
      {
         std::string textContent = A(pChildElement->getTextContent());
         if (XMLString::equals(pChildElement->getNodeName(), X("FILENAME")))
         {
            curTile.mTilFilename = fileDir.filePath(QString::fromStdString(textContent)).toStdString();
         }
         if (XMLString::equals(pChildElement->getNodeName(), X("ULCOLOFFSET")))
         {
            curTile.mStartCol = StringUtilities::fromXmlString<unsigned int>(textContent, &error);
         }
         if (XMLString::equals(pChildElement->getNodeName(), X("ULROWOFFSET")))
         {
            curTile.mStartRow = StringUtilities::fromXmlString<unsigned int>(textContent, &error);
         }
         if (XMLString::equals(pChildElement->getNodeName(), X("LRCOLOFFSET")))
         {
            curTile.mEndCol = StringUtilities::fromXmlString<unsigned int>(textContent, &error);
         }
         if (XMLString::equals(pChildElement->getNodeName(), X("LRROWOFFSET")))
         {
            curTile.mEndRow = StringUtilities::fromXmlString<unsigned int>(textContent, &error);
         }
         pChildElement = pChildElement->getNextElementSibling();
      }
      tiles.push_back(curTile);
      if (curTile.mEndCol > width)
      {
         width = curTile.mEndCol;
      }
      if (curTile.mEndRow > height)
      {
         height = curTile.mEndRow;
      }
   }
   return tiles;
}
Ejemplo n.º 9
0
 bool ValueIntT<T>::deserializeXML(DOMElement e)
 {
   Base::m_value = Radiant::StringUtils::fromString<T>(e.getTextContent().c_str());
   
   return true;
 }
Ejemplo n.º 10
0
//===================================================================================================================
void geometryLoader::acquireInfo(DOMElement * element)
{
    //  static const boost::regex matchDoubleQuotes(".*?\"(.*)\".*", boost::regex::perl);

    DOMNodeList*      children  = element->getChildNodes();
    const  XMLSize_t  nodeCount = children->getLength()   ;
    double rowPitch=0,colPitch=0;
    int dutNumbers=0;

    std::string  parentTagName = XMLString::transcode(element->getTagName()) ;

    std::map<std::string, std::string> keyValue ;

    for( XMLSize_t j = 0; j < nodeCount; ++j )
    {
        DOMNode* currentNode = children->item(j);

        if( !(currentNode->getNodeType() &&
              currentNode->getNodeType() == DOMNode::ELEMENT_NODE )) continue ; // is element otherwise close the recursive stack

        DOMElement      * currentElement = dynamic_cast< xercesc::DOMElement* >( currentNode ); // Found node which is an Element. Re-cast node as such.
        DOMNamedNodeMap * attList	     = currentNode->getAttributes() ;
        std::string       tagName	     = XMLString::transcode(currentElement->getTagName()) ;
        std::string       textContent    = "" ;
        std::string       textWithBlanks = "" ;

        if(currentNode->getTextContent())
            textWithBlanks = XMLString::transcode(currentElement->getTextContent()) ;

        textContent = this->stripBlanks(textWithBlanks) ;

        keyValue.clear() ;
        bool used = true;

        for(unsigned int i=0; i<attList->getLength(); ++i) // Set attibutes apart in a temporary hash map
        {
            if(                                                  attList->item(i)->getTextContent() )
                keyValue[                   XMLString::transcode(attList->item(i)->   getNodeName())] =
                        this->stripBlanks( XMLString::transcode(attList->item(i)->getTextContent()));
        }


        if( tagName == "testBeamGeometry" )
        {
            //theGeometry_->                keyValue["id" ]           ;
            //theGeometry_->       ( this->toLower(keyValue["date"]) );
            STDLINE("Entered " + tagName,ACYellow) ;
        }

        if( tagName == "stations" )
        {
            ss_.str("");
            ss_ << "stations in use: " << keyValue["inUse" ];
            STDLINE(ss_.str(),ACYellow) ;
        }

        if( tagName == "station" )
        {
            if(this->toLower(keyValue["used"])=="yes")
                station_    = keyValue["id"];
            else                   used        = false         ;
        }

        if( tagName == "detectors" )
        {
            ss_.str("");
            ss_ << "detectors in use: " << keyValue["inUse" ];
            STDLINE(ss_.str(),ACYellow) ;
        }

        if( tagName == "detector" )
        {
            if( this->toLower(keyValue["used"])=="yes" )
            {
                ss_.str("");
                ss_ << "Station: " << station_ << " - " << "Plaq: " << keyValue["id"];
                currentPlaqID_ = ss_.str();
                theGeometry_->addDetector( currentPlaqID_ );

                STDLINE(keyValue["name"] + " detector id: " + currentPlaqID_,ACYellow) ;

                if( this->toLower(keyValue["isDUT"]) == "yes" )
                {
                    theGeometry_->getDetector( currentPlaqID_ )->setDUT();
                    dutNumbers++;
                    theGeometry_->setDUTnumbers(dutNumbers);
                }
            }
            else used=false;
        }

        if( tagName == "largeGranularity" )
        {
            STDLINE("Rotations relative to " + keyValue["relativeRotations"],ACYellow) ;
        }

        if( tagName == "xBackFlipped"  && this->validContent(tagName,textContent))
        {
            if( this->toLower(textContent) == "yes" || this->toLower(textContent) == "true")
            {
                STDLINE("get Detector",ACYellow) ;
                theGeometry_->getDetector( currentPlaqID_ )->setXBackFlipped(true );
                STDLINE("cleared",ACYellow) ;
            }
            else   theGeometry_->getDetector( currentPlaqID_ )->setXBackFlipped(false);
        }

        if( tagName == "yBackFlipped"  && this->validContent(tagName,textContent))
        {
            if( this->toLower(textContent) == "yes" || this->toLower(textContent) == "true")
                theGeometry_->getDetector( currentPlaqID_ )->setYBackFlipped(true );
            else   theGeometry_->getDetector( currentPlaqID_ )->setYBackFlipped(false);
        }

        if( tagName == "xPosition"  && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->setXPosition(Utils::toDouble(textContent)*CONVF);

        if( tagName == "yPosition"  && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->setYPosition(Utils::toDouble(textContent)*CONVF);

        if( tagName == "zPosition"  && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->setZPosition(Utils::toDouble(textContent)*CONVF);

        if( tagName == "xRotation"  && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->setXRotation( Utils::toDouble(textContent));

        if( tagName == "yRotation"  && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->setYRotation( Utils::toDouble(textContent));

        if( tagName == "zRotation"  && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->setZRotation( Utils::toDouble(textContent) );

        if( toRead_ == "correction" || toRead_ == "all" )
        {
            if( tagName == "fineGranularity" )
            {
                STDLINE("Reading fineGranularity",ACGreen);
                STDLINE("Rotations relative to " + keyValue["relativeRotations"],ACYellow) ;
            }

            if( tagName == "xPosCorrection"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setXPositionCorrection(Utils::toDouble(textContent)*CONVF);

            if( tagName == "xPositionError"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setXPositionError(Utils::toDouble(textContent)*CONVF);

            if( tagName == "yPosCorrection"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setYPositionCorrection(Utils::toDouble(textContent)*CONVF);

            if( tagName == "yPositionError"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setYPositionError(Utils::toDouble(textContent)*CONVF);

            if( tagName == "zPosCorrection"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setZPositionCorrection(Utils::toDouble(textContent)*CONVF);

            if( tagName == "zPositionError"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setZPositionError(Utils::toDouble(textContent)*CONVF);

            if( tagName == "xRotationCorrection"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setXRotationCorrection( Utils::toDouble(textContent) );

            if( tagName == "xRotationCorrectionError"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setXRotationCorrectionError( Utils::toDouble(textContent) );

            if( tagName == "yRotationCorrection"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setYRotationCorrection( Utils::toDouble(textContent) );

            if( tagName == "yRotationCorrectionError"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setYRotationCorrectionError( Utils::toDouble(textContent) );

            if( tagName == "zRotationCorrection"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setZRotationCorrection( Utils::toDouble(textContent) );

            if( tagName == "zRotationCorrectionError"  && this->validContent(tagName,textContent))
                theGeometry_->getDetector( currentPlaqID_ )->setZRotationCorrectionError( Utils::toDouble(textContent) );
        }

        if( tagName == "ROCs" )
        {
            STDLINE("ROCs in use: " + keyValue["inUse"],ACYellow) ;
            theGeometry_->getDetector( currentPlaqID_ )->setXNumberOfROCs( Utils::toInt(keyValue["xChipsNumber"]) );
            theGeometry_->getDetector( currentPlaqID_ )->setYNumberOfROCs( Utils::toInt(keyValue["yChipsNumber"]) );
        }

        if( tagName == "ROC" )
        {
            if( this->toLower(keyValue["used"])=="yes" )
            {
                currentROC_ = Utils::toInt(keyValue["pos"]);
                theGeometry_->getDetector( currentPlaqID_ )->addROC( Utils::toInt(keyValue["pos"]),
                                                                     Utils::toInt(keyValue["id"] ) );
            }
            else used=false;
        }

        if ( tagName == "calibrationFilePath" && this->validContent(tagName,textContent))
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setCalibrationFilePath(textContent);

        if ( tagName == "standardRowPitch" && this->validContent(tagName,textContent)) rowPitch = Utils::toDouble(textContent)*CONVF;
        if ( tagName == "standardColPitch" && this->validContent(tagName,textContent))
        {
            colPitch = Utils::toDouble(textContent)*CONVF;
            ss_.str("");
            ss_ << ACCyan   << ACBold << "Pitch. Row : " << ACWhite << ACBold << rowPitch
                    << ACCyan   << ACBold << " Col: "        << ACWhite << ACBold << colPitch
                    << ACYellow << ACBold << " (tens of microns)";
            STDLINE(ss_.str(),ACRed) ;
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setStandardPixPitch(rowPitch,colPitch);
        }

        if ( tagName == "nonStandardRowPitch" && this->validContent(tagName,textContent) )
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOneRowPitch(Utils::toInt(keyValue["rowNum"]),
                                                                                               Utils::toDouble(textContent)*CONVF     );


        if ( tagName == "nonStandardColPitch" && this->validContent(tagName,textContent) )
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOneColPitch(Utils::toInt(keyValue["colNum"]),
                                                                                               Utils::toDouble(textContent)*CONVF     );


        if( tagName == "MAX_ROWS"  && this->validContent(tagName,textContent))
        {
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setNumberOfRows(Utils::toInt(textContent)+1 );
        }
        if( tagName == "MAX_COLS"  && this->validContent(tagName,textContent))
        {
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setNumberOfCols(Utils::toInt(textContent)+1 );
        }
        if( tagName == "orientation"  && this->validContent(tagName,textContent))
        {
            theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOrientation( Utils::toInt(textContent) );
            ss_.str("") ; ss_ << ACCyan  << ACBold << "Orientation: " << ACWhite << textContent
                    << ACYellow << ACBold << " (degrees)";
            STDLINE(ss_.str(),ACGreen) ;
        }
        //closingFlag_ = false ;
        //STDLINE(tagName,ACRed) ;
        if ( used ) this->acquireInfo(currentElement) ;
        //STDLINE(tagName,ACGreen) ;
        //closingFlag_ = true ;
    }
}
Ejemplo n.º 11
0
// 2006/11/07
void handleDocument(DOMDocument* document, char* outputfile)
{
  if (document == NULL) {
    cerr << _PREFIX_ << "WARNING null XML Document\n";
    return;
  }
  DOMElement* docElement = NULL;
  docElement = document->getDocumentElement();

  if (docElement == NULL) {
    cerr << _PREFIX_ << "WARNING null XML Document Element\n";
    return;
  }


  DOMNodeList* sections = docElement->getElementsByTagName(XMLString::transcode("section"));
  int sCount = 0;
  int paragraphID = 1;

  for (unsigned int i = 0; i < sections->getLength(); i++) {
    int sectID = i+1;
    if (verbose) cerr << _PREFIX_ << "Section " << i;
    DOMElement* aSect = NULL;
    aSect = (DOMElement*)sections->item(i);
    string sectName = XMLString::transcode(((DOMElement*)aSect)->getAttribute(XMLString::transcode("name")));
    string analyze =
      XMLString::transcode(((DOMElement*)aSect)->getAttribute(XMLString::transcode("analyze")));
    if (verbose) cerr << " ['" << sectName << "'";
    // Ignore non affected sections 
    if ( ( analyze == "yes" ) ||
         ( sectName.length() == 0 ) ||
         ( affectedSections.find(sectName + "|") != string::npos )) {      
      
      if (verbose) cerr << " analyze=yes ";
      // Deal with unnamed and affected sections

      // create a stream
      aSect->normalize();
      stringstream text(XMLString::transcode(aSect->getTextContent()));

      if (verbose) {
        string temp(XMLString::transcode(aSect->getTextContent()));
        cerr << temp.length() << " charcters]\n" << _PREFIX_ << "           ";
      }

      aSect->removeChild(aSect->getFirstChild());

      vector<vector<string> > result;
      result = seg->segmentInVectors(text);

      for(vector<vector<string> >::iterator itp = result.begin(); 
          itp != result.end(); 
          itp++) {
        stringstream parID;
        parID << _ID_PREFIX_SECTION << sectID << _ID_PREFIX_PARAGRAPH << paragraphID++;
        sCount += addSegmentedParagraphToSection(*itp,aSect,parID.str().c_str());
      }
   
      if (verbose) cerr << endl;
    } else {
      if (verbose) cerr << " analyze=no]" << endl;
    }
  }

  if (stamp) stampDocument(docElement);

  /* SERIALIZE XML DOCUMENT */
  if (outputfile == NULL) xmlInterface->serializeTo(document);
  else xmlInterface->serializeTo(document,outputfile);

  if (verbose) cerr << _PREFIX_ << "Segmented in " << sCount << " sentences." << endl;
}
Ejemplo n.º 12
0
ret_ CXMLLoaderNetwork::Load(XercesDOMParser *pParser,
							 const ch_1 *pszEnvironmentPath)
{
	_START(LOAD);

#ifdef _DEBUG_
	if (!pParser)
		_RET(PARAMETER_NULL | PARAMETER_1);

	if (!pszEnvironmentPath)
		_RET(PARAMETER_NULL | PARAMETER_2);

	if (null_v == pszEnvironmentPath[0])
		_RET(PARAMETER_EMPTY | PARAMETER_2);
#endif

	SetParser(pParser);

	ch_1 sNetwork[ENVIRONMENT_PATH_LENGTH];

	memset(sNetwork, 0, ENVIRONMENT_PATH_LENGTH);
	strncpy(sNetwork, pszEnvironmentPath, ENVIRONMENT_PATH_LENGTH);
	strncat(sNetwork, NETWORK_XML_FILE, ENVIRONMENT_PATH_LENGTH);

	DOMDocument *pNetworkDoc = null_v;

	try
	{
		GetParser()->parse(sNetwork);
        pNetworkDoc = GetParser()->getDocument();
	}
    catch (const OutOfMemoryException &err)
    {
		auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		_RET(XML_LOADER_ERROR);
    }
	catch (const XMLException &err)
    {
		auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		_RET(XML_LOADER_ERROR);
	}
    catch (const DOMException &err)
    {
        auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		_RET(XML_LOADER_ERROR);
	}
	catch (...)
    {
		printf("Unexpected error during parsing.\n");

		_RET(XML_LOADER_ERROR);
    }

	DOMElement *pRoot = pNetworkDoc->getDocumentElement();

	if (!pRoot)
		_RET(XML_LOADER_ERROR);

	DOMElement *pChild = (DOMElement *)pRoot->getFirstChild();

	if (!pChild)
		_RET(XML_LOADER_ERROR);

	auto_xerces_str wsIdentity		("identity");
	auto_xerces_str wsPDU			("pdu");
	auto_xerces_str wsDirection		("direction");
	auto_xerces_str	wsName			("name");
	auto_xerces_str	wsProtocolName	("protocol");
	auto_xerces_str wsCommandID		("command_id");
	auto_xerces_str wsSizeID		("size_id");
	auto_xerces_str	wsLocalPort		("local_port");
	auto_xerces_str wsAuto			("auto");

	auto_xerces_str wsFilter		("filter");
	auto_xerces_str wsMaxConnections("max_connections");
	auto_xerces_str wsRemoteIP		("remote_ip");
	auto_xerces_str	wsRemotePort	("remote_port");
	auto_xerces_str wsReconnect		("reconnect");

	auto_xerces_str wsAcceptorName	("acceptor");
	auto_xerces_str	wsConnectorName	("connector");
 	auto_xerces_str wsReceiverName	("receiver");
	auto_xerces_str wsSenderName	("sender");

	auto_xerces_str wsType			("type");


	while (pChild)
    {
		ENetworkType NetworkType = NETWORK_NONE;
		CProtocolInfo *pProtocol = null_v;
		CField *pCommandIDField	= null_v;
		CField *pSizeIDField = null_v;
		bool_ bIsAutoStart = true_v;

		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsAcceptorName))
		{
			NetworkType = NETWORK_ACCEPTOR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsConnectorName))
		{
			NetworkType = NETWORK_CONNECTOR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsReceiverName))
		{
			NetworkType = NETWORK_RECEIVER;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSenderName))
		{
			NetworkType = NETWORK_SENDER;
		}
		else
		{
			pChild = (DOMElement *)pChild->getNextSibling();

			continue;
		}

		auto_xerces_str sProtocolName(pChild->getAttribute(wsProtocolName));

		if (SUCCESS != _ERR(
				CXMLLoaderProtocol::Instance()->Load(pParser,
													 pszEnvironmentPath,
													 sProtocolName)))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		if (SUCCESS != _ERR(
                CProtocolManager::instance()->getProtocol(sProtocolName,
                        pProtocol)))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		auto_xerces_str sCommandID(pChild->getAttribute(wsCommandID));

        if (SUCCESS != _ERR(pProtocol->getHeadField(sCommandID,
                pCommandIDField))
			|| FIELD_NORMAL_STYLE !=
                (pCommandIDField->type() & FIELD_NORMAL_STYLE)
                || 4 < _LEN(pCommandIDField->type()))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		auto_xerces_str sSizeID(pChild->getAttribute(wsSizeID));

        if (SUCCESS != _ERR(pProtocol->getHeadField(sSizeID,
                pSizeIDField))
			|| FIELD_NORMAL_STYLE !=
                (pSizeIDField->type() & FIELD_NORMAL_STYLE)
                || 4 < _LEN(pSizeIDField->type()))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		auto_xerces_str wsAutoFalse("false");

		if (0 == XMLString::compareString(wsAutoFalse,
										  pChild->getAttribute(wsAuto)))
		{
			bIsAutoStart = false_v;
		}

        CNode *pNetwork = null_v;
		auto_xerces_str sName(pChild->getAttribute(wsName));

		switch (NetworkType)
		{
		case NETWORK_NONE:
			_RET(XML_LOADER_ERROR);
		case NETWORK_ACCEPTOR:
			{
				auto_xerces_str	sLocalPort(pChild->getAttribute(wsLocalPort));
				auto_xerces_str
					sMaxConnections(pChild->getAttribute(wsMaxConnections));

				pNetwork = new CAcceptor(pProtocol,
										 pCommandIDField,
										 pSizeIDField,
										 (ub_2)atoi(sLocalPort),
										 (size_)atoi(sMaxConnections),
										 bIsAutoStart);
			}

			break;
		case NETWORK_CONNECTOR:
			{
				//
				auto_xerces_str	nLocalPort	(pChild->getAttribute(wsLocalPort));
				auto_xerces_str	sRemoteIP	(pChild->getAttribute(wsRemoteIP));
				auto_xerces_str	nRemotePort
					(pChild->getAttribute(wsRemotePort));
				auto_xerces_str	sReconnect	(pChild->getAttribute(wsReconnect));

				pNetwork = new CConnector(pProtocol,
										  pCommandIDField,
										  pSizeIDField,
										  (ub_2)atoi(nLocalPort),
										  (const ch_1 *)sRemoteIP,
										  (ub_2)atoi(nRemotePort),
										  (b_4)atoi(sReconnect),
										  bIsAutoStart);
			}

			break;
		case NETWORK_RECEIVER:
			{
				//
				auto_xerces_str sLocalPort(pChild->getAttribute(wsLocalPort));


				pNetwork = new CReceiver(pProtocol,
										 pCommandIDField,
										 pSizeIDField,
										 (ub_2)atoi(sLocalPort),
										 bIsAutoStart);
			}

			break;
		case NETWORK_SENDER:
			{
				//
				auto_xerces_str sLocalPort(pChild->getAttribute(wsLocalPort));

				pNetwork = new CSender(pProtocol,
									   pCommandIDField,
									   pSizeIDField,
									   (ub_2)atoi(sLocalPort),
									   bIsAutoStart);
			}
		}

        CNodeConf *pNetworkConf = (CNodeConf *) pNetwork->getConf();

		//
		DOMElement *pSub = (DOMElement *)pChild->getFirstChild();

		if (!pSub)
			_RET(XML_LOADER_ERROR);

		while (pSub)
		{
			if (0 == XMLString::compareString(pSub->getNodeName(),
											  wsIdentity))
			{
				//
				auto_xerces_str sIdentity(pSub->getAttribute(wsIdentity));
				ch_1 			*sIdentityName = null_v;

				if (SUCCESS != _ERR(GetLastName(sIdentity, sIdentityName)))
					_RET(XML_LOADER_ERROR);

                v_ *pV = pProtocol->data().value(sIdentityName);

				if (!pV)
					_RET(XML_LOADER_ERROR);

				//
				auto_xerces_str	sPDU(pSub->getAttribute(wsPDU));
                CPduInfo *pPDU = null_v;

                if (SUCCESS != _ERR(pProtocol->getPdu(sPDU, pPDU)))
					_RET(XML_LOADER_ERROR);

				//
				auto_xerces_str sDirection(pSub->getAttribute(wsDirection));
				EDirection		Direction;

				if (SUCCESS != _ERR(GetDirection(sDirection, Direction)))
					_RET(XML_LOADER_ERROR);

				//
				if (SUCCESS != _ERR(pNetworkConf->ConfigPDU(*pV,
															pPDU,
															Direction)))
				{
					_RET(XML_LOADER_ERROR);
				}
			}
			else if (0 == XMLString::compareString(pSub->getNodeName(),
												   wsFilter))
			{
				CIPFilter *pIPFilter = null_v;

				if (NETWORK_ACCEPTOR == NetworkType)
				{
					pIPFilter =
						&((CAcceptorConf *)pNetworkConf)->IPFilter();
				}
				else if (NETWORK_RECEIVER == NetworkType)
				{
					pIPFilter =
						&((CReceiverConf *)pNetworkConf)->IPFilter();
				}
				else
				{
					_RET(XML_LOADER_ERROR);
				}

				auto_xerces_str sType(pSub->getAttribute(wsType));

				if (0 == strcmp(sType, "forbid")) {
                    pIPFilter->setForbid(true_v);
                } else if (0 == strcmp(sType, "permit")) {
                    pIPFilter->setForbid(false_v);
                }

                auto_xerces_str sIPGroup(pSub->getTextContent());

                if (false_v == pIPFilter->addIpGroup((const ch_1 *) sIPGroup))
					_RET(XML_LOADER_ERROR);
			}

			pSub = (DOMElement *)pSub->getNextSibling();
		}

        if (SUCCESS != _ERR(CNetworkManager::instance()->AddNetwork(
														(const char *)sName,
														NetworkType,
														pNetwork)))
		{
			_RET(XML_LOADER_ERROR);
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	_RET(SUCCESS);
}
Ejemplo n.º 13
0
 bool ValueBool::deserializeXML(DOMElement e)
 {
   m_value = (bool)Radiant::StringUtils::fromString<int32_t>(e.getTextContent().c_str());
   return true;
 }