Package org.dom4j

Examples of org.dom4j.Node


    private org.apache.lucene.document.Document processAdd(final Element e) throws IllegalDocumentException {
        // TODO: This method is too long, refactor.
        logger.debug("Processing Add");

    float documentBoost;
    Node node = e.selectSingleNode("boost");
    if (null == node) {
      documentBoost = 1.0F;
    } else {
      documentBoost = Float.parseFloat(node.getText());
            if ( logger.isEnabledFor(Level.DEBUG)) {
                logger.debug("Using non-default document boost of " + documentBoost);
            }
    }
        if (Float.isNaN(documentBoost) || Float.isInfinite(documentBoost) || documentBoost <= 0) {
            throw new IllegalDocumentException("Document with invalid boost (" + documentBoost + ") received.");
        }

        org.apache.lucene.document.Document ldoc = new org.apache.lucene.document.Document();
        ldoc.setBoost(documentBoost);
   
    // For comparison with the required fields we keep track of the added
    // fields.
    HashSet<String> providedFields = new HashSet<String>();

    //First, we add the documentId as a field under the name provided in the configuration (docIdName)
        node = e.selectSingleNode("documentId");
    if (null == node) {
      throw new IllegalDocumentException("Add document missing documentId.");
    }
    String docIdText = node.getText();
    //now we add the documentId as another field, using the name provided in the configuration (docIdName)
    Field lfield = new Field(docIdName, docIdText, Field.Store.YES, Field.Index.NOT_ANALYZED);
    ldoc.add(lfield);
    providedFields.add(docIdName);
        if ( logger.isEnabledFor(Level.DEBUG)) {
View Full Code Here


     * Parses a tag to produce a field.
     * @param doc the doc to modify
     * @throw exception on error, signaling the main method to return no document.
     */
    private void processTag(Document doc, final String tagName, final String fieldName) throws Exception {
        Node bodyElement = doc.selectSingleNode("/*/" + tagName);
        if (null == bodyElement) {
            logger.warn("Content element missing from document. I was expecting a '"+tagName+"'. Will not add '"+fieldName+"' field.");
            return;
        }

        Node destElement = doc.selectSingleNode("//field[@name='"+fieldName+"']");       
        if (null != destElement) {
            logger.warn("Parsed element '"+fieldName+"' already present in document. Will not overwrite.");
            return;
        }

View Full Code Here

     */
    protected Document[] internalProcess(final Document doc) {

        // check that this is a documentAdd
        // otherwise, skip.
        Node root = doc.getRootElement();
        if (!root.getName().equals("documentAdd")) return new Document[]{doc};

      
        for (String longField: longFields) {
            Node node = doc.selectSingleNode("//field[@name='"+longField+"']");
            if (null == node) {
                logger.error("Document lacks field " + longField +". Dropping document. ");
                if ( logger.isDebugEnabled()){
                    logger.debug(DomUtil.domToString(doc) + " lacks field " + longField);
                }
                return new Document[0];
            }

            String text = node.getText();
            try {
                Long.parseLong(text);
            } catch (NumberFormatException e) {
                logger.error("Document has field " + longField + ", but it is not parseable as Long. Dropping document");
                if ( logger.isDebugEnabled()){
                    logger.debug(DomUtil.domToString(doc) + " contains field " + longField + " but it is not parseable as Long. Node:" + node.toString() + " - text: " + text);
                }
                return new Document[0];
            }
        }

View Full Code Here

     * @param responseNode Element returned from REST service. (@see #getUserByUsername)
     * @return Either a LockOutFlag indicating that the user is disabled, or null if everything is fine.
     */
    private LockOutFlag checkUserDisabled(Node responseNode) {
        try {
            Node userNode = responseNode.selectSingleNode("return");

            // Gets the username
            String username = userNode.selectSingleNode("username").getText();
            // Escape the username so that it can be used as a JID.
            username = JID.escapeNode(username);

            // Gets the enabled field
            boolean isEnabled = Boolean.valueOf(userNode.selectSingleNode("enabled").getText());
            if (isEnabled) {
                // We're good, indicate that they're not locked out.
                return null;
            }
            else {
View Full Code Here

     * @param responseNode the XML representation of a CS group.
     * @return the group that corresponds to the XML.
     */
    private Group translateGroup(Element responseNode) {

        Node groupNode = responseNode.selectSingleNode("return");

        // Gets the CS DISPLAY NAME that is OF NAME
        String name = groupNode.selectSingleNode("displayName").getText();

        // Gets the CS NAME that is OF DISPLAY NAME
        String displayName = groupNode.selectSingleNode("name").getText();

        // Gets the group ID
        long id = Long.parseLong(groupNode.selectSingleNode("ID").getText());

        // Gets the group type
        int type = Integer.parseInt(groupNode.selectSingleNode("typeID").getText());

        // Gets the group description if it exist
        String description = null;
        Node tmpNode = groupNode.selectSingleNode("description");
        if (tmpNode != null) {
            description = tmpNode.getText();
        }

        // Get the members and administrators
        Collection<JID> members = new ArrayList<JID>();
        Collection<JID> administrators = new ArrayList<JID>();
View Full Code Here

     *
     * @param response the response from CS to check if it is an exception message.
     * @throws Exception if the response is an exception message.
     */
    private void checkFault(Element response) throws Exception {
        Node node = response.selectSingleNode("ns1:faultstring");
        if (node != null) {
            String exceptionText = node.getText();

            // Text accepted samples:
            // 'java.lang.Exception: Exception message'
            // 'java.lang.Exception'

View Full Code Here

        for (String value : values) {
            Element childElement = element.addElement(childName);
            if (value.startsWith("<![CDATA[")) {
                Iterator it = childElement.nodeIterator();
                while (it.hasNext()) {
                    Node node = (Node) it.next();
                    if (node instanceof CDATA) {
                        childElement.remove(node);
                        break;
                    }
                }
View Full Code Here

        }
        // Set the value of the property in this node.
        if (value.startsWith("<![CDATA[")) {
            Iterator it = element.nodeIterator();
            while (it.hasNext()) {
                Node node = (Node) it.next();
                if (node instanceof CDATA) {
                    element.remove(node);
                    break;
                }
            }
View Full Code Here

    @SuppressWarnings("unchecked")
    public void loadJobNode(Node arg0) throws LoadJobException {
        try {
            List fileList = arg0.selectNodes("filelist/file");
            for (int i = 0; fileList != null && i < fileList.size(); i++) {
                Node fileNode = (Node) fileList.get(i);
                if (fileNode != null) {
                    Node fileName = (Node) fileNode.selectSingleNode("@name");
                    if (fileName != null && fileName.getText().length() > 0) {
                        Node filePwd = (Node) fileNode.selectSingleNode("@password");
                        selectionPanel.getLoader().addFile(new File(fileName.getText()),
                                (filePwd != null) ? filePwd.getText() : null);
                    }
                }
            }
            Node rotationNode = (Node) arg0.selectSingleNode("rotation/@value");
            if (rotationNode != null) {
                rotationBox.setSelectedItem((String) rotationNode.getText());
            }

            Node rotationPageNode = (Node) arg0.selectSingleNode("pages/@value");
            if (rotationPageNode != null) {
                for (int i = 0; i < rotationPagesBox.getItemCount(); i++) {
                    if (((StringItem) rotationPagesBox.getItemAt(i)).getId().equals(rotationPageNode.getText())) {
                        rotationPagesBox.setSelectedIndex(i);
                        break;
                    }
                }
            }

            Node fileDestination = (Node) arg0.selectSingleNode("destination/@value");
            if (fileDestination != null) {
                destinationTextField.setText(fileDestination.getText());
            }

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

            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) {
                outPrefixTextField.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

        String name = null;
        String email = null;
        Date creationDate = null;
        Date modificationDate = null;

        Node userNode = responseNode.selectSingleNode("return");
        Node tmpNode;

        // Gets the username
        username = userNode.selectSingleNode("username").getText();
        // Escape the username so that it can be used as a JID.
        username = JID.escapeNode(username);

        // Gets the name if it is visible
        boolean nameVisible = Boolean.valueOf(userNode.selectSingleNode("nameVisible").getText());

        // Gets the name
        tmpNode = userNode.selectSingleNode("name");
        if (tmpNode != null) {
            name = tmpNode.getText();
        }

        // Gets the email if it is visible
        boolean emailVisible = Boolean.valueOf(userNode.selectSingleNode("emailVisible").getText());

        // Gets the email
        tmpNode = userNode.selectSingleNode("email");
        if (tmpNode != null) {
            email = tmpNode.getText();
        }

        // Gets the creation date
        tmpNode = userNode.selectSingleNode("creationDate");
        if (tmpNode != null) {
            creationDate = WSUtils.parseDate(tmpNode.getText());
        }

        // Gets the modification date
        tmpNode = userNode.selectSingleNode("modificationDate");
        if (tmpNode != null) {
            modificationDate = WSUtils.parseDate(tmpNode.getText());
        }

        // Creates the user
        User user = new User(username, name, email, creationDate, modificationDate);
        user.setNameVisible(nameVisible);
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.