Search in sources :

Example 36 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project jdk8u_jdk by JetBrains.

the class ShortHistogramTest method dump.

private static void dump(Node node, String ident) {
    if (node == null) {
        return;
    }
    System.out.printf("%s%s\n", ident, node.getNodeName());
    // dump node attributes...
    NamedNodeMap attribs = node.getAttributes();
    if (attribs != null) {
        for (int i = 0; i < attribs.getLength(); i++) {
            Node a = attribs.item(i);
            System.out.printf("%s  %s: %s\n", ident, a.getNodeName(), a.getNodeValue());
        }
    }
    // dump node children...
    dump(node.getFirstChild(), ident + "    ");
    dump(node.getNextSibling(), ident);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node)

Example 37 with NamedNodeMap

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

the class MArchive method getBinaryDataFromFileSystem.

/**
	 * @return attachment data
	 */
private byte[] getBinaryDataFromFileSystem() {
    if ("".equals(m_archivePathRoot)) {
        throw new IllegalArgumentException("no attachmentPath defined");
    }
    byte[] data = super.getBinaryData();
    m_deflated = null;
    m_inflated = null;
    if (data == null) {
        return null;
    }
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.parse(new ByteArrayInputStream(data));
        final NodeList entries = document.getElementsByTagName("entry");
        if (entries.getLength() != 1) {
            log.severe("no archive entry found");
        }
        final Node entryNode = entries.item(0);
        final NamedNodeMap attributes = entryNode.getAttributes();
        final Node fileNode = attributes.getNamedItem("file");
        if (fileNode == null) {
            log.severe("no filename for entry");
            return null;
        }
        String filePath = fileNode.getNodeValue();
        log.fine("filePath: " + filePath);
        if (filePath != null) {
            filePath = filePath.replaceFirst(ARCHIVE_FOLDER_PLACEHOLDER, m_archivePathRoot.replaceAll("\\\\", "\\\\\\\\"));
            //just to be shure...
            String replaceSeparator = File.separator;
            if (!replaceSeparator.equals("/")) {
                replaceSeparator = "\\\\";
            }
            filePath = filePath.replaceAll("/", replaceSeparator);
            filePath = filePath.replaceAll("\\\\", replaceSeparator);
        }
        log.fine("filePath: " + filePath);
        final File file = new File(filePath);
        if (file.exists()) {
            // read files into byte[]
            final byte[] dataEntry = new byte[(int) file.length()];
            try {
                final FileInputStream fileInputStream = new FileInputStream(file);
                fileInputStream.read(dataEntry);
                fileInputStream.close();
            } catch (FileNotFoundException e) {
                log.severe("File Not Found.");
                e.printStackTrace();
            } catch (IOException e1) {
                log.severe("Error Reading The File.");
                e1.printStackTrace();
            }
            return dataEntry;
        } else {
            log.severe("file not found: " + file.getAbsolutePath());
            return null;
        }
    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
        log.severe(x.getMessage());
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        pce.printStackTrace();
        log.severe(pce.getMessage());
    } catch (IOException ioe) {
        // I/O error
        ioe.printStackTrace();
        log.severe(ioe.getMessage());
    }
    return null;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 38 with NamedNodeMap

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

the class MAttachment method loadLOBDataFromFileSystem.

//	loadLOBData
/**
	 * 	Load Data from file system
	 *	@return true if success
	 */
private boolean loadLOBDataFromFileSystem() {
    if ("".equals(m_attachmentPathRoot)) {
        log.severe("no attachmentPath defined");
        return false;
    }
    // Reset
    m_items = new ArrayList<MAttachmentEntry>();
    //
    byte[] data = getBinaryData();
    if (data == null)
        return true;
    log.fine("TextFileSize=" + data.length);
    if (data.length == 0)
        return true;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.parse(new ByteArrayInputStream(data));
        final NodeList entries = document.getElementsByTagName("entry");
        for (int i = 0; i < entries.getLength(); i++) {
            final Node entryNode = entries.item(i);
            final NamedNodeMap attributes = entryNode.getAttributes();
            final Node fileNode = attributes.getNamedItem("file");
            final Node nameNode = attributes.getNamedItem("name");
            if (fileNode == null || nameNode == null) {
                log.severe("no filename for entry " + i);
                m_items = null;
                return false;
            }
            log.fine("name: " + nameNode.getNodeValue());
            String filePath = fileNode.getNodeValue();
            log.fine("filePath: " + filePath);
            if (filePath != null) {
                filePath = filePath.replaceFirst(ATTACHMENT_FOLDER_PLACEHOLDER, m_attachmentPathRoot.replaceAll("\\\\", "\\\\\\\\"));
                //just to be shure...
                String replaceSeparator = File.separator;
                if (!replaceSeparator.equals("/")) {
                    replaceSeparator = "\\\\";
                }
                filePath = filePath.replaceAll("/", replaceSeparator);
                filePath = filePath.replaceAll("\\\\", replaceSeparator);
            }
            log.fine("filePath: " + filePath);
            final File file = new File(filePath);
            if (file.exists()) {
                // read files into byte[]
                final byte[] dataEntry = new byte[(int) file.length()];
                try {
                    final FileInputStream fileInputStream = new FileInputStream(file);
                    fileInputStream.read(dataEntry);
                    fileInputStream.close();
                } catch (FileNotFoundException e) {
                    log.severe("File Not Found.");
                    e.printStackTrace();
                } catch (IOException e1) {
                    log.severe("Error Reading The File.");
                    e1.printStackTrace();
                }
                final MAttachmentEntry entry = new MAttachmentEntry(filePath, dataEntry, m_items.size() + 1);
                m_items.add(entry);
            } else {
                log.severe("file not found: " + file.getAbsolutePath());
            }
        }
    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
        log.severe(x.getMessage());
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        pce.printStackTrace();
        log.severe(pce.getMessage());
    } catch (IOException ioe) {
        // I/O error
        ioe.printStackTrace();
        log.severe(ioe.getMessage());
    }
    return true;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 39 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project lucene-solr by apache.

the class Config method getUnknownAttributes.

/**
   * Returns the set of attributes on the given element that are not among the given knownAttributes,
   * or null if all attributes are known.
   */
public Set<String> getUnknownAttributes(Element element, String... knownAttributes) {
    Set<String> knownAttributeSet = new HashSet<>(Arrays.asList(knownAttributes));
    Set<String> unknownAttributeSet = null;
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); ++i) {
        final String attributeName = attributes.item(i).getNodeName();
        if (!knownAttributeSet.contains(attributeName)) {
            if (null == unknownAttributeSet) {
                unknownAttributeSet = new HashSet<>();
            }
            unknownAttributeSet.add(attributeName);
        }
    }
    return unknownAttributeSet;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) HashSet(java.util.HashSet)

Example 40 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project poi by apache.

the class XSSFExportToXml method createAttribute.

private Node createAttribute(Document doc, Node currentNode, String axisName) {
    String attributeName = axisName.substring(1);
    NamedNodeMap attributesMap = currentNode.getAttributes();
    Node attribute = attributesMap.getNamedItem(attributeName);
    if (attribute == null) {
        attribute = doc.createAttributeNS("", attributeName);
        attributesMap.setNamedItem(attribute);
    }
    return attribute;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

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