Package org.dom4j

Examples of org.dom4j.Node


                found = true;
            }
        }
        if ( !found )
        {
            Node lastTextNode = null;
            for ( Iterator<?> i = modules.nodeIterator(); i.hasNext(); )
            {
                Node node = (Node) i.next();
                if ( node.getNodeType() == Node.ELEMENT_NODE )
                {
                    lastTextNode = null;
                }
                else if ( node.getNodeType() == Node.TEXT_NODE )
                {
                    lastTextNode = node;
                }
            }
View Full Code Here


                    found = true;
                }
            }
            if ( !found )
            {
                Node lastTextNode = null;
                for ( @SuppressWarnings( "unchecked" )
                Iterator<Node> i = modules.nodeIterator(); i.hasNext(); )
                {
                    Node node = i.next();
                    if ( node.getNodeType() == Node.ELEMENT_NODE )
                    {
                        lastTextNode = null;
                    }
                    else if ( node.getNodeType() == Node.TEXT_NODE )
                    {
                        lastTextNode = node;
                    }
                }
View Full Code Here

    @SuppressWarnings("unchecked")
    public void removeNamespaces( Element elem )
    {
        elem.setQName( QName.get( elem.getName(), Namespace.NO_NAMESPACE, elem.getQualifiedName() ) );

        Node n;

        Iterator<Node> it = elem.elementIterator();
        while ( it.hasNext() )
        {
            n = it.next();

            switch ( n.getNodeType() )
            {
                case Node.ATTRIBUTE_NODE:
                    ( (Attribute) n ).setNamespace( Namespace.NO_NAMESPACE );
                    break;
                case Node.ELEMENT_NODE:
View Full Code Here

        }
    }

    public void loadJobNode(Node arg0) throws LoadJobException {
        try {
            Node fileSource = (Node) arg0.selectSingleNode("source/@value");
            if (fileSource != null && fileSource.getText().length() > 0) {
                Node filePwd = (Node) arg0.selectSingleNode("source/@password");
                String password = null;
                if (filePwd != null && filePwd.getText().length() > 0) {
                    password = filePwd.getText();
                }
                selectionPanel.getLoader().addFile(new File(fileSource.getText()), password);
            }

            Node splitOption = (Node) arg0.selectSingleNode("split_option/@value");
            if (splitOption != null) {
                if (splitOption.getText().equals(burstRadio.getSplitCommand()))
                    burstRadio.doClick();
                else if (splitOption.getText().equals(everyNRadio.getSplitCommand()))
                    everyNRadio.doClick();
                else if (splitOption.getText().equals(evenRadio.getSplitCommand()))
                    evenRadio.doClick();
                else if (splitOption.getText().equals(oddRadio.getSplitCommand()))
                    oddRadio.doClick();
                else if (splitOption.getText().equals(thisPageRadio.getSplitCommand()))
                    thisPageRadio.doClick();
                else if (splitOption.getText().equals(sizeRadio.getSplitCommand()))
                    sizeRadio.doClick();
                else if (splitOption.getText().equals(bookmarksLevel.getSplitCommand()))
                    bookmarksLevel.doClick();
            }
            Node splitNpages = (Node) arg0.selectSingleNode("npages/@value");
            if (splitNpages != null) {
                nPagesTextField.setText(splitNpages.getText());
            }

            Node splitThispage = (Node) arg0.selectSingleNode("thispage/@value");
            if (splitThispage != null) {
                thisPageTextField.setText(splitThispage.getText());
            }

            Node splitSize = (Node) arg0.selectSingleNode("splitsize/@value");
            if (splitSize != null) {
                splitSizeCombo.setSelectedItem(splitSize.getText());
            }

            Node bookLevel = (Node) arg0.selectSingleNode("bookmarkslevel/@value");
            if (bookLevel != null) {
                bLevelCombo.setSelectedItem(bookLevel.getText());
            }

            Node fileDestination = (Node) arg0.selectSingleNode("destination/@value");
            if (fileDestination != null && fileDestination.getText().length() > 0) {
                destinationFolderText.setText(fileDestination.getText());
                chooseAFolderRadio.doClick();
            } else {
                sameAsSourceRadio.doClick();
            }

            Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value");
            if (fileOverwrite != null) {
                overwriteCheckbox.setSelected(TRUE.equals(fileOverwrite.getText()));
            }

            Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value");
            if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) {
                outputCompressedCheck.doClick();
            }

            Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value");
            if (filePrefix != null) {
                outPrefixText.setText(filePrefix.getText());
            }

            Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value");
            if (pdfVersion != null) {
                for (int i = 0; i < versionCombo.getItemCount(); i++) {
                    if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) {
                        versionCombo.setSelectedIndex(i);
                        break;
                    }
                }
            }
View Full Code Here

            // Rather than reparsing these when individual messages are
            // created, lets do it now
            // We can also avoid parsing the Xml again altogether
            for (Iterator iterator = foundNodes.iterator(); iterator.hasNext();)
            {
                Node node = (Node) iterator.next();
                if (node instanceof Element)
                {
                    // Can't do detach here just in case the source object
                    // was a document.
                    node = (Node) node.clone();
                    parts.add(DocumentHelper.createDocument((Element) node));
                }
                else
                {
                    logger.warn("Dcoument node: " + node.asXML()
                            + " is not an element and thus is not a valid part");
                }
            }
            return parts;
        }
View Full Code Here

                Object obj = xpath.evaluate(doc);
                if (obj instanceof List)
                {
                    for (int i = 0; i < ((List) obj).size(); i++)
                    {
                        final Node node = (Node) ((List) obj).get(i);
                        result = add(result, node);
                       
                        if (singleResult)
                        {
                            break;
View Full Code Here

        Document input = new DocumentParser().genDocument("<foo>" +
                "<bar>some text</bar>" +
                "</foo>");
        Document[] output = internalProcess(input);
        assertThat(output.length, is(1));
        Node node = output[0].selectSingleNode("/newFoo/text");
        assertThat(node, notNullValue());
        assertThat(node.getText(), is("some text"));
    }
View Full Code Here

            logger.fatal("got null document after transformation. this should not happen. I can't tell which is the offending document.");
            System.exit(1);
        }

        // check commands
        Node command = doc.selectSingleNode("/command");
        if (null != command) {
            return processCommand(doc);
        }

        // else, it may be a document to index / delete
        // get the documentId.

        Node node = doc.selectSingleNode("//documentId");
        if (null == node) {
            logger.error("Document missing documentId. Will not index it.");
            logger.error("Document was : " + DomUtil.domToString(doc));
            return IndexerReturnCode.FAILURE;
        }


        // get the target indexer.
        // Make sure that urls begin with http://
        String url = node.getText();
        int target = hashFunction.hash(url);

        // send the document to the target indexer.
        try {
            IRemoteIndexer indexer = indexers.get(target);
            logger.debug("Sending " + node.getText() + " to indexer " + target);
            IndexerReturnCode res = indexer.index(doc);
            if (res != IndexerReturnCode.SUCCESS){
                logger.debug("Problem ("+res+") indexing " + node.getText() + " to indexer " + target);
            }
            return res;
        } catch (com.flaptor.util.remote.RpcException e) {
            logger.error("Connection failed: ",e);
            return IndexerReturnCode.FAILURE;
View Full Code Here

    }



    protected IndexerReturnCode processCommand(final Document doc) {
        Node commandNode = doc.selectSingleNode("/command");
        Node attNode = commandNode.selectSingleNode("@node");

        if (null == attNode) { // so it is for all nodes

            for (IRemoteIndexer indexer: indexers) {
                boolean accepted = false;
                int retries = 0;

                // try until accepted, or too much retries.
                while (!accepted && retries < RETRY_LIMIT ) {
                    try {
                        IndexerReturnCode retValue = indexer.index(doc);
                        if (IndexerReturnCode.SUCCESS == retValue) {
                            accepted = true;
                        } else {
                            retries++;
                            Execute.sleep(10*1000); // wait 10 seconds before retry
                        }
                    } catch (com.flaptor.util.remote.RpcException e ) {
                        logger.error("processCommand: Connection failed: " + e.getMessage(),e);
                    }
                }
                // if could not send to indexer
                if (!accepted) {
                    logger.error("processCommand: tried " + RETRY_LIMIT + " times to index command, but failed on node " + indexer.toString() + ". Will not continue with other indexers.");
                    return IndexerReturnCode.FAILURE;

                }
            }
            // in case no one returned Indexer.FAILURE
            return IndexerReturnCode.SUCCESS;
        } else { // specific node

            try {
                int indexerNumber = Integer.parseInt(attNode.getText());
                if (indexerNumber < indexers.size() && indexerNumber >=0) {
                    IRemoteIndexer indexer = indexers.get(indexerNumber);
                    try {
                        return indexer.index(doc);
                    } catch (com.flaptor.util.remote.RpcException e) {
View Full Code Here

  private void processDelete(final Element e) {
        if ( logger.isEnabledFor(Level.DEBUG)) {
            logger.debug("Processing delete");
        }
    Node node = e.selectSingleNode("documentId");
    if (null != node) {
      iwp.deleteDocument(node.getText());
    } else {
      logger.error("documentId node not found. Ignoring deletion.");
    }
  }
View Full Code Here

TOP

Related Classes of org.dom4j.Node

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.