Example #1
0
xmlstream& operator<<(xmlstream& target, const DOMNode* toWrite)
{
    // Get the name and value out for convenience
    const XMLCh* nodeName = toWrite->getNodeName();
    const XMLCh* nodeValue = toWrite->getNodeValue();


	switch (toWrite->getNodeType())
    {
		case DOMNode::TEXT_NODE:
        {
            outputContent(target, nodeValue);
            break;
        }

        case DOMNode::PROCESSING_INSTRUCTION_NODE :
        {
            target  << XMLStrL("<?")
                    << nodeName
                    << XMLStrL(' ')
                    << nodeValue
                    << XMLStrL("?>");
            break;
        }

        case DOMNode::DOCUMENT_NODE :
        {
            //
            //  Bug here:  we need to find a way to get the encoding name
            //  for the default code page on the system where the program
            //  is running, and plug that in for the encoding name.
            //
            XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* document=(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*)toWrite;
            target << XMLStrL("<?xml version=\"") << document->getVersion() << XMLStrL("\"");
            const XMLCh* str = document->getEncoding();
            if (str != 0)
                target << XMLStrL(" encoding=\"") << str << XMLStrL("\"");
            if(document->getStandalone())
                target << XMLStrL(" standalone=\"yes\"");
            target << XMLStrL("?>");

            DOMNode* child = toWrite->getFirstChild();
            while( child != 0)
            {
                target << child;
                child = child->getNextSibling();
            }
            break;
        }

        case DOMNode::ELEMENT_NODE :
        {
            // Output the element start tag.
            target << XMLStrL('<') << nodeName;

            // Output any attributes on this element
            DOMNamedNodeMap* attributes = toWrite->getAttributes();
            int attrCount = attributes->getLength();
            for (int i = 0; i < attrCount; i++)
            {
                DOMNode*  attribute = attributes->item(i);

                target  << XMLStrL(' ') << attribute->getNodeName()
                        << XMLStrL(" = \"");
                        //  Note that "<" must be escaped in attribute values.
                        outputContent(target, attribute->getNodeValue());
                        target << XMLStrL('"');
            }

            //
            //  Test for the presence of children, which includes both
            //  text content and nested elements.
            //
            DOMNode* child = toWrite->getFirstChild();
            if (child != 0)
            {
                // There are children. Close start-tag, and output children.
                target << XMLStrL(">");
                while( child != 0)
                {
                    target << child;
                    child = child->getNextSibling();
                }

                // Done with children.  Output the end tag.
                target << XMLStrL("</") << nodeName << XMLStrL(">");
            }
            else
            {
                //
                //  There were no children. Output the short form close of
                //  the element start tag, making it an empty-element tag.
                //
                target << XMLStrL("/>");
            }
            break;
        }

        case DOMNode::ENTITY_REFERENCE_NODE:
        {
            DOMNode* child;
            for (child = toWrite->getFirstChild(); child != 0; child = child->getNextSibling())
                target << child;
            break;
        }

        case DOMNode::CDATA_SECTION_NODE:
        {
            target << XMLStrL("<![CDATA[") << nodeValue << XMLStrL("]]>");
            break;
        }

        case DOMNode::COMMENT_NODE:
        {
            target << XMLStrL("<!--") << nodeValue << XMLStrL("-->");
            break;
        }

        case DOMNode::DOCUMENT_TYPE_NODE:
        {
			DOMDocumentType* doctype = (DOMDocumentType*)toWrite;;

			target << XMLStrL("<!DOCTYPE ") << nodeName ;
			const XMLCh* id = doctype->getPublicId();
			if (id != 0)
				target << XMLStrL(" PUBLIC \"") << id << XMLStrL("\"");
			id = doctype->getSystemId();
			if (id != 0)
				target << XMLStrL(" SYSTEM \"") << id << XMLStrL("\"");
			id = doctype->getInternalSubset();
			if (id !=0)
				target << XMLStrL(" [ ") << id  << XMLStrL("]");
			target  << XMLStrL(">");
            break;
        }
		case DOMNode::ENTITY_NODE:
        {
			DOMEntity* entity = (DOMEntity*)toWrite;;

			target << XMLStrL("<!ENTITY ") << nodeName;
			const XMLCh* id = entity->getPublicId();
			if (id != 0)
				target << XMLStrL("PUBLIC \"") << id << XMLStrL("\"");
			id = entity->getSystemId();
			if (id != 0)
				target << XMLStrL("SYSTEM \"") << id << XMLStrL("\"");
			id = entity->getNotationName();
			if (id != 0)
				target << XMLStrL("NDATA \"") << id << XMLStrL("\"");

            break;
        }
        default:
            target << XMLStrL("<!-- Unrecognized node type -->");
    }
	return target;
}
Example #2
0
void DeltaApplyEngine::ApplyOperation(DOMNode *operationNode) {
	 
	vddprintf(("ApplyOperation\n"));
	XMLCh dStr[2];
	XMLCh iStr[2];
	XMLCh uStr[2];
	XMLCh adStr[3];
	XMLCh aiStr[3];
	XMLCh auStr[3];
	XMLCh renameRootStr[11];
	XMLString::transcode("d", dStr, 1);
	XMLString::transcode("i", iStr, 1);
	XMLString::transcode("u", uStr, 1);
	XMLString::transcode("ad", adStr, 2);
	XMLString::transcode("ai", aiStr, 2);
	XMLString::transcode("au", auStr, 2);
	XMLString::transcode("renameRoot", renameRootStr, 10);
	XMLCh tempStr[6];
	if (XMLString::equals(operationNode->getLocalName(), dStr)) {
		vddprintf(("        d(elete)\n"));
		
		bool move = false ;
		XMLString::transcode("move", tempStr, 5);
		DOMNode* moveAttr = operationNode->getAttributes()->getNamedItem(tempStr) ;
		XMLString::transcode("yes", tempStr, 5);
		if ((moveAttr!=NULL) && (XMLString::equals(moveAttr->getNodeValue(),tempStr))) {
			move = true;
		}

		XMLString::transcode("xm", tempStr, 5);
		char *xidmapStr = XMLString::transcode(operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue());		
		if (move) {
			XidMap_Parser parse(xidmapStr) ;
			XID_t myXid = parse.getRootXID();
			Subtree_MoveFrom( myXid );
		  }
		else {
			Subtree_Delete(xidmapStr) ;
		}
		XMLString::release(&xidmapStr);
	}

	else if (XMLString::equals(operationNode->getLocalName(),iStr)) {
		vddprintf(("        i(nsert)\n"));

		bool move = false ;
		XMLString::transcode("move", tempStr, 5);
		DOMNode* moveAttr = operationNode->getAttributes()->getNamedItem(tempStr) ;
		XMLString::transcode("yes", tempStr, 5);
		if ( (moveAttr!=NULL) && (XMLString::equals( moveAttr->getNodeValue(), tempStr ))) {
			move = true;
		}
		XMLString::transcode("pos", tempStr, 5);
		DOMNode *n = operationNode->getAttributes()->getNamedItem(tempStr);
		int position = XyInt(n->getNodeValue());

		XMLString::transcode("par", tempStr, 5);
		n = operationNode->getAttributes()->getNamedItem(tempStr);
		XID_t parentXID = (XID_t)(int)XyInt(n->getNodeValue());

		XMLString::transcode("xm", tempStr, 5);
		char *xidmapStr = XMLString::transcode(operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue());
		if (move) {
			XidMap_Parser parse(xidmapStr) ;
			XID_t myXid = parse.getRootXID();

			Subtree_MoveTo( myXid, parentXID, position );
		}
		else {
			DOMNode* insertRoot ;
			// get data to insert
			if (operationNode->hasChildNodes()) insertRoot = operationNode->getFirstChild() ;
			else THROW_AWAY(("insert operator element contains no data"));
				
			Subtree_Insert( insertRoot, parentXID, position, xidmapStr ) ;
		}
		XMLString::release(&xidmapStr);
	}

	else if (XMLString::equals(operationNode->getLocalName(), uStr)) {
		vddprintf(("        u(pdate)\n"));
		XMLString::transcode("oldxm", tempStr, 5);
		char *xidmapStr = XMLString::transcode(operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue());
		XidMap_Parser parse(xidmapStr) ;
		XID_t nodeXID = parse.getRootXID();
		TextNode_Update( nodeXID, operationNode);
		XMLString::release(&xidmapStr);
		}

	else if (XMLString::equals(operationNode->getLocalName(), adStr)) {
		vddprintf(("        a(ttribute) d(elete)\n"));
		XMLString::transcode("xid", tempStr, 5);
		XID_t nodeXID = (XID_t)(int)XyInt(operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue());

		XMLString::transcode("a", tempStr, 5);
        const XMLCh* attr = operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue() ;
		Attribute_Delete( nodeXID, attr );
		}
	else if (XMLString::equals(operationNode->getLocalName(), aiStr)) {
		vddprintf(("        a(ttribute) i(nsert)\n"));
		XMLString::transcode("xid", tempStr, 5);
		XID_t nodeXID = (XID_t)(int)XyInt(operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue());
		XMLString::transcode("a", tempStr, 5);
        const XMLCh* attr = operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue() ;
		XMLString::transcode("v", tempStr, 5);
        const XMLCh* value = operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue() ;
		Attribute_Insert( nodeXID, attr, value );
		}
	else if (XMLString::equals(operationNode->getLocalName(), auStr)) {
		vddprintf(("        a(ttribute) u(pdate)\n"));
		XMLString::transcode("xid", tempStr, 5);
		XID_t nodeXID = (XID_t)(int)XyInt(operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue());
		XMLString::transcode("a", tempStr, 5);
        const XMLCh* attr = operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue() ;
		XMLString::transcode("nv", tempStr, 5);
        const XMLCh* value = operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue() ;
		Attribute_Update( nodeXID, attr, value );
		}
	else if (XMLString::equals(operationNode->getLocalName(), renameRootStr)) {
		vddprintf(("        renameRoot\n"));
		DOMNode *root = xiddoc->getDocumentElement();
		XID_t rootXID = xiddoc->getXidMap().getXIDbyNode(root);
		XMLString::transcode("to", tempStr, 5);
        const XMLCh* newrootName = operationNode->getAttributes()->getNamedItem(tempStr)->getNodeValue() ;
		DOMElement* newroot = xiddoc->createElement(newrootName);

		DOMNode* child = root->getFirstChild();
		while(child!=NULL) {
			root->removeChild(child);
			newroot->appendChild(child);
			child = root->getFirstChild();
		}
		DOMNamedNodeMap *attributes = root->getAttributes();
		for(unsigned int i=0;i<attributes->getLength();i++) {
			DOMNode *an = attributes->item(i);
			newroot->setAttribute(an->getNodeName(), an->getNodeValue());
		}
		xiddoc->removeChild(root);
		xiddoc->getXidMap().removeNode(root);
		root->release();
		xiddoc->appendChild(newroot);
		xiddoc->getXidMap().registerNode(newroot, rootXID);
		xiddoc->getXidMap().SetRootElement(newroot);
		}
	}
Example #3
0
void XSECNameSpaceExpander::recurse(DOMElement *n) {

	// Recursively go down the tree adding namespaces

	DOMNode *p = n->getParentNode();
	if (p->getNodeType() != DOMNode::ELEMENT_NODE)
		return;

	DOMNamedNodeMap *pmap = p->getAttributes();
	XMLSize_t psize = pmap->getLength();

	DOMNamedNodeMap *nmap = n->getAttributes();

	safeBuffer pname, pURI, nURI;
	DOMNode *finder;

	XSECNameSpaceEntry * tmpEnt;

	for (XMLSize_t i = 0; i < psize; i++) {

		// Run through each parent node to find namespaces
		pname << (*mp_formatter << pmap->item(i)->getNodeName());

		// See if this is an xmlns node
		
		if (pname.sbStrncmp("xmlns", 5) == 0) {

			// It is - see if it already exists
			finder = nmap->getNamedItem(pname.sbStrToXMLCh());
			if (finder == 0) {

				// Need to add
				n->setAttributeNS(DSIGConstants::s_unicodeStrURIXMLNS, 
					pmap->item(i)->getNodeName(),
					pmap->item(i)->getNodeValue());

				// Add it to the list so it can be removed later
				XSECnew(tmpEnt, XSECNameSpaceEntry);
				tmpEnt->m_name.sbStrcpyIn(pname);
				tmpEnt->mp_node = n;
				tmpEnt->mp_att = nmap->getNamedItem(pname.sbStrToXMLCh());
				m_lst.push_back(tmpEnt);

			}

		}

	}

	// Do the children

	DOMNode *c;

	c = n->getFirstChild();

	while (c != NULL) {
		if (c->getNodeType() == DOMNode::ELEMENT_NODE)
			recurse((DOMElement *) c);
		c = c->getNextSibling();
	}

}
Example #4
0
void TXFMXPathFilter::walkDocument(DOMNode * n) {

	// Non-recursive version

	DOMNode * current = n;
	DOMNode * next;
	DOMNode * attParent = NULL; 	/* Assign NULL to remove spurious Forte warning */
	bool done = false;
	bool treeUp = false;
	DOMNamedNodeMap * atts = n->getAttributes();
	int attsSize = -1;
	int currentAtt = -1;
	lstsVectorType::iterator lstsIter;

	while (done == false && current != NULL) {

		if (treeUp == true) {

			if (current == n) {

				// We are complete.
				done = true;

			}

			else {

				// Remove this node from the ancestor lists
				for (lstsIter = m_lsts.begin(); lstsIter != m_lsts.end(); ++lstsIter) {

					if ((*lstsIter)->ancestorInScope == current) {
						(*lstsIter)->ancestorInScope = NULL;
					}
				}


				// Check for another sibling
				next = current->getNextSibling();

				if (next == NULL) {

					current = current->getParentNode();
					treeUp = true;
				}

				else {

					current = next;
					treeUp = false;

				}

			}

		} /* treeUp == true */

		else {

			// Check if the current node is in the result set.  The walk the children

			// First check if this node is in any lists, and if so,
			// set the appropriate ancestor nodes (if necessary)

			for (lstsIter = m_lsts.begin(); lstsIter != m_lsts.end(); ++lstsIter) {

				if ((*lstsIter)->ancestorInScope == NULL &&
					(*lstsIter)->lst->hasNode(current)) {

					(*lstsIter)->ancestorInScope = current;

				}

				// 
			}

			// Now that the ancestor setup is done, check to see if this node is 
			// in scope.

			if (checkNodeInScope(current) && 
				checkNodeInInput(current, (atts != NULL ? attParent : NULL))) {

				m_xpathFilterMap.addNode(current);

			}

			// Now find the next node!

			if (atts != NULL) {

				// Working on an attribute list
				currentAtt++;

				if (currentAtt == attsSize) {

					// Attribute list complete
					atts = NULL;
					current = attParent;
					next = current->getFirstChild();
					if (next == NULL)
						treeUp = true;
					else {
						current = next;
						treeUp = false;
					}

				}

				else {

					current = atts->item(currentAtt);

				}

			}

			else {
				// Working on an element or other non-attribute node
				atts = current->getAttributes();

				if (atts != NULL && ((attsSize = atts->getLength()) > 0)) {

					currentAtt = 0;
					attParent = current;
					current = atts->item(0);
					treeUp = false;

				}

				else {

					atts = NULL;

					next = current->getFirstChild();

					if (next != NULL) {
						current = next;
						treeUp = false;
					}

					else {

						treeUp = true;

					}

				}
			} /* ! atts == NULL */
		}
	} /* while */
}
Example #5
0
void TXFMXPathFilter::walkDocument(DOMNode * n) {

	// Check if the current node is in the result set.  The walk the children
	lstsVectorType::iterator lstsIter;

	// First check if this node is in any lists, and if so,
	// set the appropriate ancestor nodes (if necessary)

	for (lstsIter = m_lsts.begin(); lstsIter != m_lsts.end(); ++lstsIter) {

		if ((*lstsIter)->ancestorInScope == NULL &&
			(*lstsIter)->lst->hasNode(n)) {

			(*lstsIter)->ancestorInScope = n;

		}
	}

	// Now that the ancestor setup is done, check to see if this node is 
	// in scope.

	if (checkNodeInScope(n) && checkNodeInInput(n)) {

		m_xpathFilterMap.addNode(n);

	}

	// Do any attributes

	DOMNamedNodeMap * atts = n->getAttributes();
	
	if (atts != NULL) {

		unsigned int s = atts->getLength();
		for (unsigned int i = 0; i < s; ++i) {

			walkDocument(atts->item(i));

		}

	}

	// Do any childeren

	DOMNode * c = n->getFirstChild();

	while (c != NULL) {

		walkDocument(c);
		c = c->getNextSibling();

	}

	// Now remove from ancestor lists if we are that ancestor
	for (lstsIter = m_lsts.begin(); lstsIter != m_lsts.end(); ++lstsIter) {

		if ((*lstsIter)->ancestorInScope == n) {
			(*lstsIter)->ancestorInScope = NULL;
		}
	}

}
/* NOTE: need to keep _type field in consideration as attribute type/entitlement depends on it.*/
EppMarkHolder* EppMarkHolder::fromXML( const DOMNode& root, const char* ns )
{
	/*
	  this->_name = _src._name;
	  this->_org = _src._org;
	  this->_addr = _src._addr;
	  this->_voice = _src._voice;
	  this->_fax = _src._fax;
	  this->_email = _src._email;
	  this->_addParam = _src._addParam;
	  this->_type = _src._type;

	 */
	EppMarkHolder *_ret = new EppMarkHolder(EPPMARK_HOLDER, ns);
	//_ret->setNameSpace(ns);
	int nsLen = strlen(ns);

	if( null == _ret )
		return null;
	DOMNodeList* list  = root.getChildNodes();
	DOMNamedNodeMap* attrs = root.getAttributes();

	for( unsigned int i = 0; i < list->getLength(); i++ )
	{
		DOMNode* node = list->item(i);
		DOMString name = node->getLocalName();
		if( name.isNull() )
		{
			name = node->getNodeName();
		}
		if( name.isNull() )
			continue;
		if( name.substringData(0, nsLen + 1).equals((_ret->getNameSpace() + ":").c_str()) )
		{
			name = name.substringData(nsLen + 1, name.length() - ( nsLen + 1 ));
			if( name.equals("name") )
			{
				_ret->_name = EppUtil::getText(*node);
			}
			else if ( name.equals("org") )
			{
				_ret->_org = EppUtil::getText(*node);
			}
			else if ( name.equals("addr") )
			{
				EppMarkAddress* mAddr = (EppMarkAddress*)EppMarkAddress::fromXML( *node, ns );
				_ret->_addr = *mAddr;
				delete mAddr;
			}
			else if ( name.equals("voice") )
			{
				EppE164 *_v = EppE164::fromXML(*node);
				if( NULL != _v )
				{
					_ret->_voice = *_v;
					delete _v;
				}
			}
			else if ( name.equals("fax") )
			{
				EppE164 *_f = EppE164::fromXML(*node);
				if( NULL != _f )
				{
					_ret->_fax = *_f;
					delete _f;
				}
			}
			else if ( name.equals("email") )
			{
				_ret->_email = EppUtil::getText(*node);
			}
		}
	}

	for( unsigned int i = 0; i < attrs->getLength();i++ )
	{
		DOMNode* attr = attrs->item(i);
		DOMString _v = attr->getNodeValue();
		if( XS(attr->getNodeName()).equals("entitlement") )
		{
			_ret->_type = EPPMARK_HOLDER;
			if( _v.length() > 0 )
			{
				_ret->_addParam = _v;
			}
			break;
		}
		else if ( XS(attr->getNodeName()).equals("type") )
		{
			_ret->_type = EPPMARK_CONTACT;
			if( _v.length() > 0 )
			{
				_ret->_addParam = _v;
			}
			break;
		}
	}
	return _ret;
}
Example #7
0
// ---------------------------------------------------------------------------
//  GeneralAttributeCheck: Validation methods
// ---------------------------------------------------------------------------
void
GeneralAttributeCheck::checkAttributes(const DOMElement* const elem,
                                       const unsigned short elemContext,
                                       TraverseSchema* const schema,
                                       const bool isTopLevel,
                                       ValueVectorOf<DOMNode*>* const nonXSAttList)
{
    if (nonXSAttList)
        nonXSAttList->removeAllElements();

    if (elem == 0 || !fAttMap || elemContext>=E_Count)
        return;

    const XMLCh* elemName = elem->getLocalName();
    if (!XMLString::equals(SchemaSymbols::fgURI_SCHEMAFORSCHEMA, elem->getNamespaceURI())) {
        schema->reportSchemaError
        (
            elem
            , XMLUni::fgXMLErrDomain
            , XMLErrs::ELTSchemaNS
            , elemName
        );
    }

    const XMLCh*     contextStr = (isTopLevel) ? fgGlobal : fgLocal;
    DOMNamedNodeMap* eltAttrs = elem->getAttributes();
    int              attrCount = eltAttrs->getLength();
    XMLByte          attList[A_Count];

    memset(attList, 0, sizeof(attList));

    for (int i = 0; i < attrCount; i++) {

        DOMNode*     attribute = eltAttrs->item(i);
        const XMLCh* attName = attribute->getNodeName();

        // skip namespace declarations
        if (XMLString::equals(attName, XMLUni::fgXMLNSString)
            || XMLString::startsWith(attName, XMLUni::fgXMLNSColonString))
            continue;

        // Bypass attributes that start with xml
        // add this to the list of "non-schema" attributes
        if ((*attName == chLatin_X || *attName == chLatin_x)
           && (*(attName+1) == chLatin_M || *(attName+1) == chLatin_m)
           && (*(attName+2) == chLatin_L || *(attName+2) == chLatin_l)) {

           if (nonXSAttList)
                nonXSAttList->addElement(attribute);

            continue;
        }

        // for attributes with namespace prefix
        const XMLCh* attrURI = attribute->getNamespaceURI();

        if (attrURI != 0 && *attrURI) {

            // attributes with schema namespace are not allowed
            // and not allowed on "documentation" and "appInfo"
            if (XMLString::equals(attrURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) ||
                XMLString::equals(elemName, SchemaSymbols::fgELT_APPINFO) ||
                XMLString::equals(elemName, SchemaSymbols::fgELT_DOCUMENTATION)) {

                schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
                    XMLErrs::AttributeDisallowed, attName, contextStr, elemName);
            }
            else if (nonXSAttList)
            {
                nonXSAttList->addElement(attribute);
            }

            continue;
        }

        int attNameId = A_Invalid;
        attName = attribute->getLocalName();

        bool bContinue=false;   // workaround for Borland bug with 'continue' in 'catch'
        try {
            attNameId= fAttMap->get(attName, fMemoryManager);
        }
        catch(const OutOfMemoryException&)
        {
            throw;
        }
        catch(...) {

            schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
                XMLErrs::AttributeDisallowed, attName, contextStr, elemName);
            bContinue=true;
        }
        if(bContinue)
            continue;

        if (fgElemAttTable[elemContext][attNameId] & Att_Mask) {

            attList[attNameId] = 1;
            validate
            (
                elem
                , attName
                , attribute->getNodeValue()
                , fgElemAttTable[elemContext][attNameId] & DV_Mask
                , schema
            );
        }
        else {
            schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
                XMLErrs::AttributeDisallowed, attName, contextStr, elemName);
        }
    }

    // ------------------------------------------------------------------
    // Check for required attributes
    // ------------------------------------------------------------------
    for (unsigned int j=0; j < A_Count; j++) {

        if ((fgElemAttTable[elemContext][j] & Att_Required) && attList[j] == 0) {
            schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeRequired,
                                      fAttNames[j], contextStr, elemName);
        }
    }
}
Example #8
0
void *IndexedLineSet::read(DOMNode *node) {

	#ifdef DEBUG1
		cout << "Reading IndexedLineSet" << endl;
	#endif
	
	unsigned int i; 				// variable to counter
	DOMNamedNodeMap *attributes;	// variable to hold the node attributes
	DOMNodeList *children;			// variable to hold the node children
	char *ctemp;					// temporary variable

	
	#ifndef XERCES  // actualy is the xerces parser 
		char *ptrptr;
	#endif
	
	char* message;
	
	attributes = node->getAttributes();
	for (i = 0; i < attributes->getLength(); i++) {		
		if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "DEF")) {
			strcpy(this->DEF,XMLString::transcode (attributes->item(i)->getNodeValue()));
			setLink(XMLString::transcode(attributes->item(i)->getNodeValue()),this);
		} else
		if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) {
			return(getLink(XMLString::transcode(attributes->item(i)->getNodeValue())));
		} else
		if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()),"colorPerVertex")) {
			if (!strcasecmp(XMLString::transcode(attributes->item(i)->getNodeValue()),"TRUE")) {
				*this->colorPerVertex=true;
			} else {
				*this->colorPerVertex=false;
			}
		} else
		if ( !strcmp(XMLString::transcode (attributes->item(i)->getNodeName()) , "coordIndex")) {
			message = XMLString::transcode(attributes->item(i)->getNodeValue());
			ctemp = strtok(message,", \n");
			while (ctemp != NULL) {
				coordIndex[f++] = atoi(ctemp);
				ctemp = strtok(NULL,", \n");
				if(this->f>=Minimum_MFVec3f) { // corigir
					cerr << "Error IndexedLineSet bigger than buffer" << endl;
					return(NULL);;
				}				
			}
			if(coordIndex[f-1]!=-1) {
				coordIndex[f++]=-1;
			}
		} else
		if ( !strcmp(XMLString::transcode (attributes->item(i)->getNodeName()) , "colorIndex")) {

			#ifdef XERCES  // actualy is the xerces parser 
				
				XMLStringTokenizer *tok = new XMLStringTokenizer( attributes->item(i)->getNodeValue() , XMLString::transcode(", \t\n\r\f") );
			
				while(tok->hasMoreTokens()) {
					x3d::x3DValues->MFInt32[this->counterColor++] = atoi(XMLString::transcode(tok->nextToken()));
				
					if(x3d::x3DValues->MFInt32[this->counterColor] < -1) {
						cout << "Warning value of CoordIndex outside the range" << endl;
					}
					if(this->counterColor>=Minimum_MFInt32) {
						cerr << "Error coordIndex bigger than buffer" << endl;
						return(NULL);;
					}
			
				}	
			
				delete tok;
				
			
			#else
			
				if(XMLString::stringLen(attributes->item(i)->getNodeValue()) >= Size_X3D_Message) {
					cout << " Message exced the maximun size " << endl;
				}
				if(!XMLString::transcode(attributes->item(i)->getNodeValue(),x3d::message,Size_X3D_Message)) {
					cout << " Message exced the maximun size " << endl;
				}
				ctemp = strtok_r(x3d::message,", \n",&ptrptr);
				while (ctemp != NULL) {
					x3d::x3DValues->MFInt32[this->counterColor++] = atoi(ctemp);
					if(x3d::x3DValues->MFInt32[this->counterColor] < -1) {
						cout << "Warning value of ColorIndex outside the range" << endl;
					}
					ctemp = strtok_r(NULL,", \n",&ptrptr);
					if(this->counterColor>=Minimum_MFInt32) {
						cerr << "Error colorIndex bigger than buffer" << endl;
						return(NULL);;
					}
				}

			#endif


			if(x3d::x3DValues->MFInt32[this->counterColor-1]!=-1) {
				x3d::x3DValues->MFInt32[this->counterColor++]=-1;
			}
			this->colorIndex = new int[this->counterColor];
			//this->set_colorIndex = this->colorIndex;				// just a copy
			if( colorIndex==NULL ) 
				cerr << "Memory alocation problem at indexedFaceSet" << endl;
			for(int indexCounter=0;indexCounter < this->counterColor;indexCounter++) {
				colorIndex[indexCounter] = x3d::x3DValues->MFInt32[indexCounter];
			}
	
		}
	}

	#ifdef DEBUG1
		cout << "Reading children" << endl;
	#endif
	
	children = node->getChildNodes ();
	if (children != NULL) {
		for (i = 0; i < children->getLength (); i++) {			
			if (!strcmp (XMLString::transcode(children->item(i)->getNodeName()),"Coordinate")) {
				coordinate = Coordinate::get(children->item(i));
			} else
			if (!strcmp (XMLString::transcode(children->item(i)->getNodeName()),"Color")) {
				color = Color::get(children->item(i));
			}
		}
	}
	
	#ifdef DEBUG1
		cout << "Leaving Reding IndexedLineSet" << endl;
	#endif
	return(NULL);
	
}
Example #9
0
void *Color::read(DOMNode *node) {

	unsigned int i; 		// variable to counter
	DOMNamedNodeMap *attributes;	// variable to hold the node attributes
	
	#ifndef XERCES
		char *ctemp;			// temporary variable	
		char *ptrptr;
	#endif
	
	attributes = node->getAttributes();
	for (i = 0; i < attributes->getLength(); i++) {
		if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "DEF")) {
			setLink(XMLString::transcode(attributes->item(i)->getNodeValue()),this);
		} else
		if (!strcmp(XMLString::transcode(attributes->item(i)->getNodeName()) , "USE")) {
			return(getLink(XMLString::transcode(attributes->item(i)->getNodeValue())));
		} else
		if ( !strcmp(XMLString::transcode(attributes->item(i)->getNodeName()), "color")) {

			#ifdef XERCES  // actualy is the xerces parser 
			
				XMLStringTokenizer *tok = new XMLStringTokenizer( attributes->item(i)->getNodeValue() , XMLString::transcode(", \t\n\r\f") );
			
				while(tok->hasMoreTokens()) {
					x3d::x3DValues->MFColor[this->numberOfElements++] = atof(XMLString::transcode(tok->nextToken()));
					#ifdef DEGUB
						cout << "Coordinate [ " << this->numberOfElements-1 << " :" << x3d::x3DValues->MFVec3f[this->numberOfElements-1] << endl;
					#endif
					if(this->numberOfElements>=Minimum_MFVec3f) {
						cerr << "Error Coordinates bigger than buffer" << endl;
						return(NULL);
					}	
				}	
			
				delete tok;
				
			#else

				if(XMLString::stringLen(attributes->item(i)->getNodeValue()) >= Size_X3D_Message) {
					cout << " Message exced the maximun size " << endl;
				}
				if(!XMLString::transcode(attributes->item(i)->getNodeValue(),x3d::message,Size_X3D_Message)) {
					cout << " Message exced the maximun size " << endl;
				}
				ctemp = strtok_r(x3d::message,", \n",&ptrptr);
				while (ctemp != NULL) {
					x3d::x3DValues->MFColor[this->numberOfElements++] = atof(ctemp);
					ctemp = strtok_r(NULL,", \n",&ptrptr);
					#ifdef DEGUB
						cout << "Coordinate [ " << f-1 << " :" << x3d::x3DValues->MFColor[f-1] << endl;
					#endif
					if(this->numberOfElements>=Minimum_MFColor) {
						cerr << "Error Colors bigger than buffer" << endl;
						return(NULL);;
					}
				}

			#endif
		
		}
	}

	this->value->aloc(numberOfElements);
	
	unsigned int g;							// counter
	
	for(g=0;g<numberOfElements;g++){
		value->data[g]=x3d::x3DValues->MFColor[g];
	}
	
	return(NULL);

}
bool
XMLParserThread::xmlParseSMSFormatRequest( DOMNode* cur, 
                                           DOMNode* out,
                                           DOMDocument* reply,
                                           bool indent )
try {
   bool ok = true;
   int indentLevel = 1;

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

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

   XMLSMSCommon::InviteData inviteData; // for invite_sms

   XMLSMSCommon::PlaceSMSData placeData; // for place_sms

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

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

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

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

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

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

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

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

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

      smsVector->deleteAllObjs();
      delete smsVector;

   } // Not ok handled below

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

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

   return ok;
} catch ( const XMLTool::Exception& e ) {
   
   return false;
}
void
DomUtilsInternal::Dom2XMLString( 
            const DOMNode* toWrite, 
            XMLFormatter& fmt )
{
    int i;
    DOMNode child;
    int attrCount;
    DOMString id;
    DOMNamedNodeMap attributes;
    DOMDocumentType doctype;


    // Get the name and value out for convenience
    DOMString   nodeName = toWrite.getNodeName();
    DOMString   nodeValue = toWrite.getNodeValue();
    unsigned long lent = nodeValue.length();

    switch (toWrite.getNodeType())
    {
        case DOMNode::ELEMENT_NODE:
            // The name has to be representable without any escapes
            fmt  << XMLFormatter::NoEscapes << chOpenAngle << nodeName;

            // Output the element start tag.

            // Output any attributes on this element
            attributes = ((DOMElement&)toWrite).getAttributes();
            attrCount = attributes.getLength();
            for (i = 0; i < attrCount; i++)
            {
                DOMNode  attribute = attributes.item(i);

                //
                //  Again the name has to be completely representable. But the
                //  attribute can have refs and requires the attribute style
                //  escaping.
                //
                fmt  << XMLFormatter::NoEscapes
                             << chSpace << attribute.getNodeName() 
                             << chEqual << chDoubleQuote
                             << XMLFormatter::AttrEscapes
                             << attribute.getNodeValue() 
                             << XMLFormatter::NoEscapes
                             << chDoubleQuote;
            }

            //
            //  Test for the presence of children, which includes both
            //  text content and nested elements.
            //
            child = toWrite.getFirstChild();
            if ( !child.isNull() )
            {
                // There are children. Close start-tag, and output children.
                // No escapes are legal here
                fmt << XMLFormatter::NoEscapes << chCloseAngle;

                while( !child.isNull() )
                {
                    DomUtilsInternal::Dom2XMLString( child, fmt );
                    child = child.getNextSibling();
                }

                //
                // Done with children.  Output the end tag.
                //
                fmt << XMLFormatter::NoEscapes << gEndElement
                            << nodeName << chCloseAngle;
            }
            else
            {
                //
                //  There were no children. Output the short form close of
                //  the element start tag, making it an empty-element tag.
                //
                fmt << XMLFormatter::NoEscapes << chForwardSlash << chCloseAngle;
            }
            break;

        case DOMNode::TEXT_NODE:
            fmt.formatBuf( nodeValue.rawBuffer(),  lent, XMLFormatter::CharEscapes );
            break;


        case DOMNode::CDATA_SECTION_NODE :
            fmt << XMLFormatter::NoEscapes << gStartCDATA
                        << nodeValue << gEndCDATA;
            break;

        case DOMNode::ENTITY_REFERENCE_NODE:
            fmt << XMLFormatter::NoEscapes << chAmpersand
                << nodeName << chSemiColon;
            break;

        case DOMNode::PROCESSING_INSTRUCTION_NODE :
            fmt << XMLFormatter::NoEscapes << gStartPI << nodeName;
            if (lent > 0)
            {
                fmt << chSpace << nodeValue;
            }
            fmt << XMLFormatter::NoEscapes << gEndPI;
            break;

        case DOMNode::COMMENT_NODE :
            fmt << XMLFormatter::NoEscapes << gStartComment
                        << nodeValue << gEndComment;
            break;

        case DOMNode::DOCUMENT_NODE :
            child = toWrite.getFirstChild();
            while( !child.isNull() )
            {
                DomUtilsInternal::Dom2XMLString( child, fmt );
                child = child.getNextSibling();
                if ( !child.isNull() )
                {
                    fmt << chCR;
                }
            }
            break;

        case DOMNode::DOCUMENT_TYPE_NODE :
            doctype = (DOMDocumentType &)toWrite;

            fmt << XMLFormatter::NoEscapes  << gStartDoctype
                        << nodeName;

            id = doctype.getPublicId();
            if (id != 0)
            {
                fmt << XMLFormatter::NoEscapes << chSpace << gPublic
                    << id << chDoubleQuote;
                id = doctype.getSystemId();
                if (id != 0)
                {
                    fmt << XMLFormatter::NoEscapes << chSpace 
                       << chDoubleQuote << id << chDoubleQuote;
                }
            }
            else
            {
                id = doctype.getSystemId();
                if (id != 0)
                {
                    fmt << XMLFormatter::NoEscapes << chSpace << gSystem
                        << id << chDoubleQuote;
                }
            }

            id = doctype.getInternalSubset(); 
            if (id !=0)
                fmt << XMLFormatter::NoEscapes << chOpenSquare
                            << id << chCloseSquare;

            fmt << XMLFormatter::NoEscapes << chCloseAngle;
            break;


        case DOMNode::ENTITY_NODE:
            fmt << XMLFormatter::NoEscapes << gStartEntity
                        << nodeName;

            id = ((DOMEntity &)toWrite).getPublicId();
            if (id != 0)
                fmt << XMLFormatter::NoEscapes << gPublic
                            << id << chDoubleQuote;

            id = ((DOMEntity &)toWrite).getSystemId();
            if (id != 0)
                fmt << XMLFormatter::NoEscapes << gSystem
                            << id << chDoubleQuote;

            id = ((DOMEntity &)toWrite).getNotationName();
            if (id != 0)
                fmt << XMLFormatter::NoEscapes << gNotation
                            << id << chDoubleQuote;

            fmt << XMLFormatter::NoEscapes << chCloseAngle << chCR << chLF;
            break;

        case DOMNode::XML_DECL_NODE:
            fmt << gXMLDecl1 << ((DOMXMLDecl &)toWrite).getVersion();

            fmt << gXMLDecl2 << fmt.getEncodingName();
            
            id = ((DOMXMLDecl &)toWrite).getStandalone();
            if ( id!= 0 )
                fmt << gXMLDecl3 << id;
            
            fmt << gXMLDecl4;
            break;
    }
}
Example #12
0
void GeomAttributesBuilder::getParameters()
{
	// First set default parameters.
	// The parameters are dependent on the type of geom
	//	box:			length, width, height (all doubles)
	//	ccylinder:	radius, length (all doubles)
	//	sphere:		radius (all doubles)
	//	plane:		normal_x, normal_y, normal_z, d (all doubles)
	//	mesh:		filname (std::string)	
	std::string type = attrib_->getValAsStr("type");
	
	if (!type.compare("box")) {
		attrib_->add("length", "1");
		attrib_->add("width", "1");
		attrib_->add("height", "1");
	} else if (!type.compare("ccylinder")) {
		attrib_->add("radius", "1");
		attrib_->add("length", "3");
	} else if (!type.compare("cylinder")) {
		attrib_->add("radius", "1");
		attrib_->add("length", "3");
	} else if (!type.compare("sphere")) {
		attrib_->add("radius", "1");
	} else if (!type.compare("plane")) {
		attrib_->add("normal_x", "0");
		attrib_->add("normal_y", "0");
		attrib_->add("normal_z", "1");
		attrib_->add("d", "0");
	} else if (!type.compare("mesh")) {
		attrib_->add("filename", "_NODATA_");
	} else {
		return;
	}
	
	DOMNodeList* allChildNodes = node_->getChildNodes();

	// Loop over all of the parameters
	for (unsigned int c = 0; c < allChildNodes->getLength(); ++c) {
		DOMNode* thisChildItem = allChildNodes->item(c);
			    			
		if (thisChildItem->getNodeType() == DOMNode::ELEMENT_NODE) {
		
			char* pChildTagName = XMLString::transcode(thisChildItem->getNodeName());
			
			if ( strcmp(pChildTagName, "parameter") == 0 ) {
     			
				if ( thisChildItem->hasAttributes() ) 
				{
					DOMNamedNodeMap* theAttributes = thisChildItem->getAttributes();
					int numAttributes = theAttributes->getLength();
			
					if (numAttributes == 2) { // Parameters can only 1 Name/Value pair
						DOMNode* nodeName = theAttributes->item(0);
						DOMNode* nodeValue = theAttributes->item(1);

						const XMLCh* xmlch_Name = nodeName->getNodeValue();
						char* attrName = XMLString::transcode(xmlch_Name);

						const XMLCh* xmlch_Value = nodeValue->getNodeValue();
						char* attrValue = XMLString::transcode(xmlch_Value);
						
						try {
							attrib_->update(attrName, attrValue);
						} catch (std::runtime_error &ex) {
							std::cerr << ex.what() << std::endl
									<< builderType_ << "::getParameters() - "
									<< "In geom \"" << attrib_->getValAsStr("name")
									<< "\", parameter \"" << attrName << "=" << attrValue
									<< "\" is illegal for this geom type ("
									<< attrib_->getValAsStr("type")
									<< "). Ignoring it." << std::endl;
						};
						
						XMLString::release( &attrName );
						XMLString::release( &attrValue );		
					}
				}
			}
			
			delete [] pChildTagName;
		}
	}
}
Example #13
0
void SpaceAttributesBuilder::getParameters()
{
	// First set default parameters.
	// The parameters are dependent on the type of space
	//	simple:	No parameters
	//	hash:	center,	dVector3
	//			extents,	dVector3
	//			depth,	int
	//	quatree:	minlevel,	int
	//			maxlevel,	int
	std::string type = attrib_->getValAsStr("type");
	
	if (!type.compare("simple")) return; // No parameters for simple space
	else if (!type.compare("hash")) {
		attrib_->add("center", "0 0 0");
		attrib_->add("extents", "0 0 0");
		attrib_->add("depth", "4");
	} else if (!type.compare("quadtree")) {
		attrib_->add("minlevel", "-1");
		attrib_->add("maxlevel", "8");
	} else {
		return;
	}
	
	DOMNodeList* allChildNodes = node_->getChildNodes();

	// Loop over all of the spaces
	for (unsigned int c = 0; c < allChildNodes->getLength(); ++c) {
		DOMNode* thisChildItem = allChildNodes->item(c);
			    			
		if (thisChildItem->getNodeType() == DOMNode::ELEMENT_NODE) {
		
			char* pChildTagName = XMLString::transcode(thisChildItem->getNodeName());
			
			if ( strcmp(pChildTagName, "parameter") == 0 ) {
     			
				if ( thisChildItem->hasAttributes() ) {
					DOMNamedNodeMap* theAttributes = thisChildItem->getAttributes();
					int numAttributes = theAttributes->getLength();
			
					if (numAttributes == 2) {
						DOMNode* nodeName = theAttributes->item(0);
						DOMNode* nodeValue = theAttributes->item(1);

						const XMLCh* xmlch_Name = nodeName->getNodeValue();
						char* attrName = XMLString::transcode(xmlch_Name);

						const XMLCh* xmlch_Value = nodeValue->getNodeValue();
						char* attrValue = XMLString::transcode(xmlch_Value);

						
						try {
							attrib_->update(attrName, attrValue);
						} catch (std::runtime_error &ex) {
							std::cerr << ex.what() << std::endl
									<< builderType_ << "::getParameters() - "
									<< "In space \"" << attrib_->getValAsStr("name")
									<< "\", parameter \"" << attrName << "=" << attrValue
									<< "\" is illegal for this space type ("
									<< attrib_->getValAsStr("type")
									<< "). Ignoring it." << std::endl;
						}

						XMLString::release( &attrName );
						XMLString::release( &attrValue );
					}
				}
			}
			
			delete [] pChildTagName;
		}
	}
}
Example #14
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* typeTmp = XMLString::transcode(influenceAttr->getNamedItem(XercesString("type"))->getNodeValue());
			std::string type;
			type.assign(typeTmp);
			XMLString::release(&typeTmp);
			
			IInfluenceCalculator* pInfluence = InfluenceCalculatorMaker::newInfluenceCalculator(type, w, fap);
			if(pInfluence)
				pItem->addInfluenceCalculator(pInfluence);
		}
	}

	m_pFDP->insertItem(pItem);
}
Example #15
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")
		{
			char *fileTmp, *formatTmp, *pathTmp;
			XEngine::MeshInfo info;
			attrList = current->getAttributes();
			attr = attrList->getNamedItem(XercesString("file"));
			if(attr)
			{
				fileTmp = XMLString::transcode(attr->getNodeValue());
				info.file.assign(fileTmp);
				XMLString::release(&fileTmp);
			}

			attr = attrList->getNamedItem(XercesString("format"));
			if(attr)
			{
				formatTmp = XMLString::transcode(attr->getNodeValue());
				info.format.assign(formatTmp);
				XMLString::release(&formatTmp);
			}

			attr = attrList->getNamedItem(XercesString("path"));
			if(attr)
			{
				pathTmp = XMLString::transcode(attr->getNodeValue());
				info.path.assign(pathTmp);
				XMLString::release(&pathTmp);
			}
			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)
			{
				char* submeshTmp = XMLString::transcode(attr->getNodeValue());
				submesh.assign(submeshTmp);
				XMLString::release(&submeshTmp);
			}
			
			attr = attrList->getNamedItem(XercesString("item"));
			if(attr)
			{
				char* itemTmp = XMLString::transcode(attr->getNodeValue());
				item.assign(itemTmp);
				XMLString::release(&itemTmp);
			}
			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));
		}
	}
}
Example #16
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;
}