Example usage for org.jdom2 Element getTextTrim

List of usage examples for org.jdom2 Element getTextTrim

Introduction

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

Prototype

public String getTextTrim() 

Source Link

Document

Returns the textual content of this element with all surrounding whitespace removed.

Usage

From source file:org.jahia.utils.osgi.parsers.TldXmlFileParser.java

License:Open Source License

public static String getTaglibUri(Element tldRootElement) throws JDOMException {
    boolean hasDefaultNamespace = !StringUtils.isEmpty(tldRootElement.getNamespaceURI());

    Element uriElement = null;
    if (hasDefaultNamespace) {
        uriElement = getElement(tldRootElement, "/xp:taglib/xp:uri");
    } else {/*from w w w .  j  av  a  2  s. c o m*/
        uriElement = getElement(tldRootElement, "/taglib/uri");
    }
    return uriElement != null ? uriElement.getTextTrim() : null;
}

From source file:org.jahia.utils.osgi.parsers.TldXmlFileParser.java

License:Open Source License

@Override
public void parse(String fileName, Element rootElement, String fileParent, boolean externalDependency,
        boolean optionalDependency, String version, ParsingContext parsingContext) throws JDOMException {
    dumpElementNamespaces(rootElement);/*from  ww w . j  a  va  2 s. co m*/
    boolean hasDefaultNamespace = !StringUtils.isEmpty(rootElement.getNamespaceURI());
    if (hasDefaultNamespace) {
        getLogger().debug("Using default namespace XPath queries");
    }

    String uri = getTaglibUri(rootElement);
    if (uri == null) {
        getLogger().warn("Couldn't find /taglib/uri tag in " + fileParent + " / " + fileName
                + ", aborting TLD parsing !");
        return;
    }
    getLogger().debug("Taglib URI=" + uri);
    Set<PackageInfo> taglibPackageSet = parsingContext.getTaglibPackages().get(uri);
    if (taglibPackageSet == null) {
        taglibPackageSet = new TreeSet<PackageInfo>();
    }

    List<Element> tagClassElements = new LinkedList<Element>();
    tagClassElements.addAll(
            getElements(rootElement, hasDefaultNamespace ? "//xp:tag/xp:tag-class" : "//tag/tag-class"));
    tagClassElements.addAll(
            getElements(rootElement, hasDefaultNamespace ? "//xp:tag/xp:tei-class" : "//tag/tei-class"));
    tagClassElements.addAll(getElements(rootElement,
            hasDefaultNamespace ? "//xp:tag/xp:attribute/xp:type" : "//tag/attribute/type"));
    tagClassElements
            .addAll(getElements(rootElement, hasDefaultNamespace ? "//xp:tag/xp:tagclass" : "//tag/tagclass"));
    tagClassElements
            .addAll(getElements(rootElement, hasDefaultNamespace ? "//xp:tag/xp:teiclass" : "//tag/teiclass"));
    for (Element tagClassElement : tagClassElements) {
        getLogger().debug(fileName + " Found tag class " + tagClassElement.getTextTrim() + " package="
                + PackageUtils.getPackagesFromClass(tagClassElement.getTextTrim(), optionalDependency, version,
                        fileParent + "/" + fileName, parsingContext).toString());
        taglibPackageSet.addAll(PackageUtils.getPackagesFromClass(tagClassElement.getTextTrim(),
                optionalDependency, version, fileParent + "/" + fileName, parsingContext));
    }

    // Parsing function class
    List<Element> functionClassElements = null;
    if (hasDefaultNamespace) {
        functionClassElements = getElements(rootElement, "//xp:function/xp:function-class");
    } else {
        functionClassElements = getElements(rootElement, "//function/function-class");
    }
    for (Element functionClassElement : functionClassElements) {
        getLogger()
                .debug(fileName + " Found function class " + functionClassElement.getTextTrim() + " package="
                        + PackageUtils.getPackagesFromClass(functionClassElement.getTextTrim(),
                                optionalDependency, version, fileParent + "/" + fileName, parsingContext)
                                .toString());
        taglibPackageSet.addAll(PackageUtils.getPackagesFromClass(functionClassElement.getTextTrim(),
                optionalDependency, version, fileParent + "/" + fileName, parsingContext));
    }

    // Parsing function signature
    for (Element functionSignatureElement : getElements(rootElement,
            hasDefaultNamespace ? "//xp:function/xp:function-signature" : "//function/function-signature")) {
        List<PackageInfo> pkgs = getPackagesFromFunctionSignature(functionSignatureElement.getTextTrim(),
                fileParent + "/" + fileName, optionalDependency, version, parsingContext);
        if (pkgs != null && !pkgs.isEmpty()) {
            getLogger().debug(
                    fileName + " Found packages in function signature " + functionSignatureElement.getTextTrim()
                            + " packages=[" + StringUtils.join(pkgs, ", ") + "]");
            taglibPackageSet.addAll(pkgs);
        }
    }

    // Parsing a special "hint" in comments
    for (Object comment : selectNodes(rootElement, "//comment()")) {
        if (comment instanceof Comment) {
            String text = ((Comment) comment).getText();
            List<PackageInfo> pkgs = getPackagesFromTagFileComment(text, fileParent + "/" + fileName,
                    parsingContext);
            if (pkgs != null && !pkgs.isEmpty()) {
                getLogger().debug(fileName + " Found import packages hint in comment " + text + " packages=["
                        + StringUtils.join(pkgs, ", ") + "]");
                taglibPackageSet.addAll(pkgs);
            }
        }
    }

    // Parse tag files
    for (Element tagFilePathElement : getElements(rootElement,
            hasDefaultNamespace ? "//xp:tag-file/xp:path" : "//tag-file/path")) {
        String tagFilePath = tagFilePathElement.getTextTrim();
        if (tagFilePath.startsWith("/")) {
            tagFilePath = tagFilePath.substring(1);
        }
        getLogger().debug("Adding tag file to be parsed later in the process: " + tagFilePath);
        parsingContext.addAdditionalFileToParse(tagFilePath);
    }

    Set<PackageInfo> effectivePackages = new TreeSet<PackageInfo>(taglibPackageSet);
    for (PackageInfo pkg : taglibPackageSet) {
        if (knownTransitiveImportPackages.containsKey(pkg.getName())) {
            effectivePackages.addAll(knownTransitiveImportPackages.get(pkg.getName()));
        }
    }

    parsingContext.putTaglibPackages(uri, effectivePackages);
    parsingContext.putExternalTaglib(uri, externalDependency);
}

From source file:org.jpos.q2.QFactory.java

License:Open Source License

public void getExtraPath(QClassLoader loader, Element e) {
    Element classpathElement = e.getChild("classpath");
    if (classpathElement != null) {
        try {// ww  w.j a va  2 s.co m
            loader = loader.scan(true); // force a new classloader
        } catch (Throwable t) {
            getQ2().getLog().error(t);
        }
        for (Object o : classpathElement.getChildren("url")) {
            Element u = (Element) o;
            try {
                loader.addURL(u.getTextTrim());
            } catch (MalformedURLException ex) {
                q2.getLog().warn(u.getTextTrim(), ex);
            }
        }
    }
}

From source file:org.jpos.qi.system.CommandRunner.java

License:Open Source License

@Override
public void setConfiguration(Element e) throws ConfigurationException {
    Element ce = e.getChild("command");
    if (ce != null)
        command = ce.getTextTrim();

    if (command != null) {
        String viewStyle = e.getAttributeValue("viewStyle");
        String objectStyle = e.getAttributeValue("commandStyle");
        boolean clearScreen = "true".equalsIgnoreCase(e.getAttributeValue("clearScreen"));
        repeat = getRepeat(e);/*  w  w  w . j  av a  2s .  c om*/
        label = clearScreen ? new Label() : new XLabel();
        label.setContentMode(ContentMode.PREFORMATTED);
        if (viewStyle != null)
            addStyleName(viewStyle);
        if (objectStyle != null)
            label.addStyleName(objectStyle);
        addComponent(label);
    }
}

From source file:org.jpos.qi.system.SQLQueryObject.java

License:Open Source License

@Override
public void setConfiguration(Element cfg) throws ConfigurationException {
    List<Element> qs = cfg.getChildren("query");
    int count = qs.toArray().length;
    if (count == 0)
        throw new ConfigurationException("no queries defined");
    queries = new String[count];
    titles = new String[count];
    maxRows = new int[count];
    int i = 0;//w w  w .j a  v a 2  s  .com
    for (Element q : qs) {
        maxRows[i] = Integer.parseInt(q.getAttributeValue("maxRows", "10"));
        titles[i] = q.getAttributeValue("title", "query");
        queries[i] = q.getTextTrim();
        i++;
    }
}

From source file:org.jpos.transaction.participant.BSHMethod.java

License:Open Source License

/** Creates a BSHMethod from a JDom Element.
 *
 *  The element is not requiered to have a specific name. 
 *  //from ww w . j  a v  a  2s  . c  o m
 *  If the given element defines an attribute named 'file' the file 
 *  specified as its value will be sourced by the created BSHMethod.
 *
 *  If the 'file' attribute is specified, a 'cache'
 *  attribute may be specified as well which can take the values true|false
 *  and indicates wether to load the script to memory or to read from the 
 *  file for every script evaluation.
 *
 *  If the 'file' attibute is not specified then the text contained by the 
 *  element is set to be evaluated by the new BSHMethod. 
 *  <pre>
 *  Example 1 : 
 *          &lt;prepare>
 *                  import org.jpos.iso.*;
 *        import org.jpos.transaction.*;
 *
 *         msg = context.get("txnRequest");
 *         BaseChannel.getChannel("loop-channel").send(msg);
 *         result=TransactionConstants.PREPARED | TransactionConstants.READONLY;
 *      &lt;/prepare>
 *
 *  Example 2 :
 *          &lt;routing file='cfg\files\routing1.bsh' cache='false'/>
 *  </pre>
 */
public static BSHMethod createBshMethod(Element e) throws IOException {
    if (e == null) {
        return null;
    }
    String file = e.getAttributeValue("file");
    String bsh;
    if (file != null) {
        boolean cache = false;
        String cacheAtt = e.getAttributeValue("cache");
        if (cacheAtt != null) {
            cache = cacheAtt.equalsIgnoreCase("true");
        }
        if (!cache) {
            return new BSHMethod(file, true);
        } else {
            bsh = "";
            FileReader f = new FileReader(file);
            int c;
            while ((c = f.read()) != -1) {
                bsh += (char) c;
            }
            f.close();
            return new BSHMethod(bsh, false);
        }
    } else {
        bsh = e.getTextTrim();
        if (bsh == null || bsh.equals("")) {
            return null;
        }
        return new BSHMethod(bsh, false);
    }
}

From source file:org.jpos.transaction.participant.SelectDestination.java

License:Open Source License

/**
 * @param xml Configuration element/* ww w . j a  v a  2s. com*/
 * @throws ConfigurationException
 *
 *
 * SelectDestination expects an XML configuration in the following format:
 *
 * <endpoint destination="XXX">
 *   4000000..499999
 *   4550000..455999
 *   5
 * </endpoint>
 *
 */
public void setConfiguration(Element xml) throws ConfigurationException {
    for (Element ep : xml.getChildren("endpoint")) {
        String destination = QFactory.getAttributeValue(ep, "destination");
        StringTokenizer st = new StringTokenizer(ep.getText());
        while (st.hasMoreElements()) {
            BinRange br = new BinRange(destination, st.nextToken());
            binranges.add(br);
        }
    }
    for (Element re : xml.getChildren("regexp")) {
        String destination = QFactory.getAttributeValue(re, "destination");
        regexps.add(new PanRegExp(QFactory.getAttributeValue(re, "destination"), re.getTextTrim()));
    }
    LogEvent evt = Log.getLog(Q2.LOGGER_NAME, this.getClass().getName()).createLogEvent("config");
    for (PanRegExp r : regexps)
        evt.addMessage("00:" + r);
    for (BinRange r : binranges)
        evt.addMessage(r);
    Logger.log(evt);
}

From source file:org.jpos.ui.factory.JTreeFactory.java

License:Open Source License

public JComponent create(UI ui, Element e) {
    final UI parentUI = ui;
    final Map map = new HashMap();
    final JTree tree = new JTree(getNode(e, map));
    String font = e.getAttributeValue("font");
    if (font != null)
        tree.setFont(Font.decode(font));
    tree.setRootVisible(e.getTextTrim().length() > 0);

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node != null) {
                String s = (String) map.get(node);
                if (s != null) {
                    StringTokenizer st = new StringTokenizer(s);
                    String action = st.nextToken();
                    String command = null;
                    if (st.hasMoreTokens())
                        command = st.nextToken();

                    ActionListener al = (ActionListener) parentUI.get(action);
                    if (al != null) {
                        al.actionPerformed(new ActionEvent(node, 0, command));
                    }/*from  ww  w. j  ava 2 s  .  c o  m*/
                    // System.out.println ("ACTION: " + action);
                    // System.out.println ("COMMAND: " + command);
                }
            }
        }
    });
    return tree;
}

From source file:org.jpos.ui.factory.JTreeFactory.java

License:Open Source License

private DefaultMutableTreeNode getNode(Element e, Map map) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(e.getTextTrim());
    String action = e.getAttributeValue("action");
    if (action != null) {
        String command = e.getAttributeValue("command");
        if (command != null)
            action = action + " " + command;

        map.put(node, action);/*www.  ja v a 2  s .  c o  m*/
    }
    Iterator iter = e.getChildren().iterator();
    while (iter.hasNext()) {
        node.add(getNode((Element) iter.next(), map));
    }
    return node;
}

From source file:org.jreserve.gui.calculations.api.AbstractCalculationProvider.java

License:Open Source License

protected <T> T lookupSource(Class<T> clazz, Element root, String sourceTag) throws IOException {
    if (project == null)
        return null;

    Element dse = JDomUtil.getExistingChild(root, sourceTag);

    String sPath = dse.getTextTrim();
    if (sPath == null || sPath.length() == 0)
        return null;

    ProjectContentProvider pol = project.getLookup().lookup(ProjectContentProvider.class);
    if (pol == null)
        return null;

    return pol.getContent(sPath, clazz);
}