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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations