Example usage for org.dom4j Element getTextTrim

List of usage examples for org.dom4j Element getTextTrim

Introduction

In this page you can find the example usage for org.dom4j Element getTextTrim.

Prototype

String getTextTrim();

Source Link

Document

DOCUMENT ME!

Usage

From source file:fr.gouv.culture.vitam.database.utils.swing.Dom4jTreeBuilder.java

License:Open Source License

public void addElement(Element curnode) {
    DefaultMutableTreeNode previousNode = currentNode;
    for (@SuppressWarnings("unchecked")
    Iterator<Element> it = curnode.elementIterator(); it.hasNext();) {
        Element elt = it.next();
        DefaultMutableTreeNode node = null;
        if (elt.getTextTrim().length() == 0) {
            node = new DefaultMutableTreeNode(elt.getName());
            previousNode.add(node);//from  ww  w  .  ja va 2 s .co  m
        } else {
            node = new DefaultMutableTreeNode(elt.getName());
            DefaultMutableTreeNode subnode = new DefaultMutableTreeNode("T=" + elt.getText());
            node.add(subnode);
            previousNode.add(node);
        }
        currentNode = node;
        addAttribute(elt);
        addElement(elt);
    }
    currentNode = previousNode;
}

From source file:gestionecassa.XmlPreferencesHandler.java

License:Open Source License

/**
 * Loads options from a file//  w w w  . j a  va  2s .  co m
 * @param preferences
 * @throws IOException
 * @throws DocumentException
 */
public void loadPrefs(DataType preferences) throws IOException, DocumentException {

    SAXReader reader = new SAXReader();
    Document document = reader.read(preferences.getFileName());

    Element nodoRoot = document.getRootElement();
    if (!nodoRoot.attributeValue("version").equals(preferences.getVersion())) {
        throw new IOException("Wrong file version!");
    } else if (!nodoRoot.attributeValue("application").equals(preferences.getApplication())) {
        throw new IOException("This config file is for another client");
    }

    for (Field field : preferences.getClass().getFields()) {
        Element node = nodoRoot.element(field.getName());
        try {
            if (node != null) {
                assignField(preferences, field, node.getTextTrim());
            } else {
                System.out.println(
                        "errore campo: " + field.getName() + "\nThis config file does not contain right info");
                assignField(preferences, field, "");
            }
        } catch (IllegalArgumentException ex) {
            logger.warn("campo sbagliato", ex);
        } catch (IllegalAccessException ex) {
            logger.warn("campo sbagliato", ex);
        }
    }
}

From source file:gr.abiss.calipso.domain.Field.java

License:Open Source License

public void addOption(Element e) {
    String value = e.attributeValue(VALUE);
    if (value == null) {
        return;//w  ww. ja  v  a2  s . c o m
    }
    String text = e.getTextTrim();
    if (text == null || text.equals("")) {
        return;
    }
    addOption(value, text);
}

From source file:hudson.plugins.robot.model.RobotCaseResult.java

License:Apache License

private void parseStatus(Element testCase) {

    Element status = testCase.element("status");
    passed = status.attributeValue("status").equalsIgnoreCase("pass");

    if (!passed) {
        errorMsg = status.getTextTrim();
    }/*from   w  w  w.  j  ava 2  s.co  m*/

    String start = status.attributeValue("starttime");
    String end = status.attributeValue("endtime");
    duration = timeDifference(start, end);
}

From source file:hvv_constructor.FrmMainWindow.java

private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed
    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new MyXMLFilter());

    fc.setCurrentDirectory(new File(theApp.GetAMSRoot() + "/ReadyPrograms"));

    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        //This is where a real application would open the file.
        logger.info("LoadProgram opening: " + file.getName());

        TreeMap newProgram = new TreeMap();
        boolean bResOk = true;
        try {/* w  w  w .  java 2  s  .  c o  m*/
            SAXReader reader = new SAXReader();
            URL url = file.toURI().toURL();
            Document document = reader.read(url);
            Element program = document.getRootElement();
            if (program.getName().equals("Program")) {
                // iterate through child elements of root
                for (Iterator i = program.elementIterator(); i.hasNext();) {
                    Element element = (Element) i.next();
                    String name = element.getName();
                    String strLineNumber = element.getTextTrim();
                    int nLineNumber = Integer.parseInt(strLineNumber);

                    JProgAStatement statement = JProgAStatement.parse(element);
                    if (statement != null)
                        newProgram.put(nLineNumber, statement);

                    logger.debug("Pairs: [" + name + " : " + strLineNumber + "]");
                }

                theApp.m_program = newProgram;
                ShowProgram();
            } else
                logger.error("There is no 'program' root-tag in pointed XML");

        } catch (MalformedURLException ex) {
            logger.error("MalformedURLException caught while loading settings!", ex);
            bResOk = false;
        } catch (DocumentException ex) {
            logger.error("DocumentException caught while loading settings!", ex);
            bResOk = false;
        }

    } else {
        logger.info("LoadProgram cancelled.");
    }
}

From source file:hvv_executor.comm.admin.from.HVV_Comm_srv_A2E.java

@Override
public void processIncomingCommand(String strReqId, LinkedList lstIncomingParcel) throws Exception {
    String strCmd;/*from www.  j ava  2s  . c o m*/

    int nRetCode = 0;

    strCmd = (String) lstIncomingParcel.get(0);
    if (strCmd != null) {
        switch (strCmd) {

        case "START_PROGRAM":
            String strProgramToLoad = (String) lstIncomingParcel.get(1);

            logger.debug("INCOMING: [" + strReqId + ";START_PROGRAM;" + strProgramToLoad + "]");

            File file = new File(theApp.GetAMSRoot() + "/ReadyPrograms/AdminSteps/" + strProgramToLoad);

            //This is where a real application would open the file.
            logger.info("LoadProgram opening: " + file.getName());
            theApp.m_strCurrentProgram = file.getName();

            TreeMap newProgram = new TreeMap();
            boolean bResOk = true;
            try {
                SAXReader reader = new SAXReader();
                URL url = file.toURI().toURL();
                Document document = reader.read(url);
                Element program = document.getRootElement();
                if (program.getName().equals("Program")) {
                    // iterate through child elements of root
                    for (Iterator i = program.elementIterator(); i.hasNext();) {
                        Element element = (Element) i.next();
                        String name = element.getName();
                        String strLineNumber = element.getTextTrim();
                        int nLineNumber = Integer.parseInt(strLineNumber);
                        JProgAStatement statement = JProgAStatement.parse(element);
                        if (statement != null)
                            newProgram.put(nLineNumber, statement);

                        logger.debug("Pairs: [" + name + " : " + strLineNumber + "]");
                    }

                    theApp.m_program = newProgram;
                    theApp.m_pMainWnd.ShowProgram();
                } else
                    logger.error("There is no 'program' root-tag in pointed XML");

            } catch (MalformedURLException ex) {
                logger.error("MalformedURLException caught while loading settings!", ex);
                bResOk = false;
            } catch (DocumentException ex) {
                logger.error("DocumentException caught while loading settings!", ex);
                bResOk = false;
            }

            theApp.m_pMainWnd.btnStart.setEnabled(false);
            logger.info("Starting Exec program");
            new Thread(theApp.m_MainExeThread).start();
            theApp.m_nRunningState = HVV_Executor.RUNNING_STATE_RUN;
            theApp.SetExProgramStartDateAsCurrent();

            nRetCode = 0;
            break;

        case "PING":
            logger.debug("INCOMING: [" + strReqId + ";PING;" + "]");
            nRetCode = 0;

            if (m_nStopRequested == 1) {
                nRetCode = 100;
                m_nStopRequested = 2;
            }
            break;

        case "QUIT":
            logger.info("'QUIT' processing");
            SetState(STATE_DISCONNECTED);
            return;

        default:
            logger.error("" + strReqId + ": Unknown command '" + strCmd + "'. RetCode 3");
            nRetCode = 3;
            break;
        }
    } else {
        logger.error("" + strReqId + ": Command is null. RetCode 2");
        nRetCode = 2;
    }

    //RESPOND
    logger.debug("RESPOND [ " + strReqId + ";" + nRetCode + "]");

    GetObjectOutputStream().writeObject(strReqId);
    GetObjectOutputStream().writeInt(1);
    GetObjectOutputStream().writeObject(nRetCode);
    GetObjectOutputStream().flush();
}

From source file:hvv_executor.FrmMainWindow.java

private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed

    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new MyXMLFilter());

    String strCurrentProgram = theApp.GetAMSRoot() + "/ReadyPrograms";
    fc.setCurrentDirectory(new File(strCurrentProgram));

    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        //This is where a real application would open the file.
        logger.info("LoadProgram opening: " + file.getName());
        theApp.m_strCurrentProgram = file.getName();

        TreeMap newProgram = new TreeMap();
        boolean bResOk = true;
        try {//from  ww  w  .  ja va 2  s.c  o  m
            SAXReader reader = new SAXReader();
            URL url = file.toURI().toURL();
            Document document = reader.read(url);
            Element program = document.getRootElement();
            if (program.getName().equals("Program")) {
                // iterate through child elements of root
                for (Iterator i = program.elementIterator(); i.hasNext();) {
                    Element element = (Element) i.next();
                    String name = element.getName();
                    String strLineNumber = element.getTextTrim();
                    int nLineNumber = Integer.parseInt(strLineNumber);
                    JProgAStatement statement = JProgAStatement.parse(element);
                    if (statement != null)
                        newProgram.put(nLineNumber, statement);

                    logger.debug("Pairs: [" + name + " : " + strLineNumber + "]");
                }

                theApp.m_program = newProgram;
                ShowProgram();
            } else
                logger.error("There is no 'program' root-tag in pointed XML");

        } catch (MalformedURLException ex) {
            logger.error("MalformedURLException caught while loading settings!", ex);
            bResOk = false;
        } catch (DocumentException ex) {
            logger.error("DocumentException caught while loading settings!", ex);
            bResOk = false;
        }

    } else {
        logger.info("LoadProgram cancelled.");
    }
}

From source file:itensil.repository.web.ShellServlet.java

License:Open Source License

/**
 *  /setProps//from w w  w .j a  v  a2 s .  co  m
 *
 * Set node properties
 *
 */
@ContentType("text/xml")
public void webSetProps(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Document reqDoc = XMLDocument.readStream(request.getInputStream());
    Element root = reqDoc.getRootElement();
    String uri = root.attributeValue("uri");
    if (!(Check.isEmpty(uri) || uri.length() < 2)) {

        RepositoryHelper.beginTransaction();
        uri = RepositoryHelper.resolveUri(uri);
        MutableRepositoryNode node = getNode(uri);
        String name = UriHelper.name(node.getUri());

        Namespace davNs = root.getNamespaceForURI(PropertyHelper.DEFAULT_QNAMESPACE);

        // check rename
        String reqName = root.elementTextTrim(new org.dom4j.QName("displayname", davNs));
        if (!Check.isEmpty(reqName)) {
            if (!name.equals(reqName)) {
                String parUri = UriHelper.getParent(node.getUri());
                node.move(UriHelper.absoluteUri(parUri, UriHelper.filterName(reqName)));
            }
        }

        Namespace irNs = root.getNamespaceForURI(PropertyHelper.ITENSIL_QNAMESPACE);
        Element desc = root.element(new org.dom4j.QName("description", irNs));
        NodeProperties props = node.getProperties(new DefaultNodeVersion());
        if (props == null) {
            props = new DefaultNodeProperties(new DefaultNodeVersion());
        }
        props.setValue(PropertyHelper.itensilQName("description"), desc != null ? desc.getTextTrim() : "");
        node.setProperties(props);

        RepositoryHelper.commitTransaction();
        response.getWriter().print("<ok/>");

    } else {
        throw new NotFoundException("[blank]");
    }
}

From source file:itensil.workflow.activities.web.ActivityServlet.java

License:Open Source License

/**
 *  /submit/*  www  . j  av  a 2 s  . c o  m*/
 *
 * Submit an Activity for flow routing
 *
 * Request XML:
 *      <submit>
 *          <activity>activity.id</activity>
 *          <step>step.id</step>
 *          <expr>expression</expr>
 *
 *          <!-- maybe this for more wiki inputs? -->
 *          <data name="...">value</data> ...
 *      </submit>
 */
@SuppressWarnings("unchecked")
@ContentType("text/xml")
public void webSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Document doc = XMLDocument.readStream(request.getInputStream());
    Element root = doc.getRootElement();
    if ("submit".equals(root.getName())) {

        User user = (User) request.getUserPrincipal();

        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        UserActivities uActivities = new UserActivities(user, session);

        // resolve the activity
        String activityId = root.elementTextTrim("activity");
        Activity activityEnt = uActivities.getActivity(activityId);
        if (activityEnt == null) {
            throw new NotFoundException(activityId);
        }
        String step = root.elementTextTrim("step");
        if (Check.isEmpty(step)) {
            throw new NotFoundException("[empty step]");
        }

        HashMap<String, String> submitValues = null;
        Element data = root.element("rule-data");
        if (data != null) {
            List<Element> kids = data.elements();
            if (!kids.isEmpty()) {
                submitValues = new HashMap<String, String>();
                for (Element attrElem : kids) {
                    submitValues.put(attrElem.getName(), attrElem.getText());
                }
            }
        }
        Element swPath = root.element("switch-path");
        String resTx;
        if (swPath != null && swPath.hasContent()) {
            resTx = uActivities.exitSwitch(activityEnt, step, swPath.getTextTrim());
        } else {
            resTx = uActivities.submit(activityEnt, step, submitValues, root.elementTextTrim("expr"));
        }

        // return activity's status
        Element actElem = ActivityXML.display(activityEnt);
        actElem.addAttribute("resTx", resTx);

        Document retDoc = DocumentHelper.createDocument(actElem);
        HibernateUtil.commitTransaction();

        retDoc.write(response.getWriter());
    }

}

From source file:job.tot.xml.DOM4JConfiguration.java

License:Apache License

/**
 * Loads and initializes from the XML file.
 *
 * @param element The element to start processing from.  Callers
 * should supply the root element of the document.
 * @param hierarchy/*from w w w.j  a v a  2s  . c  om*/
 */
private void initProperties(Element element, StringBuffer hierarchy) {
    for (Iterator it = element.elementIterator(); it.hasNext();) {
        StringBuffer subhierarchy = new StringBuffer(hierarchy.toString());
        Element child = (Element) it.next();
        String nodeName = child.getName();
        String nodeValue = child.getTextTrim();
        subhierarchy.append(nodeName);
        if (nodeValue.length() > 0) {
            super.addProperty(subhierarchy.toString(), nodeValue);
        }

        // Add attributes as x.y{ATTRIB_START_MARKER}att{ATTRIB_END_MARKER}
        List attributes = child.attributes();
        for (int j = 0, k = attributes.size(); j < k; j++) {
            Attribute a = (Attribute) attributes.get(j);
            String attName = subhierarchy.toString() + '[' + ATTRIB_MARKER + a.getName() + ']';
            String attValue = a.getValue();
            super.addProperty(attName, attValue);
        }
        StringBuffer buf = new StringBuffer(subhierarchy.toString());
        initProperties(child, buf.append('.'));
    }
}