use of org.w3c.dom.DOMException in project oozie by apache.
the class XConfiguration method processNodes.
// Cannibalized from Hadoop <code>Configuration.loadResource()</code>.
private void processNodes(Element root) throws IOException {
try {
NodeList props = root.getChildNodes();
for (int i = 0; i < props.getLength(); i++) {
Node propNode = props.item(i);
if (!(propNode instanceof Element)) {
continue;
}
Element prop = (Element) propNode;
if (prop.getLocalName().equals("configuration")) {
processNodes(prop);
continue;
}
if (!"property".equals(prop.getLocalName())) {
throw new IOException("bad conf file: element not <property>");
}
NodeList fields = prop.getChildNodes();
String attr = null;
String value = null;
for (int j = 0; j < fields.getLength(); j++) {
Node fieldNode = fields.item(j);
if (!(fieldNode instanceof Element)) {
continue;
}
Element field = (Element) fieldNode;
if ("name".equals(field.getLocalName()) && field.hasChildNodes()) {
attr = ((Text) field.getFirstChild()).getData().trim();
}
if ("value".equals(field.getLocalName()) && field.hasChildNodes()) {
value = ((Text) field.getFirstChild()).getData();
}
}
if (attr != null && value != null) {
set(attr, value);
}
}
} catch (DOMException e) {
throw new IOException(e);
}
}
use of org.w3c.dom.DOMException in project photon-model by vmware.
the class VcSessionHandler method handleMessage.
@Override
public boolean handleMessage(SOAPMessageContext smc) {
if (isOutgoingMessage(smc)) {
try {
SOAPHeader header = getSOAPHeader(smc);
SOAPElement vcsessionHeader = header.addChildElement(new javax.xml.namespace.QName("#", "vcSessionCookie"));
vcsessionHeader.setValue(this.vcSessionCookie);
} catch (DOMException e) {
throw new RuntimeException(e);
} catch (SOAPException e) {
throw new RuntimeException(e);
}
}
return true;
}
use of org.w3c.dom.DOMException in project cerberus-source by cerberustesting.
the class XmlUtil method fromNode.
/**
* Returns a {@link Document} from the given {@link Node}
*
* @param node to transform to {@link Document}
* @return a {@link Document} from the given {@link Node}
* @throws XmlUtilException if an error occurs
*/
public static Document fromNode(Node node) throws XmlUtilException {
try {
Document document = XmlUtil.newDocument();
document.appendChild(document.adoptNode(node.cloneNode(true)));
return document;
} catch (DOMException e) {
Log.warn("Unable to create document from node " + node, e);
return null;
}
}
use of org.w3c.dom.DOMException in project ant by apache.
the class DOMUtil method importNode.
/**
* Simple tree walker that will clone recursively a node. This is to
* avoid using parser-specific API such as Sun's <tt>changeNodeOwner</tt>
* when we are dealing with DOM L1 implementations since <tt>cloneNode(boolean)</tt>
* will not change the owner document.
* <tt>changeNodeOwner</tt> is much faster and avoid the costly cloning process.
* <tt>importNode</tt> is in the DOM L2 interface.
* @param parent the node parent to which we should do the import to.
* @param child the node to clone recursively. Its clone will be
* appended to <tt>parent</tt>.
* @return the cloned node that is appended to <tt>parent</tt>
*/
public static Node importNode(Node parent, Node child) {
final Document doc = parent.getOwnerDocument();
Node copy;
switch(child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
copy = doc.createCDATASection(((CDATASection) child).getData());
break;
case Node.COMMENT_NODE:
copy = doc.createComment(((Comment) child).getData());
break;
case Node.DOCUMENT_FRAGMENT_NODE:
copy = doc.createDocumentFragment();
break;
case Node.ELEMENT_NODE:
final Element elem = doc.createElement(((Element) child).getTagName());
copy = elem;
final NamedNodeMap attributes = child.getAttributes();
if (attributes != null) {
final int size = attributes.getLength();
for (int i = 0; i < size; i++) {
final Attr attr = (Attr) attributes.item(i);
elem.setAttribute(attr.getName(), attr.getValue());
}
}
break;
case Node.ENTITY_REFERENCE_NODE:
copy = doc.createEntityReference(child.getNodeName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
final ProcessingInstruction pi = (ProcessingInstruction) child;
copy = doc.createProcessingInstruction(pi.getTarget(), pi.getData());
break;
case Node.TEXT_NODE:
copy = doc.createTextNode(((Text) child).getData());
break;
default:
// this should never happen
throw new IllegalStateException("Invalid node type: " + child.getNodeType());
}
// and we are iterating recursively over its children.
try {
final NodeList children = child.getChildNodes();
if (children != null) {
final int size = children.getLength();
for (int i = 0; i < size; i++) {
final Node newChild = children.item(i);
if (newChild != null) {
importNode(copy, newChild);
}
}
}
} catch (DOMException ignored) {
// Ignore
}
// bingo append it. (this should normally not be done here)
parent.appendChild(copy);
return copy;
}
use of org.w3c.dom.DOMException in project santuario-java by apache.
the class TransformXPath method enginePerformTransform.
/**
* Method enginePerformTransform
* {@inheritDoc}
* @param input
*
* @throws TransformationException
*/
protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws TransformationException {
try {
/**
* If the actual input is an octet stream, then the application MUST
* convert the octet stream to an XPath node-set suitable for use by
* Canonical XML with Comments. (A subsequent application of the
* REQUIRED Canonical XML algorithm would strip away these comments.)
*
* ...
*
* The evaluation of this expression includes all of the document's nodes
* (including comments) in the node-set representing the octet stream.
*/
Element xpathElement = XMLUtils.selectDsNode(transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);
if (xpathElement == null) {
Object[] exArgs = { "ds:XPath", "Transform" };
throw new TransformationException("xml.WrongContent", exArgs);
}
Node xpathnode = xpathElement.getFirstChild();
if (xpathnode == null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath");
}
String str = XMLUtils.getStrFromNode(xpathnode);
input.setNeedsToBeExpanded(needsCircumvent(str));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
input.setNodeSet(true);
return input;
} catch (DOMException ex) {
throw new TransformationException(ex);
}
}
Aggregations