bool DOMNodeImpl::isDefaultNamespace(const XMLCh* namespaceURI) const{ DOMNode *thisNode = castToNode(this); short type = thisNode->getNodeType(); switch (type) { case DOMNode::ELEMENT_NODE: { const XMLCh *prefix = thisNode->getPrefix(); // REVISIT: is it possible that prefix is empty string? if (prefix == 0 || !*prefix) { return XMLString::equals(namespaceURI, thisNode->getNamespaceURI()); } if (thisNode->hasAttributes()) { DOMElement *elem = (DOMElement *)thisNode; DOMNode *attr = elem->getAttributeNodeNS(XMLUni::fgXMLNSURIName, XMLUni::fgXMLNSString); if (attr != 0) { const XMLCh *value = attr->getNodeValue(); return XMLString::equals(namespaceURI, value); } } DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->isDefaultNamespace(namespaceURI); } return false; } case DOMNode::DOCUMENT_NODE:{ return ((DOMDocument*)thisNode)->getDocumentElement()->isDefaultNamespace(namespaceURI); } case DOMNode::ENTITY_NODE : case DOMNode::NOTATION_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: // type is unknown return false; case DOMNode::ATTRIBUTE_NODE:{ if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) { return fOwnerNode->isDefaultNamespace(namespaceURI); } return false; } default:{ DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->isDefaultNamespace(namespaceURI); } return false; } } }
const XMLCh* DOMNodeImpl::lookupNamespacePrefix(const XMLCh* const namespaceURI, bool useDefault, DOMElement *el) const { DOMNode *thisNode = castToNode(this); const XMLCh* ns = thisNode->getNamespaceURI(); // REVISIT: if no prefix is available is it null or empty string, or // could be both? const XMLCh* prefix = thisNode->getPrefix(); if (ns != 0 && XMLString::equals(ns,namespaceURI)) { if (useDefault || prefix != 0) { const XMLCh* foundNamespace = el->lookupNamespaceURI(prefix); if (foundNamespace != 0 && XMLString::equals(foundNamespace, namespaceURI)) { return prefix; } } } if (thisNode->hasAttributes()) { DOMNamedNodeMap *nodeMap = thisNode->getAttributes(); if(nodeMap != 0) { int length = nodeMap->getLength(); for (int i = 0;i < length;i++) { DOMNode *attr = nodeMap->item(i); const XMLCh* attrPrefix = attr->getPrefix(); const XMLCh* value = attr->getNodeValue(); ns = attr->getNamespaceURI(); if (ns != 0 && XMLString::equals(ns, XMLUni::fgXMLNSURIName)) { // DOM Level 2 nodes if ((useDefault && XMLString::equals(attr->getNodeName(), XMLUni::fgXMLNSString)) || (attrPrefix != 0 && XMLString::equals(attrPrefix, XMLUni::fgXMLNSString)) && XMLString::equals(value, namespaceURI)) { const XMLCh* localname= attr->getLocalName(); const XMLCh* foundNamespace = el->lookupNamespaceURI(localname); if (foundNamespace != 0 && XMLString::equals(foundNamespace, namespaceURI)) { return localname; } } } } } } DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return castToNodeImpl(ancestor)->lookupNamespacePrefix(namespaceURI, useDefault, el); } return 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(); }
bool CConfigParser::ParseButtons(DOMNode* node, TActionByNameMap actions, CDeviceContext* device) { if(node->hasChildNodes()) { DOMNodeList* buttonNodes = node->getChildNodes(); unsigned long length = buttonNodes->getLength(); for(unsigned long idx = 0; idx < length; idx++) { DOMNode* buttonNode = buttonNodes->item(idx); wstring nodeName = buttonNode->getNodeName(); if(buttonNode->hasAttributes()) { DOMNode* mouseSim = buttonNode->getAttributes()->getNamedItem(L"simulateMouseButton"); if(mouseSim != NULL) { wstring mouseSimBtn = mouseSim->getNodeValue(); if(mouseSimBtn.compare(L"left") == 0) device->AddButton(new CLeftMouseButtonAction()); if(mouseSimBtn.compare(L"right") == 0) device->AddButton(new CRightMouseButtonAction()); } else { wstring downAction = buttonNode->getAttributes()->getNamedItem(L"downAction")->getNodeValue(); wstring upAction = buttonNode->getAttributes()->getNamedItem(L"upAction")->getNodeValue(); device->AddButton(new CActionButton(actions[downAction], actions[upAction])); } } else if (nodeName.compare(L"button") == 0) { device->AddButton((IButton*)NULL); } } } return false; }
const XMLCh* DOMNodeImpl::lookupNamespaceURI(const XMLCh* specifiedPrefix) const { DOMNode *thisNode = castToNode(this); short type = thisNode->getNodeType(); switch (type) { case DOMNode::ELEMENT_NODE : { const XMLCh* ns = thisNode->getNamespaceURI(); const XMLCh* prefix = thisNode->getPrefix(); if (ns != 0) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix == 0 && prefix == specifiedPrefix) { // looking for default namespace return ns; } else if (prefix != 0 && XMLString::equals(prefix, specifiedPrefix)) { // non default namespace return ns; } } if (thisNode->hasAttributes()) { DOMNamedNodeMap *nodeMap = thisNode->getAttributes(); if(nodeMap != 0) { int length = nodeMap->getLength(); for (int i = 0;i < length;i++) { DOMNode *attr = nodeMap->item(i); const XMLCh *attrPrefix = attr->getPrefix(); const XMLCh *value = attr->getNodeValue(); ns = attr->getNamespaceURI(); if (ns != 0 && XMLString::equals(ns, XMLUni::fgXMLNSURIName)) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == 0 && XMLString::equals(attr->getNodeName(), XMLUni::fgXMLNSString)) { // default namespace return value; } else if (attrPrefix != 0 && XMLString::equals(attrPrefix, XMLUni::fgXMLNSString) && XMLString::equals(attr->getLocalName(), specifiedPrefix)) { // non default namespace return value; } } } } } DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->lookupNamespaceURI(specifiedPrefix); } return 0; } case DOMNode::DOCUMENT_NODE : { return((DOMDocument*)thisNode)->getDocumentElement()->lookupNamespaceURI(specifiedPrefix); } case DOMNode::ENTITY_NODE : case DOMNode::NOTATION_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: // type is unknown return 0; case DOMNode::ATTRIBUTE_NODE:{ if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) { return fOwnerNode->lookupNamespaceURI(specifiedPrefix); } return 0; } default:{ DOMNode *ancestor = getElementAncestor(castToNode(this)); if (ancestor != 0) { return ancestor->lookupNamespaceURI(specifiedPrefix); } return 0; } } }
bool CConfigParser::ParseActions(DOMNodeList* actionNodeList, ADeviceListener& configClass) { USES_CONVERSION; // Parse all the actions if(actionNodeList != NULL && actionNodeList->getLength() > 0) { DOMNodeList* actionNodes = actionNodeList->item(0)->getChildNodes(); for(unsigned long i = 0; i < actionNodes->getLength(); i++) { DOMNode* actionNode = actionNodes->item(i); wstring actionType = actionNode->getNodeName(); if(actionType.compare(L"#text") == 0) continue; XMLCh* xmlChNameTxt = L"name"; wstring actionName; if(actionNode->hasAttributes()) { DOMNode* nameAttribute = actionNode->getAttributes()->getNamedItem(xmlChNameTxt); actionName = nameAttribute->getNodeValue(); } if(actionType.compare(L"sendCopyDataWindowMessage") == 0 || actionType.compare(L"sendCommandWindowMessage") == 0) { wstring message = actionNode->getAttributes()->getNamedItem(L"message")->getNodeValue(); bool findByClass = FALSE; wstring windowAttributeName = L"window"; if(actionNode->getAttributes()->getNamedItem(L"window") == NULL) { findByClass = TRUE; windowAttributeName = L"windowClass"; } wstring window = actionNode->getAttributes()->getNamedItem(windowAttributeName.c_str())->getNodeValue(); CSendWindowMessageAction* messageActionToAdd = NULL; if(actionType.compare(L"sendCommandWindowMessage") == 0) { messageActionToAdd = new CSendWindowMessageAction(_wtol(message.c_str()), OLE2T(window.c_str()), findByClass); } if(actionType.compare(L"sendCopyDataWindowMessage") == 0) { messageActionToAdd = new CSendWindowMessageAction(OLE2T(message.c_str()), OLE2T(window.c_str()), findByClass); } if(messageActionToAdd != NULL) configClass.AddAction(actionName, messageActionToAdd); } if(actionType.compare(L"execute") == 0) { char* executable = XMLString::transcode( actionNode->getAttributes()->getNamedItem(L"executable")->getNodeValue()); char* commandline = XMLString::transcode( actionNode->getAttributes()->getNamedItem(L"commandline")->getNodeValue()); configClass.AddAction(actionName, new CExecuteAction(executable, commandline)); XMLString::release(&executable); XMLString::release(&commandline); } if(actionType.compare(L"keyPress") == 0) { TKeyList keys; DOMNodeList* keyNodes = actionNode->getChildNodes(); unsigned long count = keyNodes->getLength(); for(unsigned long keyIdx=0; keyIdx < keyNodes->getLength(); keyIdx++) { DOMNode* keyNode = keyNodes->item(keyIdx); if(wcscmp(keyNode->getNodeName(), L"#text") == 0) continue; const XMLCh* keyValue = keyNode->getFirstChild()->getNodeValue(); if(keyValue == NULL) continue; int test = VK_CONTROL; keys.push_back(_wtoi(keyValue)); } configClass.AddAction(actionName, new CKeyboardAction(keys)); } if(actionType.compare(L"winampPlayPause") == 0) { configClass.AddAction(actionName, new CWinampPlayPause()); } if(actionType.compare(L"winampMute") == 0) { configClass.AddAction(actionName, new CWinampMute()); } // We make the assumption that the macros were put at the end of the // config file, otherwise the actions they execute may not exist! if(actionType.compare(L"macro") == 0) { wstring type = actionNode->getAttributes()->getNamedItem(L"type")->getNodeValue(); CMacroAction* actionToAdd = new CMacroAction(type.compare(L"all") == 0 ? true : false); DOMNodeList* macroActions = actionNode->getChildNodes(); unsigned long count = macroActions->getLength(); for(unsigned long actionIdx=0; actionIdx < count; actionIdx++) { DOMNode* macroActionNode = macroActions->item(actionIdx); if(wcscmp(macroActionNode->getNodeName(), L"#text") == 0) continue; wstring macroActionName = macroActionNode->getAttributes()->getNamedItem(L"name")->getNodeValue(); actionToAdd->AddAction(configClass.GetActions()[macroActionName]); } configClass.AddAction(actionName, actionToAdd); } } } return true; }
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; } } }
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; } } }