Example #1
0
Node*
Element::_getElementById (const DOMString& id)
{
    for (size_t i = 0; i < _children.length(); i++) {
        NamedNodeMap attrs = _children.item(i)->attributes();

        for (size_t h = 0; h < attrs.length(); h++) {
            Attr* attr = (Attr*) attrs.item(h);

            if (attr->_isId) {
                if (attr->value() == id) {
                    return _children.item(i);
                }
            }
        }
    }

    for (size_t i = 0; i < _children.length(); i++) {
        Node* element = _children.item(i)->_getElementById(id);

        if (element) {
            return element;
        }
    }

    return NULL;
}
static String imageToMarkup(const String& url, Element* element)
{
    StringBuilder markup;
    markup.append("<img src=\"");
    markup.append(url);
    markup.append("\"");
    // Copy over attributes.  If we are dragging an image, we expect things like
    // the id to be copied as well.
    NamedNodeMap* attrs = element->attributes();
    unsigned length = attrs->length();
    for (unsigned i = 0; i < length; ++i) {
        RefPtr<Attr> attr(static_cast<Attr*>(attrs->item(i).get()));
        if (attr->name() == "src")
            continue;
        markup.append(" ");
        markup.append(attr->name());
        markup.append("=\"");
        String escapedAttr = attr->value();
        escapedAttr.replace("\"", "&quot;");
        markup.append(escapedAttr);
        markup.append("\"");
    }

    markup.append("/>");
    return markup.toString();
}
Example #3
0
v8::Handle<v8::Value> V8NamedNodeMap::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.NamedNodeMap.IndexedPropertyGetter");
    NamedNodeMap* imp = V8NamedNodeMap::toNative(info.Holder());
    RefPtr<Node> result = imp->item(index);
    if (!result)
        return v8::Handle<v8::Value>();

    return toV8(result.release(), info.GetIsolate());
}
Example #4
0
void XmlWriter::write(const NodePtr nodeArg)
{
    NodePtr node = nodeArg;

    indent+=2;

    NamedNodeMap attributes = node->getAttributes();
    int nrAttrs = attributes.getLength();

    //### Start open tag
    spaces();
    po("<");
    pos(node->getNodeName());
    if (nrAttrs>0)
        po("\n");

    //### Attributes
    for (int i=0 ; i<nrAttrs ; i++)
        {
        NodePtr attr = attributes.item(i);
        spaces();
        pos(attr->getNodeName());
        po("=\"");
        pos(attr->getNodeValue());
        po("\"\n");
        }

    //### Finish open tag
    if (nrAttrs>0)
        spaces();
    po(">\n");

    //### Contents
    spaces();
    pos(node->getNodeValue());

    //### Children
    for (NodePtr child = node->getFirstChild() ;
         child.get() ;
         child=child->getNextSibling())
        {
        write(child);
        }

    //### Close tag
    spaces();
    po("</");
    pos(node->getNodeName());
    po(">\n");

    indent-=2;
}
Example #5
0
JSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionItem(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
    UNUSED_PARAM(args);
    if (!thisValue.isObject(&JSNamedNodeMap::s_info))
        return throwError(exec, TypeError);
    JSNamedNodeMap* castedThisObj = static_cast<JSNamedNodeMap*>(asObject(thisValue));
    NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThisObj->impl());
    unsigned index = args.at(0).toInt32(exec);


    JSC::JSValue result = toJS(exec, WTF::getPtr(imp->item(index)));
    return result;
}
Example #6
0
EncodedJSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionItem(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSNamedNodeMap::s_info))
        return throwVMTypeError(exec);
    JSNamedNodeMap* castedThis = static_cast<JSNamedNodeMap*>(asObject(thisValue));
    NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThis->impl());
    unsigned index(exec->argument(0).toUInt32(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->item(index)));
    return JSValue::encode(result);
}
Example #7
0
void dumpattrs(Node *node)
{
    NamedNodeMap  *attrs;
    Attr          *a;
    uword          i;
    size_t         na;

    oratext   *qname;
    oratext   *namespce;
    oratext   *local;
    oratext   *prefix;
    oratext   *value;

    if (attrs = node->getAttributes())
    {
       cout << "\n    ATTRIBUTES: \n";
       for (na = attrs->getLength(), i = 0; i < na; i++)
       { 
          /* get attr qualified name, local name, namespace, and prefix */

          a = (Attr *)attrs->item(i);

          qname = namespce = local = prefix = value = (oratext*)" ";

          if (a->getQualifiedName() != (oratext*)NULL)
             qname = a->getQualifiedName();

          if (a->getNamespace() != (oratext*)NULL)
             namespce = a->getNamespace();

          if (a->getLocal() != (oratext*)NULL)
             local = a->getLocal();

          if (a->getPrefix() != (oratext*)NULL)
             prefix = a->getPrefix();

          if (a->getValue() != (oratext*)NULL)
             value = a->getValue();

          cout << "      " << (char*)qname << " = " << (char*)value << "\n";
          cout << "      Namespace : " << (char*)namespce << "\n";
          cout << "      Local Name: " << (char*)local << "\n";
          cout << "      Prefix    : " << (char*)prefix << "\n\n";
       }
    }
    cout << "\n";
}
 /*
  * Runs the test case.
  */
 void runTest()
 {
    Document doc;
    DocumentType docType;
    NamedNodeMap notationList;
    Node notation;
    int notationType;
    doc = (Document) baseT::load("staff", false);
    docType = doc.getDoctype();
    baseT::assertNotNull(docType, __LINE__, __FILE__);
    notationList = docType.getNotations();
    baseT::assertNotNull(notationList, __LINE__, __FILE__);
    for (unsigned int indexN65609 = 0; indexN65609 != notationList.getLength(); indexN65609++) {
        notation = (Node) notationList.item(indexN65609);
  notationType = (int) notation.getNodeType();
    baseT::assertEquals(12, notationType, __LINE__, __FILE__);
  }
    
 }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList elementList;
      Node testAddress;
      NamedNodeMap attributes;
      Node child;
      String name;
      doc = (Document) baseT::load("staff", true);
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("address"));
      testAddress = elementList.item(1);
      attributes = testAddress.getAttributes();
      child = attributes.item(0);
      name = child.getNodeName();
      assertTrue(
    (baseT::equals("domestic", name) | baseT::equals("street", name))
);
      
   }
Example #10
0
/**
 * Parse incomming message (from server).
 * @param str Incomming server message
 * @return Message in Command structure
 */
Command XMLTool::parseXML(string str) {
	Command cmd;

	try  {
		DOMParser parser = DOMParser(0);
		AutoPtr<Document> pDoc = parser.parseString(str);
		NodeIterator it(pDoc, NodeFilter::SHOW_ELEMENT);
		Node* pNode = it.nextNode();
		NamedNodeMap* attributes = NULL;
		Node* attribute = NULL;

		while (pNode)  {
			if (pNode->nodeName().compare("server_adapter") == 0) {
				if (pNode->hasAttributes()) {
					attributes = pNode->attributes();
					for(unsigned int i = 0; i < attributes->length(); i++) {
						attribute = attributes->item(i);
						if (attribute->nodeName().compare("protocol_version") == 0) {
							cmd.protocol_version = attribute->nodeValue();
						}

						else if (attribute->nodeName().compare("state") == 0) {
							cmd.state = attribute->nodeValue();
						}
						// FIXME - id attribute is here only for backward compatibility, it should be removed in Q1/2016
						else if (attribute->nodeName().compare("euid") == 0 || attribute->nodeName().compare("id") == 0) {
							cmd.euid = stoull(attribute->nodeValue(), nullptr, 0);
						}

						else if (attribute->nodeName().compare("device_id") == 0) {
							cmd.device_id = atoll(attribute->nodeValue().c_str());
						}

						else if (attribute->nodeName().compare("time") == 0) {
							cmd.time = atoll(attribute->nodeValue().c_str());
						}

						else {
							log.error("Unknow attribute for SERVER_ADAPTER : " + fromXMLString(attribute->nodeName()));
						}
					}
					attributes->release();
				}
			}

			else if (pNode->nodeName().compare("value") == 0) {
				if(cmd.state == "getparameters" || cmd.state == "parameters"){
					string inner = pNode->innerText();
					string device_id = "";

					if (pNode->hasAttributes()) {
						attributes = pNode->attributes();
						string device_id = "";
						for(unsigned int i = 0; i < attributes->length(); i++) {
							attribute = attributes->item(i);
							if (attribute->nodeName().compare("device_id") == 0) {
								device_id = toNumFromString(attribute->nodeValue());
							}
						}
						attributes->release();
					}
					cmd.params.value.push_back({inner, device_id});
				}
				else {
					float val = atof(pNode->innerText().c_str());

					if (pNode->hasAttributes()) {
						int module_id = 0;
						attributes = pNode->attributes();
						for(unsigned int i = 0; i < attributes->length(); i++) {
							attribute = attributes->item(i);
							if (attribute->nodeName().compare("module_id") == 0) {
								module_id = toNumFromString(attribute->nodeValue());
							}
						}
						cmd.values.push_back({module_id, val});  //TODO Hex number is processed wrongly
						attributes->release();
					}
				}
			}
			else if (pNode->nodeName().compare("parameter") == 0) {
				if (pNode->hasAttributes()) {
					attributes = pNode->attributes();
					for(unsigned int i = 0; i < attributes->length(); i++) {
						attribute = attributes->item(i);
						if (attribute->nodeName().compare("param_id") == 0 || attribute->nodeName().compare("id") == 0) {
							cmd.params.param_id = toNumFromString(attribute->nodeValue());
						}
						else if (attribute->nodeName().compare("euid") == 0) {
							cmd.params.euid = toNumFromString(attribute->nodeValue());
						}
					}
					attributes->release();
				}
			}
			pNode = it.nextNode();
		}
	}
	catch (Poco::Exception& e) {
		log.error("Invalid format of incoming message!" + e.displayText());
		cmd.state = "error";
	}
	return cmd;
}