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