Package org.dom4j

Examples of org.dom4j.DocumentFactory


    /**
     * @since 1.2.1
     */
    public Dom4JWriter(final Branch root, final XmlFriendlyReplacer replacer) {
        this(root, new DocumentFactory(), replacer);
    }
View Full Code Here


    public Dom4JWriter(final Branch root, final XmlFriendlyReplacer replacer) {
        this(root, new DocumentFactory(), replacer);
    }

    public Dom4JWriter(final Branch root) {
        this(root, new DocumentFactory(), new XmlFriendlyReplacer());
    }
View Full Code Here

    /**
     * @since 1.2.1
     */
    public Dom4JWriter() {
        this(new DocumentFactory(), new XmlFriendlyReplacer());
    }
View Full Code Here

    /**
     * Generates the WSDL document from the WSDL-DTC specification.
     */
    protected void generateWsdl()
    {
        DocumentFactory factory = DocumentFactory.getInstance();

        SoapMessageUtils.configureDocumentFactoryXPathNamespaceURIs(factory);
        SoapMessageUtils.registerDocumentFactoryXPathNamespaceURIs(factory, "xsd", XSD_NS_URI);
        SoapMessageUtils.registerDocumentFactoryXPathNamespaceURIs(factory, "wsdl", WSDL_NS_URI);
        SoapMessageUtils.registerDocumentFactoryXPathNamespaceURIs(factory, "wsoap12", WSOAP12_NS_URI);
        SoapMessageUtils.registerDocumentFactoryXPathNamespaceURIs(factory, "wsdl-dtc", WSDL_DTC_NS_URI);

        XPP3Reader reader = new XPP3Reader();
        Document doc;
        try
        {
            doc = reader.read(getClass().getResourceAsStream(resource));
        }
        catch (Exception e)
        {
            e.printStackTrace();
            wsdl = "Could not generate a WSDL document...";
            return;
        }
        String endpointName = doc.valueOf("wsdl-dtc:specification/wsdl-dtc:endpoint/wsdl-dtc:name/text()");
        String endpointNS = doc.valueOf("wsdl-dtc:specification/wsdl-dtc:endpoint/wsdl-dtc:namespace/text()");

        /*
         * Root
         */
        Document wsdlDoc = factory.createDocument();
        Element wsdlRoot = wsdlDoc.addElement("wsdl:definitions", WSDL_NS_URI);
        wsdlRoot.addNamespace("tns", endpointNS);
        wsdlRoot.addNamespace("wsoap12", WSOAP12_NS_URI);
        wsdlRoot.addNamespace("wsdl", WSDL_NS_URI);
        wsdlRoot.addNamespace("xsd", XSD_NS_URI);
        wsdlRoot.addAttribute("targetNamespace", doc.valueOf("//wsdl-dtc:endpoint/wsdl-dtc:namespace/text()"));

        /*
         * Copy the NS
         */
        List<Namespace> namespaces = doc.getRootElement().additionalNamespaces();
        for (Namespace ns : namespaces)
        {
            wsdlRoot.addNamespace(ns.getPrefix(), ns.getURI());
        }

        /*
         * Schema
         */
        Element types = wsdlRoot.addElement("wsdl:types", WSDL_NS_URI);
        types.add((Element)doc.selectSingleNode("//xsd:schema").clone());

        /*
         * Messages
         */
        List<Element> operationNodes = doc.selectNodes("//wsdl-dtc:operation");
        Map<String, Element> inputWsdlMessages = new HashMap<String, Element>();
        Map<String, Element> outputWsdlMessages = new HashMap<String, Element>();
        for (Element operationElement : operationNodes)
        {
            Element inBody = (Element) operationElement.selectSingleNode("wsdl-dtc:input/wsdl-dtc:body");
            if (inBody != null)
            {
                Element message = factory.createElement("wsdl:message", WSDL_NS_URI);
                message.addAttribute("name", operationElement.attributeValue("name") + "In");
                List<Element> parts = inBody.selectNodes("wsdl-dtc:part");
                for (Element part : parts)
                {
                    message.addElement("wsdl:part", WSDL_NS_URI).addAttribute("name", part.attributeValue("name")).addAttribute("element", part.attributeValue("element"));
                }
                wsdlRoot.add(message);
                inputWsdlMessages.put(operationElement.attributeValue("name"), message);
            }

            Element outBody = (Element) operationElement.selectSingleNode("wsdl-dtc:output/wsdl-dtc:body");
            if (outBody != null)
            {
                Element message = factory.createElement("wsdl:message", WSDL_NS_URI);
                message.addAttribute("name", operationElement.attributeValue("name") + "Out");
                List<Element> parts = outBody.selectNodes("wsdl-dtc:part");
                for (Element part : parts)
                {
                    message.addElement("wsdl:part", WSDL_NS_URI).addAttribute("name", part.attributeValue("name")).addAttribute("element", part.attributeValue("element"));
View Full Code Here

        Document articleDocument = new SAXReader().read(articleFile);

        String headlinePath = "/article" + "/head" + "/title";

        DocumentFactory factory = DocumentFactory.getInstance();

        XPath headlineXPath = factory.createXPath(headlinePath);

        List nodes = headlineXPath.selectNodes(articleDocument, headlineXPath);

        Element headlineElement = (Element) nodes.get(0);
View Full Code Here

        log.debug("Article file: " + articleFile.getPath());

        SAXReader reader = new SAXReader();
        Document articleDocument = reader.read(articleFile);

        DocumentFactory factory = DocumentFactory.getInstance();

        try {
            //------------------------------------
            // article file
            //------------------------------------
            StringTokenizer tokenizer = new StringTokenizer(articlePathParameter, "/");
            String articleChannel = tokenizer.nextToken();
            String articleSection = tokenizer.nextToken();
            String articleYear = tokenizer.nextToken();
            String articleDirectory = tokenizer.nextToken();

            // create backup
            backupFile(articlePath);

            // on we go
            XPath articleXPath = factory.createXPath(
                    "/NewsML/NewsItem/NewsComponent/ContentItem/DataContent/nitf/body/body.head");
            List parentNodes = articleXPath.selectNodes(articleDocument);
            Element parent = null;

            if (parentNodes.size() > 0) {
                parent = (Element) parentNodes.get(0);
                log.debug("\n--------------------------" + "\n- Parent element: " +
                    parent.getName() + "\n--------------------------");
            } else {
                log.error("\n--------------------------" + "\n- Parent node not found!" +
                    "\n--------------------------");
            }

            Element dossierElement = parent.element("dossier");

            String oldDossierId = "none";

            if (dossierElement != null) {
                oldDossierId = dossierElement.attribute("id").getStringValue();
            }

            boolean replace = !oldDossierId.equals(newDossierId);

            // ----------------------------------------------------
            // do we need to replace it at all?
            // ----------------------------------------------------
            if (replace) {
                // ----------------------------------------------------
                // does a previous dossier entry exist?
                // ----------------------------------------------------
                if (dossierElement != null) {
                    parent.remove(dossierElement);

                    // ----------------------------------------------------
                    // remove from old dossier file
                    // ----------------------------------------------------
                    String oldDossierPath = dossierBasePath + oldDossierId + File.separator +
                        "index.xml";
                    File oldDossierFile = new File(oldDossierPath);

                    Document oldDossierDocument = reader.read(oldDossierFile);

                    XPath dossierXPath = factory.createXPath("/dossier/articles");
                    List oldArticlesElements = dossierXPath.selectNodes(oldDossierDocument);
                    Element oldArticlesElement = null;

                    if (oldArticlesElements.size() > 0) {
                        oldArticlesElement = (Element) oldArticlesElements.get(0);
                        log.debug("\n--------------------------" +
                            "\n- Old Dossier Parent element: " + oldArticlesElement.getName() +
                            "\n--------------------------");
                    } else {
                        log.error("\n--------------------------" +
                            "\n- Old Dossier Parent node not found!" +
                            "\n--------------------------");
                    }

                    List articleElements = oldArticlesElement.elements("article");
                    Element elementToRemove = null;

                    for (Iterator i = articleElements.iterator(); i.hasNext();) {
                        Element articleElement = (Element) i.next();

                        if (articleElement.attribute("channel").getStringValue().equals(articleChannel) &&
                                articleElement.attribute("section").getStringValue().equals(articleSection) &&
                                articleElement.attribute("year").getStringValue().equals(articleYear) &&
                                articleElement.attribute("id").getStringValue().equals(articleDirectory)) {
                            elementToRemove = articleElement;
                        }
                    }

                    oldArticlesElement.remove(elementToRemove);
                    writeDocument(oldDossierPath, oldDossierDocument);

                    // ----------------------------------------------------
                    // removing done
                    // ----------------------------------------------------
                }

                if (!newDossierId.equals("none")) {
                    // ----------------------------------------------------
                    // insert new dossier element
                    // ----------------------------------------------------
                    dossierElement = factory.createElement("dossier");
                    dossierElement.add(factory.createAttribute(dossierElement, "id", newDossierId));
                    parent.add(dossierElement);

                    //------------------------------------
                    // new dossier file
                    //------------------------------------
                    // create backup
                    backupFile(newDossierPath);

                    File newDossierFile = new File(newDossierPath);
                    log.debug("New dossier file: " + newDossierFile.getPath());

                    Document newDossierDocument = reader.read(newDossierFile);

                    XPath dossierXPath = factory.createXPath("/dossier/articles");
                    List articlesElements = dossierXPath.selectNodes(newDossierDocument);
                    Element articlesElement = null;

                    if (articlesElements.size() > 0) {
                        articlesElement = (Element) articlesElements.get(0);
                        log.debug("\n--------------------------" + "\n- Parent element: " +
                            articlesElement.getName() + "\n--------------------------");
                    } else {
                        log.error("\n--------------------------" + "\n- Parent node not found!" +
                            "\n--------------------------");
                    }

                    Element articleElement = factory.createElement("article");
                    articleElement.add(factory.createAttribute(articleElement, "channel",
                            articleChannel));
                    articleElement.add(factory.createAttribute(articleElement, "section",
                            articleSection));
                    articleElement.add(factory.createAttribute(articleElement, "year", articleYear));
                    articleElement.add(factory.createAttribute(articleElement, "id",
                            articleDirectory));
                    articlesElement.add(articleElement);

                    writeDocument(newDossierPath, newDossierDocument);
                }
View Full Code Here

            Document dossierDocument = new SAXReader().read(dossierFile);

            String headlinePath = "/dossier" + "/head" + "/title";

            DocumentFactory factory = DocumentFactory.getInstance();
            XPath headlineXPath = factory.createXPath(headlinePath);
            List nodes = headlineXPath.selectNodes(dossierDocument, headlineXPath);
            Element headlineElement = (Element) nodes.get(0);
            String title = headlineElement.getText();

            String dossiersFilename = publicationPath + authoringPath + "/frontpage/dossier.xml";
View Full Code Here

        Document articleDocument = new SAXReader().read(articleFile);

        String headlinePath = "/NewsML" + "/NewsItem" + "/NewsComponent" + "/ContentItem" +
            "/DataContent" + "/nitf" + "/body" + "/body.head" + "/hedline" + "/hl1";

        DocumentFactory factory = DocumentFactory.getInstance();
        XPath headlineXPath = factory.createXPath(headlinePath);
        List nodes = headlineXPath.selectNodes(articleDocument, headlineXPath);
        Element headlineElement = (Element) nodes.get(0);
        String title = headlineElement.getText();

        //article's  channel, section, year, id. FIXME: should be readen from the article, but now:
View Full Code Here

    public void setup() throws Exception {
        templateResources = applicationContext.getResources(TEMPLATE_LOCATION);

        Map<String,String> nsPrefixes = new HashMap<String,String>();
        nsPrefixes.put("dlm", FragmentDefinition.NAMESPACE_URI);
        DocumentFactory factory = new DocumentFactory();
        factory.setXPathNamespaceURIs(nsPrefixes);
        reader.setDocumentFactory(factory);

        DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
        fac.setNamespaceAware(true);
        domImpl = fac.newDocumentBuilder().getDOMImplementation();
View Full Code Here

        assertEquals(byte[].class, testSubject.targetType());
    }

    @Test
    public void testConvert() throws Exception {
        DocumentFactory df = DocumentFactory.getInstance();
        Document doc = df.createDocument("UTF-8");
        doc.setRootElement(df.createElement("rootElement"));

        SimpleSerializedObject<Document> original = new SimpleSerializedObject<Document>(doc,
                                                                                         Document.class,
                                                                                         serializedType);
        SerializedObject<byte[]> actual = testSubject.convert(original);
View Full Code Here

TOP

Related Classes of org.dom4j.DocumentFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.