static TUIObjectInstance extractTUIObjectInstance(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {

    TUIObjectInstance tuiObjectInstance;
    DOMNode * node = domTreeWalker->getCurrentNode();
    DOMNamedNodeMap * nodeMap = node->getAttributes();

    DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
    if (nameAttribute) {
        tuiObjectInstance.setName(XMLString::transcode(nameAttribute->getNodeValue()));
    }

    DOMNode * tuiTypeNameAttribute = nodeMap->getNamedItem(XMLString::transcode("typename"));
    if (tuiTypeNameAttribute) {
        tuiObjectInstance.setTypeName(XMLString::transcode(tuiTypeNameAttribute->getNodeValue()));
    }

    while (node) {
        if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) {
            XMLCh * textContent = XMLString::replicate(node->getTextContent());
            XMLString::trim(textContent);
            tuiObjectInstance.setDescription(XMLString::transcode(textContent));
            XMLString::release(&textContent);
        }
        node = domTreeWalker->nextNode();
    }

    return tuiObjectInstance;
}
Exemplo n.º 2
0
void
Importer::addVertexToScene
(xercesc::DOMNode* vertexNode, Scene* scene)
{
  DOMNamedNodeMap* attributes = vertexNode->getAttributes();
  DOMNode* indexNode = attributes->getNamedItem(XMLString::transcode("index"));
  DOMNode* typeNode = attributes->getNamedItem(XMLString::transcode("type"));

  int vertex_index = atoi(XMLString::transcode(indexNode->getNodeValue()));
  string vertex_type = XMLString::transcode(typeNode->getNodeValue());  

  XMLCh* x_ch = XMLString::transcode("x");  
  XMLCh* y_ch = XMLString::transcode("y");  
  XMLCh* z_ch = XMLString::transcode("z");  

  float x = getValueFromTag(vertexNode, x_ch);
  float y = getValueFromTag(vertexNode, y_ch);
  float z = getValueFromTag(vertexNode, z_ch);

  // Instanciar la posición del nodo.
  Ogre::Vector3 position(x, y, z);
  // Instanciar el nodo.
  std::cout << vertex_type << std::endl;
  Node n(vertex_index, vertex_type, position);
  // Añadir el nodo a la estructura de grafo.
  scene->getGraph()->addVertex(new GraphVertex(n));

  XMLString::release(&x_ch);
  XMLString::release(&y_ch);
  XMLString::release(&z_ch);
}
Exemplo n.º 3
0
void AcsAlarmTestCase::verifyUserTimestampElement(DOMDocument * doc)
{
	// Verify the user-timestamp element
	DOMNodeList * userTimestampNodes = doc->getElementsByTagName(USER_TIMESTAMP_TAG_NAME);
	CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; no user-properties element found",
		(NULL != userTimestampNodes && userTimestampNodes->getLength() == 1));

	// verify that there are 2 attributes
	DOMNamedNodeMap * attributesMap = userTimestampNodes->item(0)->getAttributes();
	CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; user-timestamp element does not contain 2 attributes",
		(NULL!= attributesMap && attributesMap->getLength() == 2));

	// check for seconds attribute
	DOMNode * secondsValueNode = attributesMap->getNamedItem(SECONDS_TAG_NAME);
	const XMLCh * secondsValue = secondsValueNode->getNodeValue();
	char *secondsCharValue = XMLString::transcode(secondsValue);
	int secondsIntValue = atoi(secondsCharValue);
	XMLString::release(&secondsCharValue);
	CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; user-timestamp element, 'seconds' attribute value is not correct",
		(NULL!= secondsValue && secondsIntValue == SECONDS_VALUE));

	// check for microseconds attribute
	DOMNode * microsecondsValueNode = attributesMap->getNamedItem(MICROSECONDS_TAG_NAME);
	const XMLCh * microsecondsValue = microsecondsValueNode->getNodeValue();
	char *microsecondsCharValue = XMLString::transcode(microsecondsValue);
	int microsecondsIntValue = atoi(microsecondsCharValue);
	XMLString::release(&microsecondsCharValue);
	CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; user-timestamp element, 'microseconds' attribute value is not correct",
		(NULL!= microsecondsValue && microsecondsIntValue == MICROSECONDS_VALUE));

}
Exemplo n.º 4
0
void AcsAlarmTestCase::verifyFaultStateElement(DOMDocument * doc, bool propertiesAndTimestampPopulated)
{
	// Verify that the fault-state element exists
	DOMNodeList * faultStateNodes = doc->getElementsByTagName(FAULT_STATE_TAG_NAME);
	CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; no fault-state element found",
		(NULL != faultStateNodes && faultStateNodes->getLength() == 1));

	// verify that there are the expected attributes (family, member, code) on the fault-state element
	DOMNode * faultStateItem = faultStateNodes->item(0);
	if(NULL != faultStateItem)
	{
		// verify that there are 3 attributes in total
		DOMNamedNodeMap * attributesMap = faultStateItem->getAttributes();
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; fault-state does not contain 3 attributes",
			(NULL!= attributesMap && attributesMap->getLength() == 3));

		// check that the fault-state element has a "family" attribute
		DOMNode * familyNode = attributesMap->getNamedItem(FAMILY_TAG_NAME);
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; fault-state does not contain 'family' attribute",
			(NULL!= familyNode));

		// verify that the value of family attribute is correct
		const XMLCh * familyNodeValue = familyNode->getNodeValue();
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; value of fault-state 'family' is not correct",
			(NULL != familyNodeValue && XMLString::equals(familyNodeValue, FAMILY_VALUE_XMLCH)));

		// check that the fault-state element has a "member" attribute
		DOMNode * memberNode = attributesMap->getNamedItem(MEMBER_TAG_NAME);
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; fault-state does not contain 'member' attribute",
			(NULL!= memberNode));

		// verify that the value of member attribute is correct
		const XMLCh * memberNodeValue = memberNode->getNodeValue();
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; value of fault-state 'member' is not correct",
			(NULL != memberNodeValue && XMLString::equals(memberNodeValue, MEMBER_VALUE_XMLCH)));

		// check that the fault-state element has a "code" attribute
		DOMNode * codeNode = attributesMap->getNamedItem(CODE_TAG_NAME);
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; fault-state does not contain 'code' attribute",
			(NULL!= codeNode));

		// verify that the value of code attribute is correct
		const XMLCh * codeNodeValue = codeNode->getNodeValue();
		char *codeNodeCharValue = XMLString::transcode(codeNodeValue);
		int codeNodeValueInt = atoi(codeNodeCharValue);
		XMLString::release(&codeNodeCharValue);
		CPPUNIT_ASSERT_MESSAGE("FaultState::toXML appears to be broken; value of fault-state 'code' is not correct",
			(NULL != codeNodeValue && codeNodeValueInt == CODE_VALUE));
	}

	verifyDescriptorElement(doc);
	if(propertiesAndTimestampPopulated)
	{
		verifyUserPropertiesElement(doc);
		verifyUserTimestampElement(doc);
	}
}
static MSPInstance extractMSPInstance(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {
    MSPInstance mspInstance;
    map<string, ParameterGroup> parameterGroupMap;

    DOMNode * node = domTreeWalker->getCurrentNode();
    DOMNamedNodeMap * nodeMap = node->getAttributes();

    DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
    if (nameAttribute) {
        mspInstance.setName(XMLString::transcode(nameAttribute->getNodeValue()));
    }

    DOMNode * typeNameAttribute = nodeMap->getNamedItem(XMLString::transcode("typename"));

    if (typeNameAttribute) {
        //TFDEBUG(XMLString::transcode(typeNameAttribute->getNodeValue()));
        mspInstance.setTypeName(XMLString::transcode(typeNameAttribute->getNodeValue()));
    }

    while (node) {
        if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "ParameterGroup") == 0) {
            DOMNamedNodeMap * nodeMap = node->getAttributes();
            string name;
            DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
            if (nameAttribute) {
               name = XMLString::transcode(nameAttribute->getNodeValue());
            }

            XMLNodeFilter * nodeFilter = new XMLNodeFilter();
            DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true);
            ParameterGroup pg = extractParameterGroup(domDocument, d);
            pg.setName(name);
            parameterGroupMap[name] = pg;
            d->release();
            delete nodeFilter;
        } else if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) {
            XMLCh * textContent = XMLString::replicate(node->getTextContent());
            XMLString::trim(textContent);
            mspInstance.setDescription(XMLString::transcode(textContent));
            XMLString::release(&textContent);
        }
        node = domTreeWalker->nextNode();
    }

    ParameterGroup parameterGroup;
    parameterGroup.setName("root");
    parameterGroup.setParameterGroupMap(parameterGroupMap);
    mspInstance.setParameterGroup(parameterGroup);

    return mspInstance;
}
static ParameterGroup extractParameterGroup(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {

    map<string, string> parameterMap;
    map<string, ParameterGroup> parameterGroupMap;

    DOMNode * node = domTreeWalker->nextNode();
    while (node) {
        if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Parameter") == 0) {
            DOMNamedNodeMap * nodeMap = node->getAttributes();

            string name;
            DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
            if (nameAttribute) {
                name = XMLString::transcode(nameAttribute->getNodeValue());
            }
            string value;
            DOMNode * valueAttribute = nodeMap->getNamedItem(XMLString::transcode("value"));
            if (valueAttribute) {
                value = XMLString::transcode(valueAttribute->getNodeValue());
            }
            parameterMap[name] = value;

            //TFINFO("Parameter: " << name << " -> " << value);
        } else if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "ParameterGroup") == 0) {

            DOMNamedNodeMap * nodeMap = node->getAttributes();
            string name;
            DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
            if (nameAttribute) {
                name = XMLString::transcode(nameAttribute->getNodeValue());
            }

            XMLNodeFilter * nodeFilter = new XMLNodeFilter();
            DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true);
            ParameterGroup pg = extractParameterGroup(domDocument, d);
            pg.setName(name);
            parameterGroupMap[name] = pg;
            d->release();
            delete nodeFilter;
        }
        node = domTreeWalker->nextNode();
    }

    ParameterGroup parameterGroup;
    parameterGroup.setParameterMap(parameterMap);
    parameterGroup.setParameterGroupMap(parameterGroupMap);

    return parameterGroup;
}
Exemplo n.º 7
0
const char* SYSTEM::CConfigItem::GetProperties(const char * propName)
{
	if(!propName)
	{
		return NULL;
	}
	if(((DOMElement*)itemElement)->hasAttributes())		//判断当前节点是否存在属性
	{
		DOMNamedNodeMap *pAttributes = ((DOMElement*)itemElement)->getAttributes();
		XMLCh *t = XMLString::transcode(propName);
		DOMAttr *pAttributeNode = (DOMAttr*)pAttributes->getNamedItem(t);
		XMLString::release(&t);
		if( m_curValue != NULL )
			XMLString::release(&m_curValue);
		if(!pAttributeNode)		//属性名称不存在
			m_curValue = NULL;
		else
			m_curValue = XMLString::transcode(pAttributeNode->getValue());
		return m_curValue;
	}
	else
	{
		return NULL;
	}	
}
Exemplo n.º 8
0
void SYSTEM::CConfigItem::SetProperties(const char * propName, const char * value)
{
	if(!propName||!value)
	{
		return;
	}
	if(((DOMElement*)itemElement)->hasAttributes())
	{
		DOMNamedNodeMap *pAttributes = ((DOMElement*)itemElement)->getAttributes();
		XMLCh *t = XMLString::transcode(propName);
		DOMAttr *pAttributeNode = (DOMAttr*)pAttributes->getNamedItem(t);
		XMLString::release(&t);
		if(!pAttributeNode)
		{
			return;	//属性名错误,抛出异常
		}
		t = XMLString::transcode(value);
		pAttributeNode->setValue(t);
		XMLString::release(&t);
	}
	else
	{
		return;
	}	 
}
Exemplo n.º 9
0
/**
 * extract's the value of an attribute and returns it:
 *
 * <parentNode>
 *	<elementNode attribute="returnstring" />
 * </parentNode>
 *
 * the first parentNode found in the document is used. thus, it is expected to be unique.
 *
 * @param parentNode 
 * @param elementNode 
 * @param attribute 
 * @return 
 */
string InputHandler::getAttributeValue(const XMLCh* parentNode, const XMLCh* elementNode, const XMLCh* attribute)
{
crusde_debug("%s, line: %d, InputHandler::getAttributeValue(%s) ", __FILE__, __LINE__, XMLString::transcode(elementNode));

	DOMElement *root = doc->getDocumentElement();
	DOMNodeList *node_list = root->getElementsByTagName(parentNode);
	
	/*if element does not exist, return emptry string*/
	if(node_list->getLength() == 0)
		return string();
		
	DOMNode *child = node_list->item(0)->getFirstChild();

	DOMNamedNodeMap *attributes = NULL;
		
	while (child)
	{
		if( child->getNodeType() == DOMNode::ELEMENT_NODE)
	       	{
			attributes = child->getAttributes();

			if( XMLString::compareIString(child->getNodeName(), elementNode) == 0 )
			{
				char *val = XMLString::transcode(attributes->getNamedItem(attribute)->getNodeValue());
				string value(val);
				XMLString::release(&val);
				return value;
			}
			
		}
		child = child->getNextSibling();
	}
	return string();
}
Exemplo n.º 10
0
static TUIObjectType extractTUIObjectType(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {
    TUIObjectType tuiObjectType;
    DOMNode * node = domTreeWalker->getCurrentNode();
    DOMNamedNodeMap * nodeMap = node->getAttributes();
    DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
    if (nameAttribute) {
        tuiObjectType.setName(XMLString::transcode(nameAttribute->getNodeValue()));
    }

    while (node) {
        if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "PortTypeSequence") == 0) {
            XMLNodeFilter * nodeFilter = new XMLNodeFilter();
            DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true);
            tuiObjectType.setPortMap(extractPortMap(domDocument, d));
            d->release();
            delete nodeFilter;
        } else if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Description") == 0) {
            XMLCh * textContent = XMLString::replicate(node->getTextContent());
            XMLString::trim(textContent);
            tuiObjectType.setDescription(XMLString::transcode(textContent));
            XMLString::release(&textContent);
        }
        node = domTreeWalker->nextNode();
    }
    return tuiObjectType;
}
Exemplo n.º 11
0
static DeviceInstance extractDeviceInstance(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {
    DeviceInstance deviceInstance;
    map<string, ParameterGroup> parameterGroupMap;

    DOMNode * node = domTreeWalker->getCurrentNode();
    DOMNamedNodeMap * nodeMap = node->getAttributes();

    DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
    if (nameAttribute) {
        deviceInstance.setName(XMLString::transcode(nameAttribute->getNodeValue()));
    }

    DOMNode * typenameAttribute = nodeMap->getNamedItem(XMLString::transcode("typename"));
    if (typenameAttribute) {
        deviceInstance.setDeviceTypeName(XMLString::transcode(typenameAttribute->getNodeValue()));
    }

    while (node) {
        if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "ParameterGroup") == 0) {
            DOMNamedNodeMap * nodeMap = node->getAttributes();
            string name;
            DOMNode * nameAttribute = nodeMap->getNamedItem(XMLString::transcode("name"));
            if (nameAttribute) {
               name = XMLString::transcode(nameAttribute->getNodeValue());
            }

            XMLNodeFilter * nodeFilter = new XMLNodeFilter();
            DOMTreeWalker * d = domDocument->createTreeWalker(node, DOMNodeFilter::SHOW_ALL, nodeFilter, true);

            ParameterGroup pg = extractParameterGroup(domDocument, d);
            pg.setName(name);
            parameterGroupMap[name] = pg;

            d->release();
            delete nodeFilter;
        }
        node = domTreeWalker->nextNode();
    }

    ParameterGroup parameterGroup;
    parameterGroup.setName("root");
    parameterGroup.setParameterGroupMap(parameterGroupMap);
    deviceInstance.setParameterGroup(parameterGroup);

    return deviceInstance;
}
Exemplo n.º 12
0
LibraryElement* ColladaObject::CreateLibraryElement(const DOMNode* node)
{
	_ASSERTE(node != NULL);

	if( IsElementNode( node ) == false ) { return NULL; }
	
	DOMNamedNodeMap* attr = node->getAttributes();
	if( attr == NULL ) { return NULL; }

	const DOMNode* type = attr->getNamedItem( (const XMLCh*)L"type" );
	if( type == NULL ) { return NULL; }

	LibraryElement* library = NULL;

	if( IsNodeValueEquals( type, L"ANIMATION" ) )
	{
		library = new AnimationLibrary();
	}
	else if( IsNodeValueEquals( type, L"CAMERA" ) )
	{
		library = new CameraLibrary();
	}
	else if( IsNodeValueEquals( type, L"CODE" ) )
	{
		library = new CodeLibrary();
	}
	else if( IsNodeValueEquals( type, L"CONTROLLER" ) )
	{
		library = new ControllerLibrary();
	}
	else if( IsNodeValueEquals( type, L"GEOMETRY" ) )
	{
		library = new GeometryLibrary();
	}
	else if( IsNodeValueEquals( type, L"IMAGE" ) )
	{
		library = new ImageLibrary();
	}
	else if( IsNodeValueEquals( type, L"LIGHT" ) )
	{
		library = new LightLibrary();
	}
	else if( IsNodeValueEquals( type, L"MATERIAL" ) )
	{
		library = new MaterialLibrary();
	}
	else if( IsNodeValueEquals( type, L"PROGRAM" ) )
	{
		library = new ProgramLibrary();
	}
	else if( IsNodeValueEquals( type, L"TEXTURE" ) )
	{
		library = new TextureLibrary();
	}
	else{ _ASSERTE(!"UnknownLibraryType"); }

	return library;
}
Exemplo n.º 13
0
void
OptionValueParser::parse_category(OptionCategory* category, DOMNode* node)
{
  DOMNodeList* children = node->getChildNodes();

  // Traverse the children
  for (size_t i = 0; i < children->getLength(); ++i)
  {
    DOMNode* item = children->item(i);
 
    if (item->getNodeType() != DOMNode::ELEMENT_NODE)
        continue;
 
    XMLUnicodeString node_name =
      item->getNodeName();

    DOMNamedNodeMap* attributes = item->getAttributes();
 
    XMLUnicodeString name =
      attributes->getNamedItem(XMLUnicodeString("name"))->getNodeValue();

    if (node_name.str() == std::string("OptionCategory"))
      {
        // Parsing a category node
        parse_category(category->category(name.str().c_str()), item);
      }
    else
      {
        // Parsing an option node
        Option* option = category->option(name.str().c_str());

        if (option && (node_name.str() == std::string("BooleanOption")))
          {
            parse_boolean_option((BooleanOption*) option, item);
          }
        else if (option && (node_name.str() == std::string("StringOption")))
          {
            parse_string_option((StringOption*) option, item);
          }
        else if (option && (node_name.str() == std::string("IntegerOption")))
          {
            parse_integer_option((IntegerOption*) option, item);
          }
        else if (option && (node_name.str() == std::string("EnumOption")))
          {
            parse_enum_option((EnumOption*) option, item);
          }
/*
        else
          throw UnknownOptionKind(name.str());
*/
      }
  }
}
Exemplo n.º 14
0
set<StringTable::countryCode>
XMLIndata::parseCountryList(const DOMNode* cntrListTopNode){
   set<StringTable::countryCode> countryList;
   mc2dbg << "Parsing country list" << endl;


   const XMLCh* name = cntrListTopNode->getNodeName();
   if ( ! WFXMLStr::equals(name, "country_list") ){
      mc2log << error << "Strange country list element name: " << name 
             << endl;
      MC2_ASSERT(false);
   }

   const DOMNodeList* countryNodes = cntrListTopNode->getChildNodes();
   for (XMLSize_t i=0; i<countryNodes->getLength(); i++){
      DOMNode* countryNode = countryNodes->item(i);
      DOMNode::NodeType nodeType = 
         static_cast<DOMNode::NodeType>(countryNode->getNodeType());
      const XMLCh* name = countryNode->getNodeName();
      if ( nodeType == DOMNode::ELEMENT_NODE ){
         if ( WFXMLStr::equals(name,"country") ){
            DOMNamedNodeMap* attributes = countryNode->getAttributes();
            DOMNode* attribute = 
               attributes->getNamedItem( X( "id_string" ) );
            MC2_ASSERT( attribute != NULL );
            MC2String gmsName = 
               XMLString::transcode( attribute->getNodeValue() );
            StringTable::countryCode countryCode = 
               MapGenUtil::getCountryCodeFromGmsName( gmsName );
            mc2dbg << "   Country: " << gmsName << " " 
                   << countryCode << endl;
            if ( countryCode == StringTable::NBR_COUNTRY_CODES ){
               mc2log << error << "Strange GMS name: " 
                      << gmsName << endl;
               MC2_ASSERT(false);
            }
            countryList.insert(countryCode);
         }
         else {
            mc2log << error << "Strange element name: " << name << endl;
            MC2_ASSERT(false);
         }
      }
      else if ( nodeType == DOMNode::COMMENT_NODE ){
         // Don't bother with comments.
      }
      else {
         mc2log << error << "Strange node type: " << nodeType << endl;
         MC2_ASSERT(false);
      }
   }

   return countryList;
} // parseCountryList
Exemplo n.º 15
0
static PortAddress extractPortAddress(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {
    PortAddress portAddress;

    DOMNode * node = domTreeWalker->getCurrentNode();
    DOMNamedNodeMap * nodeMap = node->getAttributes();

    // entityType = DEV | TUI | MSP
    DOMNode * entityTypeAttribute = nodeMap->getNamedItem(XMLString::transcode("entityType"));
    if (entityTypeAttribute) {
        if (XMLString::compareString(XMLString::transcode(entityTypeAttribute->getNodeValue()), "DEV") == 0) {
            //TFINFO("DEV");
            portAddress.setOwnerType(PortAddress::DEVICE);
        } else if (XMLString::compareString(XMLString::transcode(entityTypeAttribute->getNodeValue()), "TUI") == 0) {
            //TFINFO("TUI");
            portAddress.setOwnerType(PortAddress::TUIOBJECT);
        } else if (XMLString::compareString(XMLString::transcode(entityTypeAttribute->getNodeValue()), "MSP") == 0) {
            //TFINFO("MSP");
            portAddress.setOwnerType(PortAddress::MSP);
        } else {
            // TODO throw Exception
            TFERROR("");
        }
    } else {
        TFERROR("No entityType found")
    }

    DOMNode * entityNameAttribute = nodeMap->getNamedItem(XMLString::transcode("entityName"));
    if (entityNameAttribute) {
        portAddress.setName(XMLString::transcode(entityNameAttribute->getNodeValue()));
    } else {
        TFERROR("No entityName found")
    }
    DOMNode * portNameAttribute = nodeMap->getNamedItem(XMLString::transcode("portName"));
    if (portNameAttribute) {
        portAddress.setPortName(XMLString::transcode(portNameAttribute->getNodeValue()));
    } else {
        TFERROR("No portName found")
    }

    return portAddress;
}
Exemplo n.º 16
0
/**
 *  Retrieve the value of an attribute
 *  @param node the DOMNode we are extracting an attribute from
 *  @param name the name of the attribute we want
 *  @return the value of the attribute or NULL if no such attribute is found
 */
char* getAttribute(DOMNode* node, const char* name) {
	if (node == NULL)
		return NULL;

	DOMNamedNodeMap* map = node->getAttributes();
	if (map == NULL)
		return NULL;

	DOMNode* attribute = map->getNamedItem(XMLString::transcode(name));
	if (attribute == NULL)
		return NULL;

	return XMLString::transcode(attribute->getNodeValue());
}
Exemplo n.º 17
0
string InputHandler::getAttributeValueByName(const XMLCh* elementNode, const XMLCh* attribute, const XMLCh* name)
{

     crusde_debug("%s, line: %d, InputHandler::getAttributeValueByName(%s) name = %s ", __FILE__, __LINE__, XMLString::transcode(elementNode),
     XMLString::transcode(name));
     assert(doc);

     DOMElement *root = doc->getDocumentElement();
     DOMNode *child = root->getFirstChild();
     DOMNamedNodeMap *attributes = NULL;
		
     while (child)
     {
          if(child != NULL)
               if( child->getNodeType() == DOMNode::ELEMENT_NODE )
               {
                    if(child->hasAttributes())
                    {
                         attributes = child->getAttributes();

                         if( XMLString::compareIString( child->getNodeName(), elementNode) == 0 && 
                             XMLString::compareIString( attributes->getNamedItem(ATTR_name.xmlStr())->getNodeValue(), name) == 0 )
                         {
                              char *val = XMLString::transcode(attributes->getNamedItem(attribute)->getNodeValue());
                              string value(val);
                              XMLString::release(&val);
                              return value;
                         }
                    }
               }

          child = child->getNextSibling();
     }
	
     return string();
}
static long getRequiredLongOrThrow( DOMNode* node, const char* attribName )
   throw ( XMLServerErrorMsg ) {
   DOMNamedNodeMap* attribs = node->getAttributes();
   DOMNode* attrib_to_find = attribs->getNamedItem( X( attribName ) );
   if ( attrib_to_find == NULL ) {
      MC2String nodeName =
         XMLUtility::transcodefrom(node->getNodeName());
      MC2String msg = MC2String("Node \"") + nodeName
         + "\" requires attribute \"" + attribName + '"';
      mc2log << warn << __FUNCTION__ << " " << msg << endl;
      throw XMLServerErrorMsg( "-1",  msg );
   } else {
      // Try to get the value.
      return getLongOrThrow( attrib_to_find, node );
   }                               
}
Exemplo n.º 19
0
bool ConfigurationFileHandler::getSubAlgorithm(std::string algorithm, std::string subalgorithm, std::string* result){
#ifdef BRICS_XERCES_ENABLE
	if (errorsOccured) {
		return false;
	}

    DOMNode* current = NULL;
    DOMNode* attributeNode = NULL;
    XMLCh* algorithmName = XMLString::transcode(algorithm.c_str());
    XMLCh* subAlgorithmName = XMLString::transcode(subalgorithm.c_str());
    XMLCh* implementationString = XMLString::transcode("implementation");
    bool subAlgorithmFound = false;

    DOMDocument* doc = parser->getDocument();
    DOMNodeList* root = doc->getElementsByTagName(algorithmName);
    if (root->getLength() > 1) {
    	LOG(WARNING) << "More than one " << algorithm << " found, taking the first one";
    } else if(root->getLength() < 1) {
    	LOG(WARNING) << "No algorithm called " << algorithm << " found.";
		return false; //TODO release resouces
    }

    current = root->item(0);

    //search in children notes
	for (current = current->getFirstChild()->getNextSibling(); current!=NULL; current = current->getNextSibling()) {
		string nodeName = XMLString::transcode(current->getNodeName());
		if (nodeName.compare(subalgorithm) == 0) {
		    DOMNamedNodeMap* attributesList =  current->getAttributes();
		    attributeNode = attributesList->getNamedItem(implementationString);
		    if (attributeNode != 0) {
		    	*result = XMLString::transcode(attributeNode->getNodeValue());
		    	subAlgorithmFound = true;
		    	break; //take only first found
		    }
		}
	}

    XMLString::release(&algorithmName);
    XMLString::release(&subAlgorithmName);
    XMLString::release(&implementationString);

    return subAlgorithmFound;
#else
    return false;
#endif
}
Exemplo n.º 20
0
static ServerStartupConfig extractServerStartupConfig(DOMDocument * domDocument, DOMTreeWalker * domTreeWalker) {
    ServerStartupConfig serverStartupConfig;
    DOMNode * node = domTreeWalker->getCurrentNode();
    while (node) {
        if (XMLString::compareString(XMLString::transcode(node->getNodeName()), "Network") == 0) {
            DOMNamedNodeMap * nodeMap = node->getAttributes();
            DOMNode * portAttribute = nodeMap->getNamedItem(XMLString::transcode("port"));
            if (portAttribute) {
                
                serverStartupConfig.setPortNr(XMLString::parseInt(portAttribute->getNodeValue()));
            }
        }
        node = domTreeWalker->nextNode();
    }

    return serverStartupConfig;
}
Exemplo n.º 21
0
static void removeBaseAttr(DOMDocument * domDocument) {

    XMLNodeFilter * nodeFilter = new XMLNodeFilter();
    DOMTreeWalker * domTreeWalker = domDocument->createTreeWalker(domDocument, DOMNodeFilter::SHOW_ALL, nodeFilter, true);

    DOMNode * node = domTreeWalker->getCurrentNode();
    while (node) {
        DOMNamedNodeMap * nodeMap = node->getAttributes();
        if (nodeMap != 0) {
            DOMNode * attr = nodeMap->getNamedItem(XMLString::transcode("xml:base"));
            if (attr) {
                DOMNode * node = nodeMap->removeNamedItem(XMLString::transcode("xml:base"));

                TFINFO("[Server Config] filtered attribute: " << XMLString::transcode(node->getNodeName()) << "=" << XMLString::transcode(node->getNodeValue()));
                node->release();
            }
        }
        node = domTreeWalker->nextNode();
    }
    delete nodeFilter;
}
Exemplo n.º 22
0
bool ConfigurationFileHandler::getAttribute(std::string algorithm, std::string attribute, int* result) {
#ifdef BRICS_XERCES_ENABLE
	if (errorsOccured) {
		return false;
	}

    DOMNode* current = NULL;
    DOMNode* attributeNode = NULL;
    XMLCh* algorithmName = XMLString::transcode(algorithm.c_str());
    XMLCh* attributeName = XMLString::transcode(attribute.c_str());
    string tmpResult;
    bool attributeFound = false;

    DOMDocument* doc = parser->getDocument();
    DOMNodeList* root = doc->getElementsByTagName(algorithmName);
    if (root->getLength() > 1) {
    	LOG(WARNING) << "More than one " << algorithm << " found, taking the first one";
    } else if(root->getLength() < 1) {
    	LOG(WARNING) << "No algorithm called " << algorithm << " found.";
		return false; //TODO release resouces
    }

    current = root->item(0);
    DOMNamedNodeMap* attributesList =  current->getAttributes();
    attributeNode = attributesList->getNamedItem(attributeName);

    if (attributeNode != 0) {
		    tmpResult = XMLString::transcode(attributeNode->getNodeValue());
		    *result = atoi(tmpResult.c_str());
		    attributeFound = true;
	}

    XMLString::release(&algorithmName);
    XMLString::release(&attributeName);

    return attributeFound;
#else
    return false;
#endif
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
void VART::XmlAction::LoadAnimation(const Source& jointSource)
// Called by LoadFromFile after parsing to actually build the action from file.
{
    static VART::LinearInterpolator linearInterpolator; // common interpolator for all joint movers
    static VART::SineInterpolator sineInterpolator;     // common interpolator for all joint movers
    istringstream stream; // helper for converting strings to numbers
    char* charAux; // helper for converting XMLStrings to C strings
    unsigned int i, j, k; // loop counters (aaargh!)
    float dur, speed; // duration and speed of the action
    bool cycle;       // cyclic status of the action
    string dofIdentifier, jName, itplName;
    XMLCh* xmlStr; // helper for converting C strings to XMLStrings
    DOMNodeList* actionList;
    DOMNamedNodeMap* attrAc; // attributes for the action
    VART::JointMover* jointMPtr;

    // Get list of actions (but there should be only one!)
    xmlStr = XMLString::transcode("action");
    actionList = documentPtr->getElementsByTagName(xmlStr);
    XMLString::release(&xmlStr);

    attrAc = documentPtr->getDocumentElement()->getAttributes();

    // Read speed value
    xmlStr = XMLString::transcode("speed");
    charAux = XMLString::transcode(attrAc->getNamedItem(xmlStr)->getNodeValue());
    stream.clear();
    stream.str(charAux);
    stream >> speed;
    XMLString::release(&xmlStr);
    XMLString::release(&charAux);

    // Read cyclic value
    xmlStr = XMLString::transcode("cycle");
    charAux = XMLString::transcode(attrAc->getNamedItem(xmlStr)->getNodeValue());
    cycle = (strcmp(charAux, "true") == 0);
    XMLString::release(&xmlStr);
    XMLString::release(&charAux);

    // Set action attributes
    Set(speed, 1, cycle); //Priority default is 1.

    // For each action (but there should be only one!):
    for (i = 0; i<actionList->getLength(); i++)
    {
        DOMNodeList* jointsL = actionList->item(i)->getChildNodes();

        // For each joint movement:
        for (j = 0; j<jointsL->getLength(); j++)
        {
            bool isJointMovement;

            charAux = XMLString::transcode(jointsL->item(j)->getNodeName());
            isJointMovement = (strcmp(charAux, "joint_movement") == 0);
            XMLString::release(&charAux);

            if (isJointMovement)
            {
                Joint* jointPtr;
                DOMNamedNodeMap* attrLt = jointsL->item(j)->getAttributes();

                // Read joint mover's duration value
                xmlStr = XMLString::transcode("duration");
                charAux = XMLString::transcode(attrLt->getNamedItem(xmlStr)->getNodeValue());
                stream.clear();
                stream.str(charAux);
                stream >> dur;
                XMLString::release(&xmlStr);
                XMLString::release(&charAux);

                // Read joint mover's target joint name
                xmlStr = XMLString::transcode("joint_name");
                charAux = XMLString::transcode(attrLt->getNamedItem(xmlStr)->getNodeValue());
                jName = charAux;
                XMLString::release(&xmlStr);
                XMLString::release(&charAux);

                jointPtr = jointSource.GetJointByName(jName);
                if (jointPtr)
                {
                    DOMNodeList* dofsL = jointsL->item(j)->getChildNodes();

                    // It is now almost safe to create a joint mover :)
                    // Add an ease-in, ease-out interpolator as default. Change it when the
                    // interpolator gets known.
                    jointMPtr = AddJointMover(jointPtr, dur, sineInterpolator);

    
                    // For each element of a joint movement (may be interpolator or dof movement):
                    for(k = 0; k<dofsL->getLength(); k++)
                    {
                        bool isInterpolation;

                        charAux = XMLString::transcode(dofsL->item(k)->getNodeName());
                        isInterpolation = (strcmp(charAux, "interpolation") == 0);
                        XMLString::release(&charAux);
                        if (isInterpolation)
                        {
                            DOMNamedNodeMap* attrInterpLt = dofsL->item(k)->getAttributes();

                            // Read interpolation type
                            xmlStr = XMLString::transcode("type");
                            charAux = XMLString::transcode(attrInterpLt->getNamedItem(xmlStr)->getNodeValue());
                            itplName = charAux;
                            XMLString::release(&xmlStr);
                            XMLString::release(&charAux);

                            // Change interpolator if it is different from default (ease-in/ease-out) value
                            if (itplName != "ease-in_ease-out")
                            {
                                if (itplName == "linear")
                                    jointMPtr->SetInterpolator(linearInterpolator);
                                else if (itplName == "range_sine")
                                {
                                    Interpolator* interpolatorPtr = new RangeSineInterpolator;
                                    jointMPtr->SetInterpolator(*interpolatorPtr);
                                }
                                else
                                    cerr << "Error: Unknown interpolator: '" << itplName
                                         << "'. Using: 'ease-in_ease-out'." << endl;
                            }
                        }
                        else // item is not "interpolation"
                        {
                            charAux = XMLString::transcode(dofsL->item(k)->getNodeName());
                            if(strcmp(charAux, "dof_movement") == 0)
                                ParseDofMovement(jointMPtr, dofsL->item(k));
                            XMLString::release(&charAux);
                        }
                    }
                }
                else // the target joint was not found
                {
                    cerr << "Error: Joint mover targeting at '" << jName
                         << "': No such scene node!" << endl;
                }
            }
        }
    }
}
Exemplo n.º 25
0
void VART::XmlAction::ParseDofMovement(JointMover* jointMPtr, DOMNode* dofMovItemPtr)
// Called by LoadAnimation to create a dof mover from a XML entry.
// FixMe: Memory allocated for the interpolators is never released.
{
    DOMNodeList* dofMovElements;
    DOMNamedNodeMap* attrPt;
    XMLCh* xmlStr; // helper for converting C strings to XMLStrings
    float inTime;
    float fTime;
    float fPos;
    float noiseAmplitude;
    float noiseWaveLenght;
    float overshoot;
    float offset;
    float peakTime;
    char* charAux;
    char* cstr_nodeName; // a node name (as a C string)
    istringstream stream;
    VART::Joint::DofID dofID;
    unsigned int count;
    bool foundPositionalError = false; // any positional error elements found inside the dof mover?
    bool foundNoise = false;           // any noise elements found inside the dof mover?

    attrPt = dofMovItemPtr->getAttributes();

    xmlStr = XMLString::transcode("initialTime");
    charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
    stream.str(charAux);
    stream >> inTime;
    XMLString::release(&xmlStr);
    XMLString::release(&charAux);

    xmlStr = XMLString::transcode("finalTime");
    charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
    stream.clear();
    stream.str(charAux);
    stream >> fTime;
    XMLString::release(&xmlStr);
    XMLString::release(&charAux);

    xmlStr = XMLString::transcode("finalPosition");
    charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
    stream.clear();
    stream.str(charAux);
    stream >> fPos;
    XMLString::release(&xmlStr);
    XMLString::release(&charAux);

    // Read value for dofID
    xmlStr = XMLString::transcode("dofID");
    charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
    if ((strcmp(charAux, "FLEX") == 0) || (strcmp(charAux, "FLEXION") == 0))
        dofID = VART::Joint::FLEXION;
    else
    {
        if ((strcmp(charAux, "ADDUCT") == 0) || (strcmp(charAux, "ADDUCTION") == 0))
            dofID = VART::Joint::ADDUCTION;
        else
            if (strcmp(charAux, "TWIST") == 0)
                dofID = VART::Joint::TWIST;
            else
            {
                cerr << "XmlAction::ParseDofMovement: Unknown DOF ID" << endl;
                exit (1);
            }
    }
    XMLString::release(&xmlStr);
    XMLString::release(&charAux);

    dofMovElements = dofMovItemPtr->getChildNodes();

    // for each child node of the dof mover (may be "noise" or "error"):
    for (count = 0; count < dofMovElements->getLength(); ++count)
    {
        cstr_nodeName = XMLString::transcode(dofMovElements->item(count)->getNodeName());
        if (strcmp(cstr_nodeName, "noise") == 0)
        {
            attrPt = dofMovElements->item(count)->getAttributes();

            xmlStr = XMLString::transcode("amplitude");
            charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
            stream.clear();
            stream.str(charAux);
            stream >> noiseAmplitude;
            XMLString::release(&xmlStr);
            XMLString::release(&charAux);

            xmlStr = XMLString::transcode("length");
            charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
            stream.clear();
            stream.str(charAux);
            stream >> noiseWaveLenght;
            XMLString::release(&xmlStr);
            XMLString::release(&charAux);

            foundNoise = true;
        }
        else if (strcmp(cstr_nodeName, "error") == 0)
Exemplo n.º 26
0
void FDPLoader::loadFDPItem(DOMNode* pFDPItem)
{
	DOMNamedNodeMap* attrList = pFDPItem->getAttributes();
	FDPItem* pItem = 0;
	// get the name (id)
	DOMNode* attr = attrList->getNamedItem(XercesString("name"));
	if(attr)
	{
		char* name = XMLString::transcode(attr->getNodeValue());
		// create a new item (will be deleted in dtor of FDP class)
		pItem = new FDPItem(name);
		XMLString::release(&name);
	}
	else
		return;
	
	// get the control vertex index
	attr = attrList->getNamedItem(XercesString("index"));
	if(attr)
	{
		char* index = XMLString::transcode(attr->getNodeValue());
		pItem->setControlPoint((unsigned short)atoi(index));
		XMLString::release(&index);
	}

	// get the affecting mesh name
	attr = attrList->getNamedItem(XercesString("affects"));
	if(attr)
	{
		char* affects = XMLString::transcode(attr->getNodeValue());
		pItem->setAffects(affects);
		XMLString::release(&affects);
	}
	
	DOMNodeIterator* iterator = m_pDoc->createNodeIterator(pFDPItem,
		DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_ATTRIBUTE, NULL, true);
	// use the tree walker to print out the text nodes.
	for ( DOMNode* current = iterator->nextNode(); current != 0; current = iterator->nextNode() )
	{
		if(XercesString(current->getNodeName()) == "indices")
		{
			DOMNodeList* children = current->getChildNodes(); 
			// we should have only one child, text node, just a safety net here
			if ( (children->getLength() == 1) && (children->item(0)->getNodeType() == DOMNode::TEXT_NODE) )//(XercesString(children->item(0)->getNodeName()) == "#text") )
			{
				char* pStr = XMLString::transcode(children->item(0)->getNodeValue());
				std::string str(pStr);
				processIndices(str, pItem);
				XMLString::release(&pStr);
			}
		}
		else if (XercesString(current->getNodeName()) == "influence")	// can have multiple of those
		{
			// sample: <influence weight="0.25" fap="3" type="RaisedCosInfluenceWaveY" />
			DOMNamedNodeMap* influenceAttr = current->getAttributes();
			// get the weight
			float w = toFloat(influenceAttr->getNamedItem(XercesString("weight"))->getNodeValue());
			unsigned short fap = (unsigned short)toFloat(influenceAttr->getNamedItem(XercesString("fap"))->getNodeValue());
			char* type = XMLString::transcode(influenceAttr->getNamedItem(XercesString("type"))->getNodeValue());
			
			IInfluenceCalculator* pInfluence = InfluenceCalculatorMaker::newInfluenceCalculator(type, w, fap);
			if(pInfluence)
				pItem->addInfluenceCalculator(pInfluence);
		}
	}

	m_pFDP->insertItem(pItem);
}
Exemplo n.º 27
0
void FDPLoader::loadEntity(DOMNode* pSource)
{
	DOMNamedNodeMap* attrList = pSource->getAttributes();
	std::string alias, category;
	DOMNode* attr = attrList->getNamedItem(XercesString("alias"));
	if(attr)
	{
		char* aliasPtr = XMLString::transcode(attr->getNodeValue());
		alias.assign(aliasPtr);
		XMLString::release(&aliasPtr);
	}

	attr = attrList->getNamedItem(XercesString("category"));
	if(attr)
	{
		char* catPtr = XMLString::transcode(attr->getNodeValue());
		category.assign(catPtr);
		XMLString::release(&catPtr);
	}
		
	DOMNodeIterator* iterator = m_pDoc->createNodeIterator(pSource, 
		DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_ATTRIBUTE, NULL, true);
	// use the tree walker to print out the text nodes.
	for ( DOMNode* current = iterator->nextNode(); current != 0; current = iterator->nextNode() )
	{
		if(XercesString(current->getNodeName()) == "mesh")
		{
			XEngine::MeshInfo info;
			attrList = current->getAttributes();
			attr = attrList->getNamedItem(XercesString("file"));
			if(attr)
				info.file = XMLString::transcode(attr->getNodeValue());
			attr = attrList->getNamedItem(XercesString("format"));
			if(attr)
				info.format = XMLString::transcode(attr->getNodeValue());
			attr = attrList->getNamedItem(XercesString("path"));
			if(attr)
				info.path = XMLString::transcode(attr->getNodeValue());
			else
				info.path.assign("");
			
			info.keyframe_alias = alias;
			info.keyframe_category = category;

			if(alias == "Rest")
				m_faceEntityMeshInfo.push_back(info);
			// push the Rest state into the morph target dictionary as well
			m_morphTargetsMeshInfos[alias].push_back(info);
		}
		else if(XercesString(current->getNodeName()) == "bind")
		{
			XEngine::MeshInfo info;
			std::string submesh, item;
			attrList = current->getAttributes();
			attr = attrList->getNamedItem(XercesString("submesh"));
			if(attr)
				submesh = XMLString::transcode(attr->getNodeValue());
			attr = attrList->getNamedItem(XercesString("item"));
			if(attr)
				item = XMLString::transcode(attr->getNodeValue());
			if(item == "LeftEye" || item == "RightEye") // eye pivots
			{
				Vector3 eye(0, 0, 0);
				//std::string x, y, z;
				attr = attrList->getNamedItem(XercesString("pivotX"));
				if(attr)
					eye.x = toFloat(attr->getNodeValue());
				attr = attrList->getNamedItem(XercesString("pivotY"));
				if(attr)
					eye.y = toFloat(attr->getNodeValue());
				attr = attrList->getNamedItem(XercesString("pivotZ"));
				if(attr)
					eye.z = toFloat(attr->getNodeValue());
				if(item == "LeftEye")
					m_pFDP->setLeftEyePivot(eye);
				else
					m_pFDP->setRightEyePivot(eye);
			}
			
			m_bindings.insert(std::make_pair(submesh, item));
		}
	}
}
Exemplo n.º 28
0
bool FDPLoader::parseHeader(DOMNode* pHeader)
{
	DOMNodeIterator* iterator = m_pDoc->createNodeIterator(pHeader, 
		DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_ATTRIBUTE, NULL, true);
	// use the tree walker to print out the text nodes.
	for ( DOMNode* current = iterator->nextNode(); current != 0; current = iterator->nextNode() )
	{
		// there are "file", "model", "fapu", "translation" and "rotation" elements in this chunk
		if (XercesString(current->getNodeName()) == "file")
		{
			// sample: <file version="0.2" />

			DOMNamedNodeMap* attr = current->getAttributes();
			if(!attr) // sth wrong
				return false;
			DOMNode* versionAttr = attr->getNamedItem(XercesString("version"));
			if(XercesString(m_version.c_str()) != versionAttr->getNodeValue())
				// versions not matching, flee!!
				return false;
		}
		else if(XercesString(current->getNodeName()) == "fapu")
		{
			// sample: <fapu ES0="69.9977" IRISD0="16.0424" ENS0="51.8036" MNS0="30.1538" MW0="50.6392" />
			
			DOMNamedNodeMap* attrList = current->getAttributes();
			if(!attrList) // sth wrong
				return false;

			/////////////// ES0
			DOMNode* attr = attrList->getNamedItem(XercesString("ES0"));
			if(attr)
				m_pFDP->setES0(toFloat(attr->getNodeValue()));
			/////////////// IRISD0
			attr = attrList->getNamedItem(XercesString("IRISD0"));
			if(attr)
				m_pFDP->setIRISD0(toFloat(attr->getNodeValue()));
			/////////////// ENS0
			attr = attrList->getNamedItem(XercesString("ENS0"));
			if(attr)
				m_pFDP->setENS0(toFloat(attr->getNodeValue()));
			/////////////// MNS0
			attr = attrList->getNamedItem(XercesString("MNS0"));
			if(attr)
				m_pFDP->setMNS0(toFloat(attr->getNodeValue()));
			/////////////// MW0
			attr = attrList->getNamedItem(XercesString("MW0"));
			if(attr)
				m_pFDP->setMW0(toFloat(attr->getNodeValue()));
			
			// debug << "fapu item" << std::endl;
		}
		else if(XercesString(current->getNodeName()) == "translation")
		{
			// sample: <translation x="0" y="-1" z="-659" />
        
			DOMNamedNodeMap* attrList = current->getAttributes();
			if(!attrList) // sth wrong
				return false;

			float x = 0, y = 0, z = 0;
			/////////////// x translation
			DOMNode* attr = attrList->getNamedItem(XercesString("x"));
			if(attr)
				x = toFloat(attr->getNodeValue());
			
			/////////////// y translation
			attr = attrList->getNamedItem(XercesString("y"));
			if(attr)
				y = toFloat(attr->getNodeValue());
		
			/////////////// z translation
			attr = attrList->getNamedItem(XercesString("z"));
			if(attr)
				z = toFloat(attr->getNodeValue());
		
			m_pFDP->setGlobalTranslation(x, y, z);
		//	debug << "translation item " << x << " " << y << " " << z << std::endl;
		}
		else if(XercesString(current->getNodeName()) == "rotation")
		{
			// sample: <rotation axis_x="-0.998192" axis_y="0.0596591" axis_z="0.00728935" axis_angle="0.444541" />

			DOMNamedNodeMap* attrList = current->getAttributes();
			if(!attrList) // sth wrong
				return false;

			float x = 0, y = 0, z = 0, a = 0;
			/////////////// x rotation
			DOMNode* attr = attrList->getNamedItem(XercesString("axis_x"));
			if(attr)
				x = toFloat(attr->getNodeValue());
			
			/////////////// y rotation
			attr = attrList->getNamedItem(XercesString("axis_y"));
			if(attr)
				y = toFloat(attr->getNodeValue());
		
			/////////////// z rotation
			attr = attrList->getNamedItem(XercesString("axis_z"));
			if(attr)
				z = toFloat(attr->getNodeValue());
		
			/////////////// z rotation
			attr = attrList->getNamedItem(XercesString("axis_angle"));
			if(attr)
				a = toFloat(attr->getNodeValue());
		
			m_pFDP->setGlobalRotation(x, y, z, a);
		}
	}
  
	return true;
}
Exemplo n.º 29
0
bool
XMLIndata::parseContent(const DOMNode* content,
                        multimap<MC2String, ItemIdentifier*>& contents )
{
   if ( XMLString::equals( content->getNodeName(), "content" ) ) {
      
      // Get attributes
      DOMNamedNodeMap* attributes = content->getAttributes();

      
      // Note that map_ident attribute is #REQUIRED.
      DOMNode* attribute = 
         attributes->getNamedItem( X( "map_ident" ) );
      MC2_ASSERT( attribute != NULL );
      char* tmpStr = XMLUtility::transcodefromucs(
            attribute->getNodeValue() );
      MC2String mapIdent( tmpStr );
      delete [] tmpStr;

      // Get children
      DOMNode* child = content->getFirstChild();

      while ( child != NULL ) {
         switch ( child->getNodeType() ) {
            case DOMNode::ELEMENT_NODE :
               // See if the element is a known type
               if ( XMLString::equals( child->getNodeName(),
                                       "item_ident" ) )
               {
                  
                  // Parse item ident
                  ItemIdentifier* itemIdent = new ItemIdentifier();
                  parseItemIdent( child, *itemIdent );

                  contents.insert( make_pair( mapIdent, itemIdent ) );
                  
               } else if ( XMLString::equals( child->getNodeName(),
                                              "whole_map" ) )
               {
                  
                  // Content is all of the specified map.
                  contents.insert( make_pair( mapIdent, 
                                              (ItemIdentifier*) NULL ) );
               
               } else {
                  mc2log << warn 
                         << "XMLIndata::parseContent:"
                         << " odd Element in content element: " 
                         << child->getNodeName() << endl;
               }
               break;
            case DOMNode::COMMENT_NODE :
               // Ignore comments
               break;
            default:
               mc2log << warn 
                      << "XMLIndata::parseContent odd "
                      << "node type in content element: " 
                      << child->getNodeName() 
                      << " type " << child->getNodeType() << endl;
               break;
         }
         child = child->getNextSibling();
      }
      
      return true; 
      
   } else {
      // Not a content node.
      mc2log << warn 
             << "XMLIndata::parseContent:"
             << " not a content node."
             << content->getNodeName() << endl;
      return false;
   }
}
Exemplo n.º 30
0
bool
XMLIndata::parseName( const DOMNode* name,
                      NameCollection& names ) 
{
   if ( XMLString::equals( name->getNodeName(), "name" ) ) {
      
      // Get attributes
      DOMNamedNodeMap* attributes = name->getAttributes();

      LangTypes::language_t lang;
      ItemTypes::name_t nameType;
      
      // Note that language attribute is #REQUIRED.
      DOMNode* attribute = 
         attributes->getNamedItem( X( "language" ) );
      MC2_ASSERT( attribute != NULL );
      MC2String langStr = 
         XMLUtility::transcodefromucs(attribute->getNodeValue() );
      // Replace any occurance of '_' with space.
      for (MC2String::iterator strIt = langStr.begin();
           strIt != langStr.end(); ++strIt){
         if ( *strIt == '_' ){
            *strIt = ' ';
         }
      }

      lang = LangTypes::getStringAsLanguage( langStr.c_str(), true );
      if ( lang == LangTypes::invalidLanguage ){
         mc2log << error << "Could not interpret language code of string"
                << endl;
         MC2_ASSERT(false);
      }

      // Note that type attribute is always present.
      attribute = 
         attributes->getNamedItem( X( "type" ) );
      MC2_ASSERT( attribute != NULL );
      const char* tmpStr = XMLUtility::transcodefromucs(
            attribute->getNodeValue() );
      nameType = ItemTypes::getStringAsNameType( tmpStr );
      delete [] tmpStr;

      // Get the name.
      tmpStr = XMLUtility::getChildTextValue( name );
      
      // Add name
      Name* tmpName = new Name( tmpStr, lang, nameType );
      names.addName( tmpName );
      mc2dbg << "Added name: " << (*tmpName) << endl;
      mc2dbg8 << "All names: " << names << endl;
      delete tmpStr;

      return true;
   } else {
      // Not a name node.
      mc2log << warn 
             << "XMLIndata::parseName:"
             << " not a name node."
             << name->getNodeName() << endl;
      return false;
   }
}