Search in sources :

Example 66 with Document

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));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) HashSet(java.util.HashSet)

Example 67 with Document

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 68 with Document

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 69 with Document

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();
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 70 with Document

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;
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Aggregations

Document (org.w3c.dom.Document)3242 Element (org.w3c.dom.Element)1380 DocumentBuilder (javax.xml.parsers.DocumentBuilder)835 NodeList (org.w3c.dom.NodeList)718 Node (org.w3c.dom.Node)644 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)632 IOException (java.io.IOException)530 Test (org.junit.Test)485 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)384 SAXException (org.xml.sax.SAXException)370 InputSource (org.xml.sax.InputSource)292 File (java.io.File)268 InputStream (java.io.InputStream)249 ArrayList (java.util.ArrayList)244 StringReader (java.io.StringReader)233 DOMSource (javax.xml.transform.dom.DOMSource)230 ByteArrayInputStream (java.io.ByteArrayInputStream)202 Attr (org.w3c.dom.Attr)147 HashMap (java.util.HashMap)139 DOMException (org.w3c.dom.DOMException)136