Search in sources :

Example 26 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project ats-framework by Axway.

the class FileSnapshot method fromFile.

/**
     * Create an instance from a file
     * @param fileNode
     */
static FileSnapshot fromFile(Element fileNode) {
    NamedNodeMap fileAttributes = fileNode.getAttributes();
    String pathAtt = fileAttributes.getNamedItem("path").getNodeValue();
    long fileSize = -1;
    long fileTimeModified = -1;
    String fileMD5 = null;
    String filePermissions = null;
    Node sizeNode = fileAttributes.getNamedItem("size");
    if (sizeNode != null) {
        fileSize = Long.parseLong(sizeNode.getNodeValue());
    }
    Node timeModifiedNode = fileAttributes.getNamedItem("modified");
    if (timeModifiedNode != null) {
        fileTimeModified = SnapshotUtils.stringToDate(timeModifiedNode.getNodeValue());
    }
    Node md5Node = fileAttributes.getNamedItem("md5");
    if (md5Node != null) {
        fileMD5 = md5Node.getNodeValue();
    }
    Node permissionsNode = fileAttributes.getNamedItem("permissions");
    if (permissionsNode != null) {
        filePermissions = permissionsNode.getNodeValue();
    }
    FileSnapshot fileSnapshot = new FileSnapshot(pathAtt, fileSize, fileTimeModified, fileMD5, filePermissions);
    log.debug("Add " + fileSnapshot.toString());
    return fileSnapshot;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Example 27 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project Asqatasun by Asqatasun.

the class HeritrixInverseBooleanAttributeValueModifier method modifyDocument.

@Override
public Document modifyDocument(Document document, String value) {
    if (StringUtils.isBlank(value) || (!value.equalsIgnoreCase(Boolean.FALSE.toString()) && !value.equalsIgnoreCase(Boolean.TRUE.toString()))) {
        return document;
    }
    try {
        Boolean valueToSet = !Boolean.valueOf(value);
        Node parentNode = getNodeFromXpath(document);
        NamedNodeMap attr = parentNode.getAttributes();
        Node nodeAttr = attr.getNamedItem(DEFAULT_ATTRIBUTE_NAME);
        nodeAttr.setTextContent(valueToSet.toString());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Update " + getAttributeValue() + " attribute of bean " + getIdBeanParent() + " with value " + valueToSet.toString());
        }
    } catch (XPathExpressionException ex) {
        LOGGER.warn(ex);
    }
    return document;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node)

Example 28 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class AMModuleProperties method getAttribute.

//end of walk
private String getAttribute(Node node, String name) {
    NamedNodeMap nnm = node.getAttributes();
    if (nnm != null) {
        int len = nnm.getLength();
        Attr attr;
        for (int i = 0; i < len; i++) {
            attr = (Attr) nnm.item(i);
            if (attr.getNodeName().equals(name)) {
                return attr.getNodeValue();
            }
        }
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 29 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project ACS by ACS-Community.

the class EbeDocument method readNode.

/** Read the node into a ComplexObject
         * @param no the DOM node to read 
         * @param obj the Complex Object to fill
         */
private void readNode(Node no, ComplexObject obj) {
    if (no == null)
        return;
    NamedNodeMap attrs = no.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        String name = attrs.item(i).getNodeName();
        String val = attrs.item(i).getNodeValue();
        if (name.compareTo("name") == 0)
            obj.setValue(val);
        obj.setAttributeValue(name, val);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 30 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class XMLParser method walkTree.

/*
     * static public void main(String argv[]) throws Exception { XMLParser wp =
     * new XMLParser(true); GenericNode n = (GenericNode) wp.parse(new
     * FileInputStream(argv[0])); System.out.println("FINAL:"+n.toString()); }
     */
ParseOutput walkTree(Node nd) throws XMLException {
    Vector elements = new Vector();
    String pcdata = null;
    Hashtable atts = new Hashtable();
    NamedNodeMap nd_map = nd.getAttributes();
    if (nd_map != null) {
        for (int i = 0; i < nd_map.getLength(); i++) {
            Node att = nd_map.item(i);
            atts.put(att.getNodeName(), XMLUtils.unescapeSpecialCharacters(att.getNodeValue()));
        }
    }
    for (Node ch = nd.getFirstChild(); ch != null; ch = ch.getNextSibling()) {
        switch(ch.getNodeType()) {
            case Node.ELEMENT_NODE:
                elements.addElement(walkTree(ch));
                break;
            case Node.TEXT_NODE:
                String tmp = stripWhitespaces(XMLUtils.unescapeSpecialCharacters(ch.getNodeValue()));
                if (tmp != null && tmp.length() != 0)
                    pcdata = tmp;
                break;
            default:
        }
    }
    // lookup hash
    String po_name = (String) elemmap.get(nd.getNodeName());
    ParseOutput po;
    if (po_name == null) {
        if (useGenericClass)
            po = new GenericNode();
        else
            throw new XMLException("No class registered for" + nd.getNodeName());
    } else {
        try {
            po = (ParseOutput) Class.forName(po_name).newInstance();
        } catch (Exception ex) {
            StringBuilder buf = new StringBuilder();
            buf.append("Got Exception while creating class instance of ");
            buf.append(nd.getNodeName());
            buf.append(" :");
            buf.append(ex.toString());
            throw new XMLException(buf.toString());
        }
    }
    po.process(this, nd.getNodeName(), elements, atts, pcdata);
    return po;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Hashtable(java.util.Hashtable) Node(org.w3c.dom.Node) Vector(java.util.Vector) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

NamedNodeMap (org.w3c.dom.NamedNodeMap)991 Node (org.w3c.dom.Node)688 NodeList (org.w3c.dom.NodeList)338 Attr (org.w3c.dom.Attr)295 Element (org.w3c.dom.Element)237 Document (org.w3c.dom.Document)153 ArrayList (java.util.ArrayList)92 HashMap (java.util.HashMap)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)59 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)58 IOException (java.io.IOException)53 SAXException (org.xml.sax.SAXException)41 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)40 List (java.util.List)36 Map (java.util.Map)33 File (java.io.File)27 InputStream (java.io.InputStream)26 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)25 DOMException (org.w3c.dom.DOMException)25 ByteArrayInputStream (java.io.ByteArrayInputStream)19