Package org.w3c.dom

Examples of org.w3c.dom.Attr


   * @param attribValue The value of the attribute to set.
   */
  public static void setAttribute(Document doc, Node node, String attribName,
    String attribValue)
  {
    Attr attr = doc.createAttribute(attribName);
    attr.setNodeValue(attribValue);
    node.getAttributes().setNamedItem(attr);
  }
View Full Code Here


        .getConverter(mEncodingSystem);

    NodeList records = doc.getElementsByTagName(TAG_RECORD);
    Node recordNode;
    NamedNodeMap recordAttributes;
    Attr recordLengthAttr;
    int recordLength;
    byte[] recordArray;

    NodeList fields;
    Node fieldNode;
    NamedNodeMap fieldAttributes;
    Attr fieldLengthAttr;
    int fieldLength;
    Node fieldTextNode;
    String fieldValue;
    byte[] fieldBytes;
    int pos;

    for (int i = 0; i < records.getLength(); i++)
    {
      recordNode = records.item(i);
      recordAttributes = recordNode.getAttributes();
      recordLengthAttr = (Attr) recordAttributes.getNamedItem(TAG_LENGTH);
      recordLength = Integer.parseInt(recordLengthAttr.getNodeValue());
      recordArray = new byte[recordLength];

      pos = 0;

      fields = recordNode.getChildNodes();
      for (int k = 0; k < fields.getLength(); k++)
      {
        fieldNode = fields.item(k);

        if (fieldNode.getNodeType() == Node.ELEMENT_NODE)
        {
          fieldAttributes = fieldNode.getAttributes();
          fieldLengthAttr = (Attr) fieldAttributes
              .getNamedItem(TAG_LENGTH);
          fieldLength = Integer.parseInt(fieldLengthAttr
              .getNodeValue());
          fieldTextNode = fieldNode.getFirstChild();
          fieldValue = fieldTextNode.getNodeValue();
          fieldBytes = conv
              .stringToByteArray(fieldValue, fieldLength);
View Full Code Here

     
      public void writeResponse(HttpOutputStream outputStream, HttpInputStream inputStream, Document doc) throws IOException {
         // log.severe(debug(inputStream));
         Element el = doc.getDocumentElement();

         Attr admin = doc.createAttribute(ADMIN_ROLE);
         Attr initiator = doc.createAttribute(INITIATOR_ROLE);
         Attr user = doc.createAttribute(USER_ROLE);
         if (this.authMethod != null) {
            String userName = extractUserName(inputStream);
            if (userName == null)
               userName = "";
            String roles = (String)this.roles.get(userName);
            if (roles == null) {
               admin.setValue("false");
               initiator.setValue("false");
               user.setValue("false");
            }
            else if (roles.indexOf(ADMIN_ROLE) > -1) {
               admin.setValue("true");
               initiator.setValue("true");
               user.setValue("true");
            }
            else if (roles.indexOf(INITIATOR_ROLE) > -1) {
               admin.setValue("false");
               initiator.setValue("true");
               user.setValue("true");
            }
            else {
               admin.setValue("false");
               initiator.setValue("false");
               user.setValue("true");
            }
         }
         else {
            admin.setValue("true");
            initiator.setValue("true");
            user.setValue("true");
         }
         el.setAttributeNode(admin);
         el.setAttributeNode(initiator);
         el.setAttributeNode(user);
         // outputStream.setHeader("Cache-Control", "no-cache");
View Full Code Here

      NamedNodeMap attributes = node.getAttributes();
      if (attributes != null && attributes.getLength() > 0) {
         int attributeCount = attributes.getLength();
         for (int i = 0; i < attributeCount; i++) {
            Attr attribute = (Attr)attributes.item(i);

            if (attribute.getNodeName().equalsIgnoreCase("oid")) {
               //String val = attribute.getNodeValue();
               attribute.setNodeValue(getOid());
            }
            else if (attribute.getNodeName().equalsIgnoreCase("contentMime")) {
               //String contentMime = attribute.getNodeValue();
               attribute.setNodeValue(getContentMime());
            }
            else if (attribute.getNodeName().equalsIgnoreCase("contentMimeExtended")) {
               // String contentMimeExtended = attribute.getNodeValue();
               attribute.setNodeValue(getContentMimeExtended());
            }
            else if (attribute.getNodeName().equalsIgnoreCase("domain")) {
               // String domain = attribute.getNodeValue();
               attribute.setNodeValue(getDomain());
            }
         }
      }

      log.info("DOM parsed the XmlKey " + getOid());
View Full Code Here

            }

            case Node.ELEMENT_NODE: {
                fOut.print('<');
                fOut.print(node.getNodeName());
                Attr attrs[] = sortAttributes(node.getAttributes());
                for (int i = 0; i < attrs.length; i++) {
                    Attr attr = attrs[i];
                    fOut.print(' ');
                    fOut.print(attr.getNodeName());
                    fOut.print("=\"");
                    normalizeAndPrint(attr.getNodeValue(), fOut);
                    fOut.print('"');
                }
                fOut.print('>');
                fOut.flush();
View Full Code Here

    /** Returns a sorted list of attributes. */
    protected static Attr[] sortAttributes(NamedNodeMap attrs) {

        int len = (attrs != null) ? attrs.getLength() : 0;
        Attr array[] = new Attr[len];
        for (int i = 0; i < len; i++) {
            array[i] = (Attr)attrs.item(i);
        }
        for (int i = 0; i < len - 1; i++) {
            String name = array[i].getNodeName();
            int index = i;
            for (int j = i + 1; j < len; j++) {
                String curName = array[j].getNodeName();
                if (curName.compareTo(name) < 0) {
                    name = curName;
                    index = j;
                }
            }
            if (index != i) {
                Attr temp = array[i];
                array[i] = array[index];
                array[index] = temp;
            }
        }

View Full Code Here

    NamedNodeMap m = element.getAttributes();
    // there may be no attributes defined (check for null attribute)
    String id=null;
    for (int i = 0; id==null && _attribute != null && i < _attribute.length; i++) {
      String n = _attribute[i].getName();
      Attr a = (Attr) (n==null?null:m.getNamedItem(n));
      // the attribute may not have any occurrences
      id = _attribute[i].getID(a, ctx);
    }
    return id;
  }
View Full Code Here

 
  static boolean preserved(Node node, boolean def) {
    if (node==null) return def;
    switch (node.getNodeType()) {
    case Node.ATTRIBUTE_NODE:
      Attr a = (Attr) node;
      if (a.getNamespaceURI()!=null && a.getNamespaceURI().equals(XML) && a.getLocalName().equals("space"))
        return a.getValue().equals("preserve");
      return preserved(a.getOwnerElement(),def);
    case Node.ELEMENT_NODE:
      Element e = (Element) node;
      if (e.hasAttributeNS(XML,"space"))
        return e.getAttributeNS(XML,"space").equals("preserve");
      return preserved(e.getParentNode(),def);
View Full Code Here

      if (def==null) {
        if (!attribute[i].getRef().startsWith("xml:"))
          Gloze.logger.warn("undefined attribute: "+attribute[i].getRef());
        continue;
      }     
      Attr a = (Attr) map.get(def.createURI(m,ctx)); //map.getNamedItem(name);
      // the attribute may not have any occurrences
      attribute[i].toRDF(subject, a, ctx);
    }   
  }
View Full Code Here

  public void declareGlobalNS(Model model, Context ctx) {
    addPrefix("rdf",RDF.getURI(),model);
    if (_node instanceof Element) {
      NamedNodeMap m = ((Element)_node).getAttributes();
      for (int i=0; i<m.getLength(); i++) {
        Attr a = (Attr) m.item(i);
        if (a.getName().startsWith("xmlns:")) {
          String ns = a.getValue();
          addPrefixes(a.getName().substring("xmlns:".length()),ns,model);
        }
      }   
    }
   
    // add anonymous namespace declaration   
    if (_node instanceof Element) {
      NamedNodeMap m = ((Element)_node).getAttributes();
      for (int i=0; i<m.getLength(); i++) {
        Attr a = (Attr) m.item(i);
        if (a.getName().equals("xmlns")) {
          String ns = a.getValue();
          if (!model.getNsPrefixMap().containsValue(terminateNS(ns)))
            addPrefix(ctx.createNSPrefix(),ns,model);
          break;
        }
      }   
View Full Code Here

TOP

Related Classes of org.w3c.dom.Attr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.