示例#1
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);
}
示例#2
0
ret_ CXMLLoaderActions::LoadProgram(const CData *pParentData,
									CProgram &Program,
									const DOMElement *pElement,
									const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pParentData)
		return PARAMETER_NULL | PARAMETER_1;

	if (!pElement)
		return PARAMETER_NULL | PARAMETER_3;
#endif

	auto_xerces_str wsDataBlock("data_block");
	auto_xerces_str wsProcessBlock("process_block");

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

	if (!pChild)
		return XML_LOADER_ERROR;

	Program.Data().SetParent(pParentData);

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsDataBlock))
		{
			CData Data;

			if (SUCCESS != (LoadDataBlock(Data,  pChild)))
				return XML_LOADER_ERROR;

			Program.SetData(Data);
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProcessBlock))
		{
			if (SUCCESS != LoadProcessBlock(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}

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

	return SUCCESS;
}
示例#3
0
/*****************************************************
 * XmlWorldParser implementation
 ***************************************************/
void XmlWorldParser::processNode(DOMTreeWalker* tw, const double* pos) {

	do {

		DOMElement* node = (DOMElement*) tw->getCurrentNode();

		//		printNode(node);

		/* Process body */
		if (XMLString::equals(XMLString::transcode("body"), node->getNodeName())) {
			cout << "adding a body" << endl;
			addBody(node, pos);
		} else
		/* Process joint */
		if (XMLString::equals(XMLString::transcode("joint"),
				node->getNodeName())) {
			addJoint(node, pos);
		} else
		/* Process a transform */
		if (XMLString::equals(XMLString::transcode("transform"),
				node->getNodeName())) {
			double trans[3];
			char* x_c = getAttribute(node, "x");
			char* y_c = getAttribute(node, "y");
			char* z_c = getAttribute(node, "z");

			if (x_c == NULL || y_c == NULL || z_c == NULL)
				throw exception();

			trans[0] = pos[0] + atof(x_c);
			trans[1] = pos[1] + atof(y_c);
			trans[2] = pos[2] + atof(z_c);

			if (tw->firstChild() != NULL) {
				processNode(tw, trans);
			}
		} else if (tw->firstChild() != NULL) {
			processNode(tw, pos);
		}

	} while (tw->nextSibling() != NULL);

	tw->parentNode();

	return;
}
示例#4
0
const char *SkinElementsMgr::getElementAlias(const char *id)  {
  if(m_doc) {   
    DOMElement * node = m_doc->getElementById(id);
    if (node && !STRCMP(node->getNodeName(),"elementalias")) {
      DOMAttr * attr = node->getAttributeNode("target");
      if( attr && attr->getSpecified() )
        return attr->getValue();
    }
  }
  return NULL;
}
示例#5
0
vector<ImportDescriptor*> LayerImporter::getImportDescriptors(const string& filename, bool reportErrors)
{
   vector<ImportDescriptor*> descriptors;
   if (!filename.empty())
   {
      MessageLog* pLog = NULL;
      if (reportErrors == true)
      {
         Service<MessageLogMgr> pLogMgr;
         pLog = pLogMgr->getLog();
      }

      XmlReader xml(pLog);
      XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDoc = xml.parse(filename, "metadata");
      DOMElement* pRootElement = NULL;
      if (pDoc != NULL)
      {
         pRootElement = pDoc->getDocumentElement();
      }
      if (pRootElement != NULL)
      {
         for (DOMNode* pChild = pRootElement->getFirstChild();
            pChild != NULL;
            pChild = pChild->getNextSibling())
         {
            if (pChild->getNodeType() == DOMNode::ELEMENT_NODE)
            {
               DOMElement* pChildElement = static_cast<DOMElement*>(pChild);
               string cNodeName = A(pChildElement->getNodeName());

               ImportDescriptor* pImportDescriptor = ModelImporter::populateImportDescriptor(pChildElement, filename);
               if (pImportDescriptor != NULL)
               {
                  DataDescriptor* pDataDescriptor = pImportDescriptor->getDataDescriptor();
                  if (NULL != pDataDescriptor)
                  {
                     DynamicObject* pMetadataZ = pDataDescriptor->getMetadata();
                     VERIFYRV(pMetadataZ, descriptors);
                     if (!pMetadataZ->getAttributeByPath("Layer/Import Options/Use Pixel Coordinates").isValid())
                     {
                        pMetadataZ->setAttributeByPath("Layer/Import Options/Use Pixel Coordinates", false);
                     }
                  }
                  descriptors.push_back(pImportDescriptor);
               }
            }
         }
      }
   }

   return descriptors;
}
static DOMElement *
SAMLFindChildByName(const DOMElement *elem,
                    const char *name)
{
   XMLT sigNodeName(name);
   DOMElement *childElem;

   for (childElem = elem->getFirstElementChild();
        childElem != NULL; childElem = childElem->getNextElementSibling()) {
      if (XMLString::equals(childElem->getNodeName(),
                            sigNodeName.getUnicodeStr())) {
         break;
      }
   }

   return childElem;
}
示例#7
0
vector<ImportDescriptor*> LayerImporter::getImportDescriptors(const string& filename, bool reportErrors)
{
   vector<ImportDescriptor*> descriptors;
   if (!filename.empty())
   {
      MessageLog* pLog = NULL;
      if (reportErrors == true)
      {
         Service<MessageLogMgr> pLogMgr;
         pLog = pLogMgr->getLog();
      }

      XmlReader xml(pLog);
      XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDoc = xml.parse(filename, "metadata");
      DOMElement* pRootElement = NULL;
      if (pDoc != NULL)
      {
         pRootElement = pDoc->getDocumentElement();
      }
      if (pRootElement != NULL)
      {
         for (DOMNode* pChild = pRootElement->getFirstChild();
            pChild != NULL;
            pChild = pChild->getNextSibling())
         {
            if (pChild->getNodeType() == DOMNode::ELEMENT_NODE)
            {
               DOMElement* pChildElement = static_cast<DOMElement*>(pChild);
               string cNodeName = A(pChildElement->getNodeName());

               ImportDescriptor* pImportDescriptor = ModelImporter::populateImportDescriptor(pChildElement, filename);
               if (pImportDescriptor != NULL)
               {
                  descriptors.push_back(pImportDescriptor);
               }
            }
         }
      }
   }

   return descriptors;
}
bool SpectralLibraryManager::deserialize(SessionItemDeserializer& deserializer)
{
    if (isBatch() == true)
    {
        setInteractive();
    }

    bool success = execute(NULL, NULL);

    if (success)
    {

        std::vector<Signature*> signatures;
        Service<SessionManager> pSessionManager;
        XmlReader reader(NULL, false);
        DOMElement* pRootElement = deserializer.deserialize(reader, "SpectralLibraryManager");
        for (DOMNode* pChild = pRootElement->getFirstChild(); pChild != NULL; pChild = pChild->getNextSibling())
        {
            DOMElement* pElement = static_cast<DOMElement*>(pChild);
            if (XMLString::equals(pElement->getNodeName(), X("Signature")))
            {
                std::string signatureId = A(pElement->getAttribute(X("signatureId")));
                Signature* pSignature = dynamic_cast<Signature*>(pSessionManager->getSessionItem(signatureId));
                if (pSignature != NULL)
                {
                    signatures.push_back(pSignature);
                }
            }
        }

        clearLibrary();
        addSignatures(signatures);
    }

    return success;
}
示例#9
0
ret_ CXMLLoaderActions::LoadDataBlock(CData &Data,
									  const DOMElement *pElement)
{
#ifdef _DEBUG_
	if (!pElement)
		return PARAMETER_NULL | PARAMETER_2;
#endif

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

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str	wsObject	("v_object");
	auto_xerces_str wsB1		("v_b_1");
	auto_xerces_str wsUB1		("v_ub_1");
	auto_xerces_str wsB2		("v_b_2");
	auto_xerces_str wsUB2		("v_ub_2");
	auto_xerces_str wsB4		("v_b_4");
	auto_xerces_str wsUB4		("v_ub_4");
	auto_xerces_str wsB8		("v_b_8");
	auto_xerces_str wsUB8		("v_ub_8");
	auto_xerces_str wsFB4		("v_fb_4");
	auto_xerces_str wsFB8		("v_fb_8");
	auto_xerces_str	wsString	("v_string");
	auto_xerces_str wsGroup		("v_group");

	auto_xerces_str	wsName		("name");
	auto_xerces_str	wsValue		("value");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(), wsObject))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (false_v == Data.Define(sName, (obj_)null_v))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB1))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_1))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_1, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}

		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB1))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_1))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_1, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB2))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_2))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_2, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB2))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_2))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_2, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB4))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_4))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_4, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB4))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_4))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_4, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB8))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_8))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_8, (b_8)atoll(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB8))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_8))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_8, (ub_8)atoll(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsFB4))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, FB_4))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, (fb_4)atof(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsFB8))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, FB_8))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, (fb_8)atof(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsString))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, (ch_1 *)""))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, sValue))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsGroup))
		{
			auto_xerces_str wsNormal("normal");
			auto_xerces_str wsFloat	("float");
			auto_xerces_str wsString("string");

			auto_xerces_str	wsName	("name");
			auto_xerces_str	wsLength("length");
			auto_xerces_str	wsSigned("signed");
			auto_xerces_str	wsSize	("size");

			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sSize	(pChild->getAttribute(wsSize));

			CFieldGroupDefined *pGroupField = new CFieldGroupDefined(
				sName, 
				sSize);

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

			if (!pSub)
				return XML_LOADER_ERROR;

			while (pSub)
			{
				if (0 == XMLString::compareString(pSub->getNodeName(),
												  wsNormal))
				{
					auto_xerces_str sName (pElement->getAttribute(wsName));
					auto_xerces_str	sLength(pElement->getAttribute(wsLength));
					auto_xerces_str	sSigned(pElement->getAttribute(wsSigned));

					EFieldType Type;

					GetFieldType(
						FIELD_NORMAL_STYLE, 
						atoi(sLength), 
						0 == strcmp(sSigned, "true") ? true_v : false_v,
						Type);
					
					CFieldNumber *pField = new CFieldNumber(sName, 
															Type, 
															pGroupField);

					pGroupField->SetSubField(pField);
				}
				else if (0 == XMLString::compareString(pSub->getNodeName(),
													   wsFloat))
				{
					auto_xerces_str sName (pElement->getAttribute(wsName));
					auto_xerces_str	sLength(pElement->getAttribute(wsLength));

					EFieldType Type;

					GetFieldType(FIELD_FLOAT_STYLE, 
								 atoi(sLength), 
								 false_v, 
								 Type);
					
					CFieldNumber *pField = new CFieldNumber(sName, 
															Type, 
															pGroupField);

					pGroupField->SetSubField(pField);
				}
				else if (0 == XMLString::compareString(pSub->getNodeName(),
													   wsString))
				{
					auto_xerces_str sName (pElement->getAttribute(wsName));
					auto_xerces_str	sLength(pElement->getAttribute(wsLength));
					auto_xerces_str	sSize(pElement->getAttribute(wsSize));
					
					CFieldString *pField = new CFieldString(sName, 
															atoi(sSize), 
															pGroupField);

					pGroupField->SetSubField(pField);
				}

				pSub = (DOMElement *)pSub->getNextSibling();
			}
			
			if (false_v == Data.Define(pGroupField))
				return XML_LOADER_ERROR;
		}

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

	return SUCCESS;
}
示例#10
0
ret_ CXMLLoaderActions::LoadIf(CProgram &Program,
							   const DOMElement *pElement,
							   const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_3);
#endif

	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	auto_xerces_str wsDataBlock			("data_block");
	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsProgram			("program");

	CProgramIf *pPI = new CProgramIf();

	pPI->Data().SetParent(&Program.Data());
	
	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  wsDataBlock))
		{
			CData Data;

			if (SUCCESS != (LoadDataBlock(Data, pSub)))
				return XML_LOADER_ERROR;

			pPI->SetData(Data);
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsExpressionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsExpressionDuality)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionDuality))
		{
			CExpression *pExpression = null_v;

			if (SUCCESS != LoadExpression(pPI->Data(),
										  pSub,
										  pExpression,
										  pPDU))
			{
				return XML_LOADER_ERROR;
			}

			if (false_v == pPI->AddExpression(pExpression))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsProgram))
		{
			CProgram *pProgram = new CProgram();

			if (SUCCESS != LoadProgram(&pPI->Data(),
									   *pProgram,
									   pSub,
									   pPDU))
			{
				return XML_LOADER_ERROR;
			}

			if (false_v == pPI->AddOperator(pProgram))
				return XML_LOADER_ERROR;
		}

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

	if (false_v == Program.AddOperator(pPI))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
示例#11
0
ret_ CXMLLoaderActions::LoadConfigGroup(CProgram &Program,
										const DOMElement *pElement,
										const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

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

	if (!pSub)
		return XML_LOADER_ERROR;

	CAutoPtr<CVariable> OV[2];
	size_ n = 0;

	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  m_wsGroupVariable))
		{
			if (SUCCESS != LoadGroupVariable(Program.Data(),
											 pElement,
											 OV[0].Ptr()))
			{
				return XML_LOADER_ERROR;
			}

			n++;
			break;
		}

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

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

	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  m_wsSolidVariable))
		{
			if (SUCCESS != LoadSolidVariable(Program.Data(), 
											 pElement, 
											 OV[1].Ptr()))
			{
				return XML_LOADER_ERROR;
			}

			n++;
			break;
		}

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

	if (2 != n)
		return XML_LOADER_ERROR;

	COptConfigGroup *pOperator = new COptConfigGroup(OV[0].Ptr(), OV[1].Ptr());

	if (false_v == Program.AddOperator(pOperator))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
示例#12
0
ret_ CXMLLoaderActions::Load(XercesDOMParser *pParser,
							 const ch_1 *pszEnvironmentPath)
{
#ifdef _DEBUG_
	if (!pParser)
		return PARAMETER_NULL | PARAMETER_1;

	if (!pszEnvironmentPath)
		return PARAMETER_NULL | PARAMETER_2;

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

	SetParser(pParser);

	ch_1 sActions[ENVIRONMENT_PATH_LENGTH];

	memset(sActions, 0, ENVIRONMENT_PATH_LENGTH);
	sprintf(sActions, "%s%s", pszEnvironmentPath, ACTIONS_XML_FILE);

	DOMDocument *pActionsDoc = null_v;

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

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

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

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

 		return XML_LOADER_ERROR;
	}
    catch (const DOMException &err)
    {
		auto_xerces_str sErr(err.msg);

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

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

		return XML_LOADER_ERROR;
    }

	if (!pActionsDoc)
		return XML_LOADER_ERROR;
	
	DOMElement *pRoot = pActionsDoc->getDocumentElement();

	if (!pRoot)
		return XML_LOADER_ERROR;

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

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str wsDataBlock("data_block");
	auto_xerces_str wsStart("start");
	auto_xerces_str wsProcessor("processor");
	auto_xerces_str wsEnd("end");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsDataBlock))
		{
			if (SUCCESS != LoadDataBlock(CUIManager::Instance()->Data(),
										 pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsStart))
		{
			if (SUCCESS != LoadProgram(&CUIManager::Instance()->Data(),
									   CUIManager::Instance()->StartProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProcessor))
		{
			if (SUCCESS != LoadProcessor(pChild))
				return XML_LOADER_ERROR;

			m_pTmpContainer = null_v;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnd))
		{
			if (SUCCESS != LoadProgram(&CUIManager::Instance()->Data(),
									   CUIManager::Instance()->EndProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}

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

	return SUCCESS;
}
示例#13
0
ret_ CXMLLoaderActions::LoadProcessBlock(CProgram &Program,
										 const DOMElement *pElement,
										 const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

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

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str wsEmpty				("empty");
	auto_xerces_str	wsUnitaryCalculate	("unitary_calculate");
	auto_xerces_str	wsDualityCalculate	("duality_calculate");
	auto_xerces_str wsConfigGroup		("config_group");
	auto_xerces_str	wsIf				("if");
	auto_xerces_str	wsWhile				("while");
	auto_xerces_str wsContinue			("continue");
	auto_xerces_str wsBlock				("block");
	auto_xerces_str wsBreak				("break");
	auto_xerces_str	wsSend				("send");
	auto_xerces_str wsReadFile			("read_file");
	auto_xerces_str wsSaveFile			("save_file");
	auto_xerces_str wsDeleteFile		("delete_file");
	auto_xerces_str wsSplit				("split");
	auto_xerces_str	wsDie				("die");
	auto_xerces_str wsShowWindow		("show_window");
	auto_xerces_str wsWaitMessage		("wait_message");
	auto_xerces_str wsAlert				("alert");
	auto_xerces_str wsEnable			("enable");
	auto_xerces_str wsAddItem			("add_item");
	auto_xerces_str wsProgram			("program");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsEmpty))
		{
			if (SUCCESS != LoadEmpty(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsUnitaryCalculate))
		{
			if (SUCCESS != LoadUnitaryCalculate(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDualityCalculate))
		{
			if (SUCCESS != LoadDualityCalculate(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsConfigGroup))
		{
			if (SUCCESS != LoadConfigGroup(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsIf))
		{
			if (SUCCESS != LoadIf(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsWhile))
		{
			if (SUCCESS != LoadWhile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsContinue))
		{
			if (SUCCESS != LoadContinue(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsBlock))
		{
			if (SUCCESS != LoadBlock(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsBreak))
		{
			if (SUCCESS != LoadBreak(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSend))
		{
			if (SUCCESS != LoadSend(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsReadFile))
		{
			if (SUCCESS != LoadReadFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSaveFile))
		{
			if (SUCCESS != LoadSaveFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDeleteFile))
		{
			if (SUCCESS != LoadDeleteFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSplit))
		{
			if (SUCCESS != LoadSplit(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDie))
		{
			if (SUCCESS != LoadDie(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsShowWindow))
		{
			if (SUCCESS != LoadShowWindow(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsWaitMessage))
		{
			if (SUCCESS != LoadWaitMessage(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsAlert))
		{
			if (SUCCESS != LoadAlert(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnable))
		{
			if (SUCCESS != LoadEnable(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsAddItem))
		{
			if (SUCCESS != LoadAddItem(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProgram))
		{
			CProgram *pSubProgram = new CProgram();

			if (SUCCESS != LoadProgram(&Program.Data(),
										*pSubProgram,
										pChild,
										pPDU))
            {
				return XML_LOADER_ERROR;
            }

			if (false_v == Program.AddOperator(pSubProgram))
				return XML_LOADER_ERROR;
		}

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

	return SUCCESS;
}
示例#14
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);
}
示例#15
0
bool XmlWorldReader::Read(const std::string &file) {
	// ワールドを初期化
	try {
		initialize();
		if (initFlag) {
			initializeWorld();
		}
	} catch (...) {
		return false;
	}

	// TODO: ファイルの有無を確認

	// XMLファイルをパース
	const XMLCh gLS[] = {chLatin_L, chLatin_S, chNull};
	DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
	DOMLSParser *parser = impl->createLSParser(
		DOMImplementationLS::MODE_SYNCHRONOUS, NULL
	);
	DOMDocument *doc = parser->parseURI(file.c_str());
	if (doc == nullptr) {
		return false;
	}

	// rootノードを取得
	DOMElement *worldElement = doc->getDocumentElement();
	if (worldElement == nullptr) {
		parser->release();
		return false;
	}
	{
		YPT::XmlString temp("world");
		bool res = XMLString::equals(worldElement->getNodeName(), temp);
		if (!res) {
			parser->release();
			return false;
		}
	}

	// ロード用クラス作成
	YPT::XmlWorldPartReader partReader(doc);

	// XPathコンテキスト作成
	DOMXPathNSResolver *resolver = doc->createNSResolver(worldElement);
	if (resolver == nullptr) {
		parser->release();
		return false;
	}

	YPT::XmlString str, str2;
	DOMXPathResult *result;

	// --------------------------------------------------
	// ワールド全体の設定
	// --------------------------------------------------

	// ワールド名
	str = worldElement->getAttribute(YPT::XmlString("name"));
	if (str != "") {
		name = str;
	}

	// 重力ベクトル
	result = doc->evaluate(
		YPT::XmlString("./gravity"), worldElement, resolver,
		DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
		NULL
	);
	if (result != nullptr) {
		if (result->getSnapshotLength() >= 1) {
			str = result->getNodeValue()->getTextContent();
			b2Vec2 temp;
			if (!YPT::ConvertStrToVec2(str.ToChar(), &temp)) {
				world.SetGravity(temp);
			}
		}
		result->release();
	}

	// --------------------------------------------------
	// shapes
	// --------------------------------------------------

	result = doc->evaluate(
		YPT::XmlString("./shape"), worldElement, resolver,
		DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
		NULL
	);
	if (result != nullptr) {
		const XMLSize_t len = result->getSnapshotLength();
		for (XMLSize_t i = 0; i < len; ++i) {
			result->snapshotItem(i);
			DOMNode *node = result->getNodeValue();
			if (node == nullptr) {
				continue;
			}
			DOMNamedNodeMap *nodeMap = node->getAttributes();
			if (nodeMap == nullptr) {
				continue;
			}
			DOMNode *typeNode = nodeMap->getNamedItem(YPT::XmlString("type"));
			if (typeNode == nullptr) {
				continue;
			}
			str = typeNode->getNodeValue();
			b2Shape::Type type;
			int index;
			if (str == "circle") {
				type = b2Shape::e_circle;
				b2CircleShape temp;
				if (partReader.ReadCircleShape(node, &temp)) {
					circleShapes.push_back(temp);
					index = circleShapes.size()-1;
				} else {
					// 読み込み失敗
					continue;
				}
			} else if (str == "edge") {
				type = b2Shape::e_edge;
				b2EdgeShape temp;
				if (partReader.ReadEdgeShape(node, &temp)) {
					edgeShapes.push_back(temp);
					index = edgeShapes.size()-1;
				} else {
					// 読み込み失敗
					continue;
				}
			} else if (str == "polygon") {
				type = b2Shape::e_polygon;
				b2PolygonShape temp;
				if (partReader.ReadPolygonShape(node, &temp)) {
					polygonShapes.push_back(temp);
					index = polygonShapes.size()-1;
				} else {
					// 読み込み失敗
					continue;
				}
			} else if (str == "chain") {
				type = b2Shape::e_chain;
				b2ChainShape temp;
				if (partReader.ReadChainShape(node, &temp)) {
					chainShapes.push_back(temp);
					index = chainShapes.size()-1;
				} else {
					// 読み込み失敗
					continue;
				}
			} else {
				// 未対応
				continue;
			}

			// nameプロパティがあれば保存
			DOMNode *name = nodeMap->getNamedItem(YPT::XmlString("name"));
			if (name != nullptr) {
				str = name->getNodeValue();
				shapes.insert(ShapesMap::value_type(
					std::string(str),
					std::make_pair(type, index)
				));
			}
		}
		result->release();
	}

	// --------------------------------------------------
	// fixtures
	// --------------------------------------------------

	result = doc->evaluate(
		YPT::XmlString("./fixture"), worldElement, resolver,
		DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
		NULL
	);
	if (result != nullptr) {
		const XMLSize_t len = result->getSnapshotLength();
		for (XMLSize_t i = 0; i < len; ++i) {
			result->snapshotItem(i);
			DOMNode *node = result->getNodeValue();
			if (node == nullptr) {
				continue;
			}
			DOMXPathResult *result2 = doc->evaluate(
				YPT::XmlString("./shape"), node, resolver,
				DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
				NULL
			);
			if (result2 == nullptr) {
				continue;
			}
			DOMNode *shapeNode = result2->getNodeValue();
			if (shapeNode == nullptr) {
				continue;
			}
			str = shapeNode->getTextContent();
			result2->release();
			ShapesMap::iterator found = shapes.find(std::string(str));
			if (found == shapes.end()) {
				continue;
			}

			// fixture読み込み
			b2FixtureDef fixtureDef;
			b2Shape *shape = NULL;
			int index = found->second.second;
			switch (found->second.first) {
			case b2Shape::e_circle:
				shape = &circleShapes[index];
				break;
			case b2Shape::e_edge:
				shape = &edgeShapes[index];
				break;
			case b2Shape::e_polygon:
				shape = &polygonShapes[index];
				break;
			case b2Shape::e_chain:
				shape = &chainShapes[index];
				break;
			default:
				// 未対応
				break;
			}
			if (shape == NULL) {
				continue;
			}
			if (partReader.ReadFixture(node, shape, &fixtureDef)) {
				// 読み込み成功
				// nameプロパティがあれば保存する
				DOMNamedNodeMap *nodeMap = node->getAttributes();
				if (nodeMap == nullptr) {
					continue;
				}
				DOMNode *nameNode = nodeMap->getNamedItem(YPT::XmlString("name"));
				if (nameNode == nullptr) {
					continue;
				}
				str = nameNode->getNodeValue();
				fixtures.insert(FixturesMap::value_type(
					std::string(str), fixtureDef
				));
			}
		}
		result->release();
	}

	// --------------------------------------------------
	// bodies
	// --------------------------------------------------

	result = doc->evaluate(
		YPT::XmlString("./body"), worldElement, resolver,
		DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
		NULL
	);
	if (result != nullptr) {
		const XMLSize_t len = result->getSnapshotLength();
		for (XMLSize_t i = 0; i < len; ++i) {
			result->snapshotItem(i);
			DOMNode *node = result->getNodeValue();
			if (node == nullptr) {
				continue;
			}
			DOMXPathResult *result2 = doc->evaluate(
				YPT::XmlString("./fixtures/fixture"), node, resolver,
				DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
				NULL
			);
			if (result2 == nullptr) {
				continue;
			}
			std::vector< b2FixtureDef *> fixtureDefs;
			const XMLSize_t fixturesLen = result2->getSnapshotLength();
			for (XMLSize_t j = 0; j < fixturesLen; ++j) {
				result2->snapshotItem(j);
				DOMNode *fixtureNode = result2->getNodeValue();
				if (fixtureNode == nullptr) {
					continue;
				}
				str = fixtureNode->getTextContent();
				FixturesMap::iterator found = fixtures.find(
					std::string(str)
				);
				if (found != fixtures.end()) {
					fixtureDefs.push_back(&found->second);
				}
			}
			result2->release();

			b2Body *body = partReader.ReadBody(world, node, fixtureDefs);
			if (body != nullptr) {
				// 読み込み成功
				// nameプロパティがあれば保存する
				DOMNamedNodeMap *nodeMap = node->getAttributes();
				if (nodeMap == nullptr) {
					continue;
				}
				DOMNode *nameNode = nodeMap->getNamedItem(YPT::XmlString("name"));
				if (nameNode == nullptr) {
					continue;
				}
				str = nameNode->getNodeValue();
				bodies.insert(BodiesMap::value_type(
					std::string(str), body
				));
			}
		}
		result->release();
	}

	// --------------------------------------------------
	// 読み込み完了
	// --------------------------------------------------

	resolver->release();
	parser->release();

	return true;
}
示例#16
0
ret_ CXMLLoaderActions::LoadSend(CProgram &Program,
								 const DOMElement *pElement,
								 const CPDUInfo *pPDU)

{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	//
	CProtocolInfo *pProtocol = CProtocolManager::Instance()->GetProtocol();

	//
	auto_xerces_str	wsPDU	("pdu");
	auto_xerces_str	sPDU	(pElement->getAttribute(wsPDU));

	CPDUInfo *pPDUInfo = null_v;

	if (SUCCESS != (pProtocol->GetPDU(sPDU, pPDUInfo)))
		return XML_LOADER_ERROR;

	COptSend *pOperator = new COptSend(pPDUInfo);
	
	// For send operation, sub elements are not necessary.
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (pSub)
	{
		auto_xerces_str wsFieldVariable("field_variable");
		auto_xerces_str	wsFieldName("field_name");

		while (pSub)
		{
			if (0 == XMLString::compareString(pSub->getNodeName(), wsFieldVariable))
			{
				//
				DOMElement	*pVariable = (DOMElement *)pSub->getFirstChild();
				CAutoPtr<CVariable> OV_;

				if (!pVariable)
					return XML_LOADER_ERROR;

				while (pVariable)
				{
					ret_ Ret = LoadVariable(Program.Data(), 
											pVariable, 
											OV_.Ptr(),
											pPDU);

					if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
						return Ret;

					if (SUCCESS == Ret)
						break;

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

				//
				auto_xerces_str	sFieldName(pSub->getAttribute(wsFieldName));
				CField *pField = null_v;
			
				if (SUCCESS != pPDUInfo->GetField(sFieldName, pField))
					return XML_LOADER_ERROR;
			
				//
				if (false_v == pOperator->AddEvaluate(sFieldName, OV_.Ptr()))
					return XML_LOADER_ERROR;
			}

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

	if (false_v == Program.AddOperator(pOperator))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
示例#17
0
ret_ CXMLLoaderActions::LoadWhile(CProgram &Program,
								  const DOMElement *pElement,
								  const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_3);
#endif

	auto_xerces_str	wsPosition	("position");
	auto_xerces_str	sPosition	(pElement->getAttribute(wsPosition));
	bool_			b = true_v;

	if (0 == strcmp(sPosition, "head"))
		b = true_v;
	else if (0 == strcmp(sPosition, "foot"))
		b = false_v;

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

	if (!pSub)
		return XML_LOADER_ERROR;

	auto_xerces_str wsDataBlock			("data_block");
	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsProcessBlock		("process_block");

	CData Data;
	CExpression *pExpression = null_v;
	CProgramWhile *pPW = null_v;

	Data.SetParent(&Program.Data());

	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  wsDataBlock))
		{
			if (SUCCESS != (LoadDataBlock(Data, pSub)))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsExpressionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsExpressionDuality)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionDuality))
		{
			if (SUCCESS != LoadExpression(Data, pSub, pExpression, pPDU))
				return XML_LOADER_ERROR;
			
			pPW = new CProgramWhile(b, pExpression, &Data);
			pPW->Data().SetParent(&Program.Data());
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsProcessBlock))
		{
			if (!pPW)
				return XML_LOADER_ERROR;
			
			if (SUCCESS != LoadProcessBlock(*pPW, pSub, pPDU))
				return XML_LOADER_ERROR;
		}

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

	if (false_v == Program.AddOperator(pPW))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
bool XmlParser::mergeNodes(DOMElement *mergeEl, DOMElement *patchEl) {

//   cerr << "mergeNodes()\n";

   if (!nodesMatch(mergeEl, patchEl)) {
      if (verbose) {
         cerr << "mergeNodes() - nodes don't match\n";
      }
      return false;
   }
   DOMChildIterator patchIter(patchEl);
   DOMChildIterator mergeIter(mergeEl);
//
//   if (patchIter.getCurrentElement() == NULL) {
//      // No more children of patch node - match
//      if (verbose) {
//         cerr << "Nodes match\n";
//      }
//      processAttributes(mergeEl, patchEl);
//      return true;
//   }
//   if (mergeIter.getCurrentElement() == NULL) {
//      // Missing required children
////      cerr << "mergeNodes() - No children in merge node\n";
//      return false;
//   }
   // Match each child
   for(;;) {
      DOMElement *mergeChildEl = mergeIter.getCurrentElement();
      DOMElement *patchChildEl = patchIter.getCurrentElement();
      if (patchChildEl == NULL) {
         // No more required children (as indicated by patch node)
         if (verbose) {
            cerr << "mergeNodes() - Patch list end\n";
         }
         processAttributes(mergeEl, patchEl);
         return true;
      }
      Actions currentAction = getAction(patchChildEl);
      if (mergeChildEl == NULL) {
         // Reached end of existing children
         if (currentAction == insert) {
            // We've tried matching all the children so we have to insert
            DualString newNodeName(patchChildEl->getNodeName());
            if (verbose)
               cerr << "mergeNodes() - Appending node <" << newNodeName.asCString() << ">\n";
            DOMComment *commentNode = getCommentNode(patchChildEl);
            if (commentNode != NULL) {
               DOMNode *copyOfNode;
               copyOfNode = mergeDocument->importNode(commentNode, true);
               mergeEl->insertBefore(copyOfNode, mergeChildEl);
               copyOfNode = mergeDocument->createTextNode(DualString("\n").asXMLString());
               mergeEl->insertBefore(copyOfNode, mergeChildEl);
            }
            DOMElement *copyOfNode = dynamic_cast< DOMElement* >(mergeDocument->importNode(patchChildEl, true));
            mergeEl->insertBefore(removeActionAttributes(copyOfNode), mergeChildEl);
            patchIter.advanceElement();
            continue;
         }
         else {
            return false;
         }
      }
      if (mergeNodes(mergeChildEl, patchChildEl)) {
         if (currentAction == replace) {
            // We're replacing this node
            DualString newNodeName(patchChildEl->getNodeName());
            if (verbose) {
               cerr << "mergeNodes() - Replacing node <" << newNodeName.asCString() << ">\n";
            }
            DOMComment *commentNode = getCommentNode(patchChildEl);
            if (commentNode != NULL) {
               DOMNode *copyOfNode;
               copyOfNode = mergeDocument->importNode(commentNode, true);
               mergeEl->insertBefore(copyOfNode, mergeChildEl);
               copyOfNode = mergeDocument->createTextNode(DualString("\n").asXMLString());
               mergeEl->insertBefore(copyOfNode, mergeChildEl);
            }
            DOMElement *copyOfNode = dynamic_cast< DOMElement* >(mergeDocument->importNode(patchChildEl, true));
            mergeEl->replaceChild(removeActionAttributes(copyOfNode), mergeChildEl);
            patchIter.advanceElement();
            continue;
         }
         // Successfully merged/matched patch node - advance patch
         if (verbose) {
            cerr << "mergeNodes() - Advancing patch\n";
         }
         patchIter.advanceElement();
      }
      // Advance original only
      if (verbose) {
         cerr << "mergeNodes() - Advancing merge\n";
      }
      mergeIter.advanceElement();
   }
   return 0;
}
static bool
SAMLCheckSubject(const DOMDocument *doc,
                 SAMLTokenData &token)
{
   const DOMElement *subject;
   char *name = g_strdup_printf("%sSubject",
                                token.ns.c_str());
   subject = SAMLFindChildByName(doc->getDocumentElement(), name);
   g_free(name);

   if (NULL == subject) {
      // Should not happen, since this is required element in the schema.
      Log("%s: Missing subject element!\n", __FUNCTION__);
//      ASSERT(0);
      return false;
   }

   const DOMElement *nameID;
   name = g_strdup_printf("%sNameID", token.ns.c_str());
   nameID = SAMLFindChildByName(subject, name);
   g_free(name);
   if (NULL == nameID) {
      /*
       * The schema allows BaseID, NameID, or EncryptedID. The library code
       * for the SSO server only supports NameID. EncryptedID is really
       * complicated (and we don't have decryption keys, so let's not
       * support it for now.
       */

      Log("%s: No NameID element for the subject.\n", __FUNCTION__);
      return false;
   }

   token.subjectName = SAMLStringWrapper(nameID->getTextContent()).c_str();
   Debug("%s: subjectName: '%s'\n", __FUNCTION__, token.subjectName.c_str());

   /*
    * TODO: Investigate: NameID elements can have a NameQualifier attribute.
    * This smells like a domain name, and we might want to include it with
    * subject name (<NameQualifier>\subjectName).
    */

   /*
    * Find all the SubjectConfirmation nodes and see if at least one can be
    * verified.
    */

   name = g_strdup_printf("%sSubjectConfirmation", token.ns.c_str());
   XMLT scName(name);
   g_free(name);
   for (DOMElement *child = subject->getFirstElementChild(); child != NULL;
        child = child->getNextElementSibling()) {

      if (!XMLString::equals(child->getNodeName(), scName.getUnicodeStr())) {
         continue;
      }

      const XMLCh *method = child->getAttribute(MAKE_UNICODE_STRING("Method"));
      if ((NULL == method) || (0 == *method)) {
         // Should not happen, since this is a required attribute.
         ASSERT(0);
         Debug("%s: Missing confirmation method.\n", __FUNCTION__);
         continue;
      }

      if (!XMLString::equals(
             MAKE_UNICODE_STRING("urn:oasis:names:tc:SAML:2.0:cm:bearer"),
             method)) {
         Debug("%s: Non-bearer confirmation method in token", __FUNCTION__);
         continue;
      }

      const DOMElement *subjConfirmData;
      name = g_strdup_printf("%sSubjectConfirmationData", token.ns.c_str());
      subjConfirmData = SAMLFindChildByName(child, name);
      g_free(name);
      if (NULL != subjConfirmData) {
         if (!SAMLCheckTimeAttr(subjConfirmData, "NotBefore", true) ||
             !SAMLCheckTimeAttr(subjConfirmData, "NotOnOrAfter", false)) {
            Warning("%s: subjConfirmData time check failed\n", __FUNCTION__);
            continue;
         }

         const XMLCh *recipient;
         recipient = subjConfirmData->getAttribute(
            MAKE_UNICODE_STRING("Recipient"));
         /*
          * getAttribute() returns a 0-length string, not NULL, if it can't
          * find what it wants.
          */
         if ((0 != XMLString::stringLen(recipient)) &&
             !SAMLCheckAudience(recipient)) {
            Debug("%s: failed recipient check\n", __FUNCTION__);
            continue;
         }
      }

      return true;
   }

   Debug("%s: Could not verify using any SubjectConfirmation elements\n",
         __FUNCTION__);
   return false;
}
示例#20
0
ret_ CXMLLoaderActions::LoadExpression(const CData &Data,
									   const DOMElement *pElement,
									   CExpression *&pExpression,
									   const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);

	if (pExpression)
		return (PARAMETER_NOT_NULL | PARAMETER_3);
#endif

	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsCalculate			("calculate");
	auto_xerces_str wsRelation			("relation");

	if (0 == XMLString::compareString(pElement->getNodeName(),
									  wsExpressionUnitary))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CExpression *pExp = null_v;

		while (pChild)
		{
			if (0 == XMLString::compareString(pChild->getNodeName(),
											  wsExpressionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsExpressionDuality)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionDuality))
			{
				if (SUCCESS != LoadExpression(Data, pChild, pExp, pPDU))
					return XML_LOADER_ERROR;

				break;
			}

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

		if (!pExp)
			return XML_LOADER_ERROR;

		pExpression = (CExpression *)new CExpNot(pExp);
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsExpressionDuality))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		size_ n = 0;
		CExpression *pExp[2] = {null_v, null_v};

		while (pChild)
		{
			if (2 <= n)
				break;

			if (0 == XMLString::compareString(pChild->getNodeName(),
											  wsExpressionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsExpressionDuality)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionDuality))
			{
				if (SUCCESS != LoadExpression(Data, pChild, pExp[n++], pPDU))
					return XML_LOADER_ERROR;
			}

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

		if (2 != n)
			return XML_LOADER_ERROR;

		auto_xerces_str sRelation(pElement->getAttribute(wsRelation));

		if (0 == strcmp((const ch_1 *)sRelation, "and"))
			pExpression = (CExpression *)new CExpAnd(pExp[0], pExp[1]);
		else if (0 == strcmp((const ch_1 *)sRelation, "or"))
			pExpression = (CExpression *)new CExpOr(pExp[0], pExp[1]);
		else
			return XML_LOADER_ERROR;
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsConditionUnitary))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CAutoPtr<CVariable> v;

		while (pChild)
		{
			ret_ Ret = LoadVariable(Data, pChild, v.Ptr(), pPDU);
		
			if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
				return Ret;

			if (SUCCESS == Ret)
				break;

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

		pExpression = new CExpVarUnitary(v.Ptr());
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsConditionDuality))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CAutoPtr<CVariable> v[2];
		size_ n = 0;

		while (pChild)
		{
			ret_ Ret = LoadVariable(Data, pChild, v[n].Ptr(), pPDU);
		
			if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
				return Ret;

			if (SUCCESS == Ret)
				if (2 <= ++n)
					break;

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

		auto_xerces_str sOperator(pElement->getAttribute(wsCalculate));
		ECompareCalculate Calculate;

		if (SUCCESS != GetCompareOperator((const ch_1 *)sOperator, Calculate))
			return XML_LOADER_ERROR;

		pExpression = new CExpVarDuality(v[0].Ptr(), Calculate, v[1].Ptr());
	}

	return SUCCESS;
}
示例#21
0
ret_ CXMLLoaderActions::LoadProcessor(const DOMElement *pElement)
{
#ifdef _DEBUG_
	if (!pElement)
		return PARAMETER_NULL | PARAMETER_2;
#endif

	//
	auto_xerces_str	wsName("name");
	auto_xerces_str wsPDU("pdu");
	auto_xerces_str sName(pElement->getAttribute(wsName));

	auto_xerces_str wsDataBlock("data_block");
	auto_xerces_str wsStart("start");
	auto_xerces_str wsOnClick("on_click");
	auto_xerces_str wsOnMessage("on_message");
	auto_xerces_str wsEnd("end");

	m_pTmpContainer = CUIManager::Instance()->GetContainer(sName);
	
	// Check if there is corresponding container, it should be exist
	if (!m_pTmpContainer)
		return XML_LOADER_ERROR;

	CProtocolInfo *pProtocol = CProtocolManager::Instance()->GetProtocol();

	// Protocol should be loaded
	if (!pProtocol)
		return XML_LOADER_ERROR;

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

	if (!pChild)
		return XML_LOADER_ERROR;

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsDataBlock))
		{
			if (SUCCESS != LoadDataBlock(m_pTmpContainer->Data(), pChild))
				return XML_LOADER_ERROR;

			m_pTmpContainer->Data().SetParent(&CUIManager::Instance()->Data());
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsStart))
		{
			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   m_pTmpContainer->StartProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsOnClick))
		{
			auto_xerces_str sName(pChild->getAttribute(wsName));

			CProgram *pProgram = null_v;

			if (!m_pTmpContainer->AddOnClickProcessor(sName, pProgram))
				return XML_LOADER_ERROR;

			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   *pProgram,
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsOnMessage))
		{
			auto_xerces_str sPDU(pChild->getAttribute(wsPDU));

			CPDUInfo *pPDUInfo = null_v;

			if (SUCCESS != pProtocol->GetPDU(sPDU, pPDUInfo))
				return XML_LOADER_ERROR;

			CProgram *pProgram = null_v;

			if (!m_pTmpContainer->AddMessageProcessor(sPDU, pProgram))
				return XML_LOADER_ERROR;

			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   *pProgram,
									   pChild,
									   pPDUInfo))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnd))
		{
			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   m_pTmpContainer->EndProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}

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

	return SUCCESS;
}
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;
}
示例#23
0
int main(int argc, char *argv[]) {
	
	bool replay = false;
	if (argc>1) if (strcmp(argv[1], "-replay")==0) replay=true;
	if (argc>2) if (strcmp(argv[2], "-replay")==0) replay=true;
	
	if (!replay) generateTestFiles(argc, argv);
	else cleanTestFiles();
	
	fprintf(stderr, "\n\n[[[TEST APPLY DELTA AND COMPARE TO REFERENCES]]]\n\n");
	
	for(int i=0; i<testlevel; i++) {
		fprintf(stderr, "STEP %d\n", i);
		sprintf(s, "./XyDeltaApply ./testdir/ex_delta%03d.xml >./log_deltaApply%03d.txt", i, i);
		fprintf(stderr, "command= %s\n", s);
		int r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: XyDeltaApply return code %d\n", r);
			exit(-1);
			}
		sprintf(s, "cmp ./testdir/example%03d.xml ./testdir/example%03d.xml_expected", i+1, i+1);
		fprintf(stderr, "command= %s\n", s);
		r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: cmp xml files return code %d\n", r);
			exit(-1);
			}
		sprintf(s, "./XyCmpXML ./testdir/example%03d.xml ./testdir/example%03d.xml_expected", i+1, i+1);
		fprintf(stderr, "command= %s\n", s);
		r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: XyCmpXML xml files return code %d\n", r);
			exit(-1);
			}
		sprintf(s, "cmp ./testdir/example%03d.xml.xidmap ./testdir/example%03d.xml_expected.xidmap", i+1, i+1);
		fprintf(stderr, "command= %s\n", s);
		r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: cmp xidmap files return code %d\n", r);
			exit(-1);
			}
		fprintf(stderr, "STEP %d OK\n", i);
		}

	fprintf(stderr, "\n\n[[[DIFF THE XML FILES]]]\n\n");
	std::string previousXidmap ;
	for(int i=0; i<testlevel; i++) {
		for(int moretest=10; moretest>=0; moretest--) {
			char file1[256];
			sprintf(file1, "./testdir/example%03d.xml", i);
			char file2[256];
			sprintf(file2, "./testdir/example%03d.xml", i+1);
		
			fprintf(stderr, "doc1=%s\n", file1);
			fprintf(stderr, "doc2=%s\n", file2);
			XID_DOMDocument doc1(file1, true);
			XID_DOMDocument doc2(file2, false);
			previousXidmap = doc1.getXidMap().String();
			DOMDocument *delta = XyDelta::XyDiff(doc1.getDOMDocumentOwnership(), file1, doc2.getDOMDocumentOwnership(), file2, moretest?NULL:previousXidmap.c_str());
			if (delta==NULL) {
				fprintf(stderr, "ERROR: XyDelta::XyDiff\n");
				exit(-1);
			}
			DOMElement *t = (DOMElement*)(delta->getDocumentElement()->getLastChild());
			if (!t) {
				fprintf(stderr, "ERROR: Could not get <t> node in the delta\n");
				exit(-1);
			}
			if (!XMLString::equals(t->getNodeName(), XMLString::transcode("t"))) {
				fprintf(stderr, "ERROR: Could not get <t> node in the delta (reason #2)\n");
				exit(-1);
			}
			XyLatinStr myXidmap(t->getAttribute(XMLString::transcode("toXidMap")));
			previousXidmap = myXidmap.localForm();
			fprintf(stderr, "found new xidmap: %s\n", previousXidmap.c_str());

			XID_DOMDocument deltadoc(delta);
			char deltaname[256];
			sprintf(deltaname, "./testdir/example%03d.xml.forwardDelta.xml", i);
			deltadoc.SaveAs(deltaname, false);

			fprintf(stderr, "STEP %d OK\n", i);
		}	
	}

	fprintf(stderr, "\n\n[[[DELETE ONE OF THE TWO XML FILES SEQUENCE]]]\n\n");

	for(int i=1; i<=testlevel; i++) {
		sprintf(s, "rm -f ./testdir/example%03d.xml ./testdir/example%03d.xml.xidmap", i, i);
		fprintf(stderr, "command= %s\n", s);
		if (system(s)!=0) exit(-1);
		}

	fprintf(stderr, "\n\n[[[RECONSTRUCT AND VERIFY XML FILES WITH RESULTS FROM XYDIFF]]]\n\n");
	for(int i=0; i<testlevel; i++) {
		fprintf(stderr, "STEP %d\n", i);
		sprintf(s, "./XyDeltaApply ./testdir/example%03d.xml.forwardDelta.xml >./testdir/log_diffDeltaApply%03d.txt", i, i);
		fprintf(stderr, "command= %s\n", s);
		int r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: XyDeltaApply return code %d\n", r);
			exit(-1);
			}
		sprintf(s, "cmp ./testdir/example%03d.xml ./testdir/example%03d.xml_expected", i+1, i+1);
		fprintf(stderr, "command= %s\n", s);
		r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: cmp xml files return code %d\n", r);
			exit(-1);
			}
		sprintf(s, "./XyCmpXML ./testdir/example%03d.xml ./testdir/example%03d.xml_expected", i+1, i+1);
		fprintf(stderr, "command= %s\n", s);
		r=system(s);
		if (r!=0) {
			fprintf(stderr, "ERROR: XyCmpXML files return code %d\n", r);
			exit(-1);
			}
		fprintf(stderr, "STEP %d OK\n", i);
		}

	fprintf(stderr, "\n\nWORKS FINE�!!!\n\n");
	exit(0);
	}