use of org.w3c.dom.Document in project spring-security by spring-projects.
the class WebXmlMappableAttributesRetriever method afterPropertiesSet.
/**
* Loads the web.xml file using the configured <tt>ResourceLoader</tt> and parses the
* role-name elements from it, using these as the set of <tt>mappableAttributes</tt>.
*/
public void afterPropertiesSet() throws Exception {
Resource webXml = resourceLoader.getResource("/WEB-INF/web.xml");
Document doc = getDocument(webXml.getInputStream());
NodeList webApp = doc.getElementsByTagName("web-app");
if (webApp.getLength() != 1) {
throw new IllegalArgumentException("Failed to find 'web-app' element in resource" + webXml);
}
NodeList securityRoles = ((Element) webApp.item(0)).getElementsByTagName("security-role");
ArrayList<String> roleNames = new ArrayList<String>();
for (int i = 0; i < securityRoles.getLength(); i++) {
Element secRoleElt = (Element) securityRoles.item(i);
NodeList roles = secRoleElt.getElementsByTagName("role-name");
if (roles.getLength() > 0) {
String roleName = ((Element) roles.item(0)).getTextContent().trim();
roleNames.add(roleName);
logger.info("Retrieved role-name '" + roleName + "' from web.xml");
} else {
logger.info("No security-role elements found in " + webXml);
}
}
mappableAttributes = Collections.unmodifiableSet(new HashSet<String>(roleNames));
}
use of org.w3c.dom.Document in project hazelcast by hazelcast.
the class XmlClientConfigBuilder method parseAndBuildConfig.
private void parseAndBuildConfig(ClientConfig clientConfig) throws Exception {
this.clientConfig = clientConfig;
Document doc = parse(in);
Element root = doc.getDocumentElement();
checkRootElement(root);
try {
root.getTextContent();
} catch (Throwable e) {
domLevel3 = false;
}
process(root);
schemaValidation(root.getOwnerDocument());
handleConfig(root);
}
use of org.w3c.dom.Document in project hazelcast by hazelcast.
the class XmlConfigBuilder method parseAndBuildConfig.
private void parseAndBuildConfig(Config config) throws Exception {
this.config = config;
Document doc = parse(in);
Element root = doc.getDocumentElement();
checkRootElement(root);
try {
root.getTextContent();
} catch (Throwable e) {
domLevel3 = false;
}
process(root);
if (shouldValidateTheSchema()) {
schemaValidation(root.getOwnerDocument());
}
handleConfig(root);
}
use of org.w3c.dom.Document in project CoreNLP by stanfordnlp.
the class SUTimeMain method processTempEval3File.
public static void processTempEval3File(AnnotationPipeline pipeline, String in, String out) throws Exception {
// Process one tempeval file
Document doc = edu.stanford.nlp.util.XMLUtils.readDocumentFromFile(in);
Node timemlNode = XMLUtils.getNode(doc, "TimeML");
Node docIdNode = XMLUtils.getNode(timemlNode, "DOCID");
Node dctNode = XMLUtils.getNode(timemlNode, "DCT");
Node dctTimexNode = XMLUtils.getNode(dctNode, "TIMEX3");
Node titleNode = XMLUtils.getNode(timemlNode, "TITLE");
Node extraInfoNode = XMLUtils.getNode(timemlNode, "EXTRA_INFO");
Node textNode = XMLUtils.getNode(timemlNode, "TEXT");
String date = XMLUtils.getAttributeValue(dctTimexNode, "value");
String text = textNode.getTextContent();
Annotation annotation = textToAnnotation(pipeline, text, date);
Element annotatedTextElem = annotationToTmlTextElement(annotation);
Document annotatedDoc = XMLUtils.createDocument();
Node newTimemlNode = annotatedDoc.importNode(timemlNode, false);
if (docIdNode != null) {
newTimemlNode.appendChild(annotatedDoc.importNode(docIdNode, true));
}
newTimemlNode.appendChild(annotatedDoc.importNode(dctNode, true));
if (titleNode != null) {
newTimemlNode.appendChild(annotatedDoc.importNode(titleNode, true));
}
if (extraInfoNode != null) {
newTimemlNode.appendChild(annotatedDoc.importNode(extraInfoNode, true));
}
newTimemlNode.appendChild(annotatedDoc.adoptNode(annotatedTextElem));
annotatedDoc.appendChild(newTimemlNode);
PrintWriter pw = (out != null) ? IOUtils.getPrintWriter(out) : new PrintWriter(System.out);
String string = XMLUtils.documentToString(annotatedDoc);
pw.println(string);
pw.flush();
if (out != null)
pw.close();
}
use of org.w3c.dom.Document in project CoreNLP by stanfordnlp.
the class SUTimeMain method annotationToXmlDocument.
public static Document annotationToXmlDocument(Annotation annotation) {
Element dateElem = XMLUtils.createElement("DATE");
dateElem.setTextContent(annotation.get(CoreAnnotations.DocDateAnnotation.class));
Element textElem = annotationToTmlTextElement(annotation);
Element docElem = XMLUtils.createElement("DOC");
docElem.appendChild(dateElem);
docElem.appendChild(textElem);
// Create document and import elements into this document....
Document doc = XMLUtils.createDocument();
doc.appendChild(doc.importNode(docElem, true));
return doc;
}
Aggregations