Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.nokia.helium.scm.ant.taskdefs.ChangelogAction.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww w .java  2 s.c  om*/
 */
@SuppressWarnings("unchecked")
@Override
public void execute(ScmRepository repository) throws ScmException {
    ScmManager scmManager = getTask().getScmManager();
    ScmRevision startRevision = new ScmRevision(startVersion);
    ScmRevision endRevision = new ScmRevision(endVersion);

    ChangeLogScmResult result;
    Date start = null;
    Date end = null;

    if (numDays == 0 && (startDate != null || endDate != null)) {
        try {
            SimpleDateFormat format = new SimpleDateFormat(datePattern);
            start = format.parse(startDate);
            end = format.parse(endDate);
        } catch (Exception e) {
            throw new ScmException("Date Format not supported:" + e.getMessage());
        }
    } else {
        start = null;
        end = null;
    }
    try {
        if (startVersion == null)
            result = scmManager.changeLog(repository, getScmFileSet(), start, end, numDays, null, datePattern);
        else
            result = scmManager.changeLog(repository, getScmFileSet(), startRevision, endRevision, datePattern);
    } catch (ScmException e) {
        throw new BuildException("Execution of SCM changelog action failed.");
    }
    if (!result.isSuccess()) {
        throw new BuildException("SCM changelog command unsuccessful.");
    }
    // Output changelog information
    ChangeLogSet changelogSet = result.getChangeLog();
    if (logOutput != null && logOutput.equals("xml")) {
        getTask().log(changelogSet.toXML());
    } else if (xmlbom != null) {
        String output = "";
        for (Object o : changelogSet.getChangeSets()) {
            String revision = "";
            ChangeSet c = (ChangeSet) o;
            for (String x : c.toString().split("\n")) {
                if (x.contains("revision:"))
                    revision = x.replace("revision:", "");
            }

            output = output + "<task><id>" + revision + "</id><synopsis>" + c.getComment()
                    + "</synopsis><completed>"
                    + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(c.getDate()) + "</completed></task>";
        }
        String[] path = getTask().getScmUrl().split("/");
        String xml = "<bom><build>untitled</build><content>\n";
        String thisproject = "<project>" + "<name>" + path[path.length - 1] + "</name>" + "<baseline>"
                + getTask().getScmUrl() + "</baseline>" + "<database>mercurial</database>" + output
                + "</project>\n";
        xml = xml + thisproject;
        try {
            if (xmlbom.exists()) {
                SAXReader xmlReader = new SAXReader();
                Document antDoc = xmlReader.read(xmlbom);
                for (Iterator iterator = antDoc.selectNodes("//project").iterator(); iterator.hasNext();) {
                    boolean equal = false;
                    Element e = (Element) iterator.next();
                    for (Iterator iterator2 = antDoc.selectNodes("//baseline").iterator(); iterator2
                            .hasNext();) {
                        Element e2 = (Element) iterator2.next();
                        if (e2.getText().equals(getTask().getScmUrl()))
                            equal = true;
                    }
                    if (!equal)
                        xml = xml + e.asXML() + "\n";
                }
            }
            xml = xml + "</content></bom>";

            FileWriter fstream = new FileWriter(xmlbom);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(xml);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Iterator iterator = changelogSet.getChangeSets().iterator();
        while (iterator.hasNext()) {
            getTask().log(iterator.next().toString());
        }
    }
}

From source file:com.noterik.bart.fs.action.CollectionIndexAction.java

License:Open Source License

private void loadIndexConfig() {
    if (userConfigMemory == null) {
        userConfigMemory = new HashMap<String, Map<String, String>>();
    }//from ww w  .j a v a  2s.co  m
    if (!userConfigMemory.containsKey(domainid + ":" + userid)) {
        logger.debug("config not yet in memory for " + domainid + " " + userid);
        Map<String, String> propertiesMap = new HashMap<String, String>();

        String configUri = CONFIG_URI.replace("{domainid}", domainid).replace("{user}", userid);
        Document configuration = FSXMLRequestHandler.instance().getNodeProperties(configUri, false);

        if (configuration != null) {
            logger.debug("configuration " + configuration.asXML());

            List<Node> properties = configuration.selectNodes("//properties/*");
            for (Iterator<Node> i = properties.iterator(); i.hasNext();) {
                Element property = (Element) i.next();
                if (property.getName().equals("indextype")) {
                    indexType = property.getText();
                } else if (property.getName().equals("indexuri")) {
                    indexUri = property.getText().replace("{domainid}", domainid).replace("{user}", userid);
                } else if (property.getName().equals("indexsavetype")) {
                    indexSaveType = property.getText();
                } else {
                    propertiesMap.put(property.getName(), "enabled");
                }
            }
        } else {
            logger.debug("get default config variables");
            //default indextype & uri when configuration is not available
            indexType = DEFAULT_INDEX_TYPE;
            indexSaveType = DEFAULT_INDEX_TYPE;
            indexUri = DEFAULT_INDEX_URI.replace("{domainid}", domainid).replace("{user}", userid);
        }
        if (indexSaveType == null) {
            indexSaveType = indexType;
        }
        userConfigMemory.put(domainid + ":" + userid, propertiesMap);
    } else {
        logger.debug("config found in memory for " + domainid + ":" + userid);
    }
}

From source file:com.noterik.bart.fs.action.FlandersAction.java

License:Open Source License

private String processXml(String original, String flanders) {
    String xml = "";

    Map<String, String> values = new HashMap<String, String>();

    Document origdoc = null;//  w  w  w.  j  a  v  a2 s  . co m
    Document flandoc = null;

    try {
        origdoc = DocumentHelper.parseText(original);
        flandoc = DocumentHelper.parseText(flanders);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    Element origProp = (Element) origdoc.selectSingleNode("//properties");
    Iterator i = origProp.elementIterator();

    while (i.hasNext()) {
        Element prop = (Element) i.next();
        String name = prop.getName();
        String value = prop.getText();
        values.put(name, value);
    }

    logger.debug("\n flandProp = " + flandoc.asXML());

    Element flandProp = (Element) flandoc.selectSingleNode("/meta-data");
    Iterator j = flandProp.elementIterator();

    while (j.hasNext()) {
        Element prop = (Element) j.next();
        String name = prop.getName();
        String value = prop.getText();

        //For marin there metadata is leading
        if (values.containsKey("mount") && values.get("mount").toLowerCase().equals("marin")) {
            if (!values.containsKey(name)) {
                values.put(name, value);
            }
        } else {
            values.put(name, value);
        }
    }

    Element finalEl = DocumentHelper.createElement("fsxml");
    Element propsEl = finalEl.addElement("properties");

    Iterator<String> it = values.keySet().iterator();
    while (it.hasNext()) {
        String name = it.next();
        String value = values.get(name);
        propsEl.addElement(name).addText(value);
    }

    xml = finalEl.asXML();

    return xml;
}

From source file:com.noterik.bart.fs.cloudexporter.DiskExporter.java

License:Open Source License

public static void exportSmithersNode(String uri) {
    Document nodeXML = FSXMLRequestHandler.instance().getNodeProperties(uri, false);
    if (nodeXML != null) {
        Element p = (Element) nodeXML.selectSingleNode("/fsxml/nodes/properties/exporturl");
        if (p == null)
            return;
        String exporturl = p.getText();
        if (p != null && !p.getText().equals("")) {
            FSXMLRequestHandler.instance().handlePUT(uri + "/properties/exporturl", "");
            System.out.println("EXPORTING NODES FROM=" + exporturl);
            count = 0;// ww  w  .j av a  2 s. c  o  m
            LazyHomer.send("TRACE", exporturl, "Starting export");
            exportNodes(exporturl, "/springfield/smithers/export" + exporturl);
        }
    } else {
        System.out.println("EXPORT NODE NOT VALID (" + uri + ")");
    }
}

From source file:com.noterik.bart.fs.cloudexporter.DiskExporter.java

License:Open Source License

private static boolean exportNodes(String exporturl, String exportpath) {
    //   if (exporturl.indexOf("/user")!=-1) return true;
    //Skip backing up the indexes
    /*/*from w  w w  .  java2 s.  c  o  m*/
    if (exporturl.indexOf("/collectionindex")!=-1) return true;
    if (exporturl.indexOf("/keywordindex")!=-1) return true;
    if (exporturl.indexOf("/subtitlesindex")!=-1) return true;
    if (exporturl.indexOf("/speakersindex")!=-1) return true;
    if (exporturl.indexOf("/themesindex")!=-1) return true;
    if (exporturl.indexOf("/topicsearch")!=-1) return true;
    */
    System.out.println("(" + (count++) + ") URL=" + exporturl);
    File dirs = new File(exportpath);
    boolean result = dirs.mkdirs();
    if (dirs.exists()) {
        result = true;
    }
    if (!result)
        return false;

    Document exportXML = FSXMLRequestHandler.instance().handleDocGET(exporturl,
            "<properties><depth>0</depth></properties>");
    if (exportXML != null) {

        for (Iterator i = exportXML.nodeIterator(); i.hasNext();) {
            Element fsnode = (Element) i.next();
            if (fsnode.getName().equals("error"))
                return true; // Check if the current node is <error>
            for (Iterator j = fsnode.nodeIterator(); j.hasNext();) {
                Element mnode = (Element) j.next();
                for (Iterator k = mnode.nodeIterator(); k.hasNext();) {
                    Element dnode = (Element) k.next();
                    String name = dnode.getName();
                    String id = dnode.attributeValue("id");
                    //System.out.println("DNAME="+name);
                    if (Arrays.asList(ignorelist).contains(name)) {
                        System.out.println("ignoring " + name);
                    } else if (!name.equals("properties")) {
                        exportNodes(exporturl + "/" + name + "/" + id, exportpath + "/" + name + "/" + id);
                    } else {
                        try {
                            MimeType mimetype = FSXMLRequestHandler.instance().getMimeTypeOfResource(exporturl);
                            BufferedWriter propfile = new BufferedWriter(
                                    new FileWriter(exportpath + "/properties.txt"));
                            String propbody = "<properties>\n";
                            // set the mimetype
                            propbody += "\t<mimetype>";
                            if (mimetype.toString().equals("MIMETYPE_FS_SCRIPT")) {
                                propbody += "application/fsscript";
                            } else if (mimetype.toString().equals("MIMETYPE_FS_COMMAND")) {
                                propbody += "application/fscommand";
                            } else {
                                propbody += "text/fsxml";
                            }
                            propbody += "</mimetype>\n";
                            for (Iterator l = dnode.nodeIterator(); l.hasNext();) {
                                Object p = l.next();
                                if (p instanceof Element) {
                                    Element pnode = (Element) p;
                                    String pname = pnode.getName();
                                    String pvalue = pnode.getText();
                                    propbody += "\t<" + pname + ">" + pvalue + "</" + pname + ">\n";
                                } else if (p instanceof DefaultText) {
                                    DefaultText tnode = (DefaultText) p;
                                    //System.out.println("DEFTEXT="+tnode.toString());
                                    String pname = tnode.getName();
                                    String pvalue = tnode.getText();
                                    //propbody += "\t<"+pname+">"+pvalue+"</"+pname+">\n";   
                                } else if (p instanceof DefaultComment) {
                                    DefaultComment cnode = (DefaultComment) p;
                                    String pname = cnode.getName();
                                    String pvalue = cnode.getText();
                                    //propbody += "\t<!-- <"+pname+">"+pvalue+"</"+pname+"> -->\n";   
                                    //System.out.println("DEFCOMMENT="+cnode.toString());
                                } else {
                                    System.out.println("UNCATCHED TYPE=" + p.toString());
                                }
                            }
                            propbody += "</properties>\n";
                            propfile.write(propbody);
                            propfile.close();
                        } catch (Exception e) {
                            System.out.println("PROP ERROR");
                            e.printStackTrace();
                        }
                    }

                    if (mnode.attributeValue("id") != null && mnode.attributeValue("referid") != null
                            && !name.equals("user")) {
                        try {
                            System.out.println("MNODE2=" + mnode.asXML());
                            BufferedWriter attrfile = new BufferedWriter(
                                    new FileWriter(exportpath + "/attributes.txt"));
                            String attrbody = "<attributes>\n";
                            attrbody += "\t<referid>" + mnode.attributeValue("referid") + "</referid>\n";
                            attrbody += "</attributes>\n";
                            attrfile.write(attrbody);
                            attrfile.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                }
            }
        }

        return true;
    } else {
        System.out.println("EXPORT URL NOT VALID (" + exporturl + ")");
        return false;
    }
}

From source file:com.noterik.bart.fs.cloudimporter.DiskImporter.java

License:Open Source License

public static void importSmithersNode(String uri) {
    Document nodeXML = FSXMLRequestHandler.instance().getNodeProperties(uri, false);
    if (nodeXML != null) {
        Element p = (Element) nodeXML.selectSingleNode("/fsxml/nodes/properties/importurl");
        if (p == null)
            return;
        String importurl = p.getText();
        if (p != null && !p.getText().equals("")) {
            FSXMLRequestHandler.instance().handlePUT(uri + "/properties/importurl", "");
            String l[] = importurl.split(",");
            String target = l[0];
            String source = l[1];
            System.out.println("IMPORTING NODES TO=" + target + " SOURCE=" + source);

            LazyHomer.send("TRACE", importurl, "Starting import");
            String path = "/springfield/smithers/import/" + source;
            if (LazyHomer.isWindows()) {
                path = "c:\\springfield\\smithers\\import\\" + source;
            }/*  w w w  .ja  va2s  .  c  o m*/
            importCloud(path, target);
        }
    } else {
        System.out.println("IMPORT NODE NOT VALID (" + uri + ")");
    }
}

From source file:com.noterik.bart.fs.fscommand.CommandAdapter.java

License:Open Source License

/**
 * Returns the input parameters.//from   w w w. j  ava  2  s .c  om
 * 
 * @param xml   The xml specifying the commands parameters.
 * @return      The input parameters.
 */
public Properties getInputParameters(String xml) {
    Properties props = new Properties();
    Document doc = XMLHelper.asDocument(xml);
    if (doc == null) {
        return null;
    } else {
        Node n = doc.selectSingleNode("./fsxml/properties");
        if (n instanceof Element) {
            Element properties = (Element) n;
            for (Iterator i = properties.elementIterator(); i.hasNext();) {
                Element elem = (Element) i.next();
                props.put(elem.getName(), elem.getText().trim());
            }
        }
    }
    return props;
}

From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.cache.java

License:Open Source License

public static void readCacheConfig() {
    System.out.println("READ CACHENODE");
    Document cachenode = FSXMLRequestHandler.instance()
            .getNodeProperties("/domain/webtv/config/cache/presentationquickstart/1", false);
    System.out.println("CACHENODE=" + cachenode);
    if (cachenode != null) {
        Element activenode = (Element) cachenode
                .selectSingleNode("/fsxml/presentationquickstart[@id='1']/properties/active");
        if (activenode.getText().equals("true")) {
            active = true;//from w ww. ja  va 2 s .c  om
            logger.debug("CACHE TURNED ON");
        } else {
            active = false;
            logger.debug("CACHE TURNED OFF");
        }
        Element debuglevelnode = (Element) cachenode
                .selectSingleNode("/fsxml/presentationquickstart[@id='1']/properties/debuglevel");
        if (debuglevelnode.getText().equals("high")) {
            debuglevel = "high";
            FSXMLRequestHandler.debuglevel = "high";
            logger.debug("CACHE DEBUG LEVEL HIGH");
        } else {
            debuglevel = "off";
            FSXMLRequestHandler.debuglevel = "off";
            logger.debug("CACHE DEBUG LEVEL OFF");
        }
    } else {
        logger.debug("CACHE CONFIG MISSING");
        //DefaultImporter.importDefaultCloud();
    }

}

From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.CacheTableReader.java

License:Open Source License

public void run() {
    if (running) {
        loaded = true;// w ww  .  j a  va 2s.  co m
        return;
    }
    try {
        String hostname = InetAddress.getLocalHost().toString();
        int pos = hostname.indexOf("/");
        if (pos != -1)
            hostname = hostname.substring(pos + 1);
        Document cacheXml = FSXMLRequestHandler.instance()
                .getNodeProperties("/domain/webtv/tmp/cache/dataset/" + hostname, false);
        if (cacheXml != null) {
            System.out.println("Reader cache tables " + cacheXml.asXML());
            Element p = (Element) cacheXml
                    .selectSingleNode("/fsxml/dataset[@id='" + hostname + "']/properties/list");
            if (p != null) {

                String list[] = p.getText().split(",");
                for (int i = 0; i < list.length; i++) {
                    System.out.println("ITEM (" + (i + 1) + ")=" + list[i]);
                    Document result = null;
                    String key = list[i];
                    key = key.replace(";", ",");
                    int cpos = key.indexOf("{");
                    if (cpos == -1) {
                        result = FSXMLRequestHandler.instance().getNodeProperties(list[i], false);
                        cache.put(list[i], result);
                    } else {
                        try {
                            String params = key.substring(cpos + 1);
                            params = params.substring(0, params.length() - 1);
                            //System.out.println("P1="+params);
                            String[] pa = params.split(",");
                            String pb = "<fsxml><properties>";
                            for (int pi = 0; pi < pa.length; pi++) {
                                int ispos = pa[pi].indexOf("=");
                                String name = pa[pi].substring(0, ispos);
                                String value = pa[pi].substring(ispos + 1);
                                if (name.charAt(0) == ' ')
                                    name = name.substring(1);
                                pb += "<" + name + ">" + value + "</" + name + ">";
                            }
                            pb += "</properties></fsxml>";
                            System.out.println("PB=" + pb);
                            result = FSXMLRequestHandler.instance().handleDocGET(key.substring(0, cpos), pb);

                        } catch (Exception ee) {
                            System.out.println("ERROR WE NEED TO LOOK AT DANIEL");
                        }
                        //System.out.println("RSULT="+result);
                        //System.out.println("EEEE="+key.substring(0,cpos)+" R="+key.substring(cpos));

                        if (result != null)
                            cache.putParams(key.substring(0, cpos), result, key.substring(cpos));
                    }
                    sleep(30);
                }
                loaded = true;
            }
            System.out.println("Reader cache tables loaded size=" + cache.getCacheSize());

        } else {
            loaded = true;
            System.out.println("Reader cache tables empty");
        }

    } catch (Exception e) {
        System.out.println("Can't sleep in CacheTableReader " + e);
    }
    loaded = true;
}

From source file:com.noterik.bart.fs.legacy.tools.FlandersHelper.java

License:Open Source License

private static String processXml(String original, String flanders) {
    String xml = "";

    Map<String, String> values = new HashMap<String, String>();

    Document origdoc = null;/*from   ww w  . j a  v a  2  s . c  o m*/
    Document flandoc = null;

    try {
        origdoc = DocumentHelper.parseText(original);
        flandoc = DocumentHelper.parseText(flanders);
    } catch (DocumentException e) {
        LOG.error("", e);
    }

    Element origProp = (Element) origdoc.selectSingleNode("//properties");
    Iterator i = origProp.elementIterator();

    while (i.hasNext()) {
        Element prop = (Element) i.next();
        String name = prop.getName();
        String value = prop.getText();
        values.put(name, value);
    }

    LOG.debug("\n flandProp = " + flandoc.asXML());

    Element flandProp = (Element) flandoc.selectSingleNode("/meta-data");
    Iterator j = flandProp.elementIterator();

    while (j.hasNext()) {
        Element prop = (Element) j.next();
        String name = prop.getName();
        String value = prop.getText();
        values.put(name, value);
    }

    Element finalEl = DocumentHelper.createElement("fsxml");
    Element propsEl = finalEl.addElement("properties");

    Iterator<String> it = values.keySet().iterator();
    while (it.hasNext()) {
        String name = it.next();
        String value = values.get(name);
        propsEl.addElement(name).addText(value);
    }

    xml = finalEl.asXML();

    return xml;
}