use of org.w3c.dom.DOMException in project Lucee by lucee.
the class XMLElementStruct method setIdAttributeNS.
// used only with java 7, do not set @Override
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {
// dynamic load to support jre 1.4 and 1.5
try {
Method m = element.getClass().getMethod("setIdAttributeNS", new Class[] { namespaceURI.getClass(), localName.getClass(), boolean.class });
m.invoke(element, new Object[] { namespaceURI, localName, Caster.toBoolean(isId) });
} catch (Exception e) {
throw new PageRuntimeException(Caster.toPageException(e));
}
}
use of org.w3c.dom.DOMException in project keycloak by keycloak.
the class SubsystemParsingAllowedClockSkewTestCase method setSubsystemXml.
private void setSubsystemXml(String value, String unit) throws IOException {
try {
String template = readResource("keycloak-saml-1.4.xml");
if (value != null) {
// assign the AllowedClockSkew element using DOM
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(template)));
// create the skew element
Element allowedClockSkew = doc.createElement(Constants.XML.ALLOWED_CLOCK_SKEW);
if (unit != null) {
allowedClockSkew.setAttribute(Constants.XML.ALLOWED_CLOCK_SKEW_UNIT, unit);
}
allowedClockSkew.setTextContent(value);
// locate the IDP and insert the node
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile("/subsystem/secure-deployment[1]/SP/IDP").evaluate(doc, XPathConstants.NODESET);
nodeList.item(0).appendChild(allowedClockSkew);
// transform again to XML
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
subsystemXml = writer.getBuffer().toString();
} else {
subsystemXml = template;
}
} catch (DOMException | ParserConfigurationException | SAXException | TransformerException | XPathExpressionException e) {
throw new IOException(e);
}
}
use of org.w3c.dom.DOMException in project keycloak by keycloak.
the class SubsystemParsingAllowedClockSkewTestCase method setSubsystemXml.
private void setSubsystemXml(String value, String unit) throws IOException {
try {
String template = readResource("keycloak-saml-1.4.xml");
if (value != null) {
// assign the AllowedClockSkew element using DOM
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(template)));
// create the skew element
Element allowedClockSkew = doc.createElement(Constants.XML.ALLOWED_CLOCK_SKEW);
if (unit != null) {
allowedClockSkew.setAttribute(Constants.XML.ALLOWED_CLOCK_SKEW_UNIT, unit);
}
allowedClockSkew.setTextContent(value);
// locate the IDP and insert the node
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile("/subsystem/secure-deployment[1]/SP/IDP").evaluate(doc, XPathConstants.NODESET);
nodeList.item(0).appendChild(allowedClockSkew);
// transform again to XML
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
subsystemXml = writer.getBuffer().toString();
} else {
subsystemXml = template;
}
} catch (DOMException | ParserConfigurationException | SAXException | TransformerException | XPathExpressionException e) {
throw new IOException(e);
}
}
use of org.w3c.dom.DOMException in project keycloak by keycloak.
the class DeploymentArchiveProcessor method getKeycloakResolverClass.
private String getKeycloakResolverClass(Document doc) {
try {
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//web-app/context-param[param-name='keycloak.config.resolver']/param-value/text()");
NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
if (nodes != null && nodes.getLength() > 0) {
return nodes.item(0).getNodeValue();
}
} catch (DOMException e) {
throw new IllegalStateException(e);
} catch (XPathExpressionException e) {
throw new IllegalStateException(e);
}
return null;
}
use of org.w3c.dom.DOMException in project oozie by apache.
the class OozieCLI method parseDocument.
// Canibalized from Hadoop <code>Configuration.loadResource()</code>.
private Properties parseDocument(Document doc, Properties conf) throws IOException {
try {
Element root = doc.getDocumentElement();
if (!"configuration".equals(root.getLocalName())) {
throw new RuntimeException("bad conf file: top-level element not <configuration>");
}
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 (!"property".equals(prop.getLocalName())) {
throw new RuntimeException("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();
}
if ("value".equals(field.getLocalName()) && field.hasChildNodes()) {
value = ((Text) field.getFirstChild()).getData();
}
}
if (attr != null && value != null) {
conf.setProperty(attr, value);
}
}
return conf;
} catch (DOMException e) {
throw new IOException(e);
}
}
Aggregations