Example usage for org.dom4j Node getText

List of usage examples for org.dom4j Node getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text of this node.

Usage

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

License:Open Source License

@Override
public String run() {
    //if (1==1) return null; // not in use anymore in new momar 

    // parse request
    String requestBody = event.getRequestData();
    try {//from w ww .j a va  2 s. c  o m
        Document doc = DocumentHelper.parseText(requestBody);
        Node node = doc.selectSingleNode("//properties/reencode");
        if (node == null || !node.getText().toLowerCase().equals(DO_REENCODE)) {
            logger.debug("Not reencoding");
            return null;
        } else {
            putInQueue();
        }
    } catch (Exception e) {
        logger.error(e);
    }

    return null;
}

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

License:Open Source License

@Override
public String run() {

    logger.debug("starting action");

    // parse request
    String requestBody = event.getRequestData();
    try {//from   w w w  .  j  ava  2 s  .  c o  m
        Document doc = DocumentHelper.parseText(requestBody);
        Node node = doc.selectSingleNode("//properties/redo");
        if (node == null || !node.getText().toLowerCase().equals(REDO)) {
            logger.debug("Not redoing the job");
            return null;
        } else {
            logger.debug("about to put in queue");
            putInQueue();
        }
    } catch (Exception e) {
        logger.error("", e);
    }

    return null;
}

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

License:Open Source License

@Override
public String run() {
    // parse input
    Element element;/*  w  ww.  ja v a2  s  .  c  o m*/
    String eId;
    List<Element> iElements = script.getInput().getInputElements();
    for (Iterator<Element> iter = iElements.iterator(); iter.hasNext();) {
        element = iter.next();
        eId = element.attributeValue("id");
        if (eId != null && eId.equals("search")) {
            // parse properties
            Node pNode = element.selectSingleNode("properties");
            if (pNode != null) {
                List<Node> children = pNode.selectNodes("child::*");
                Node child;
                for (Iterator<Node> cIter = children.iterator(); cIter.hasNext();) {
                    child = cIter.next();
                    sProperties.put(child.getName(), child.getText());
                }
            }
        }
    }

    // check on uri
    String uri = sProperties.get("uri");
    if (uri == null) {
        logger.error("SearchAction: Required input parameters not specified");
        return null;
    }

    // build search uri
    String sUri = "", key, value;
    for (Iterator<String> iter = sProperties.keySet().iterator(); iter.hasNext();) {
        key = iter.next();
        if (!key.equals("uri")) {
            value = sProperties.get(key);
            sUri += "&" + key + "=" + value;
        }
    }
    sUri = sUri.replaceFirst("&", "?");

    // get service
    String domain = URIParser.getDomainFromUri(uri);
    Service service = ServiceHelper.getService(domain, "searchmanager");
    if (service == null) {
        logger.error("SearchAction: Service was null");
        return null;
    }

    // build final url
    String finalUrl = service.getUrl() + uri + sUri;

    logger.error("SearchAction: final url was " + finalUrl);

    // do request
    String response = HttpHelper.sendRequest("GET", finalUrl, null, null);

    // parse response
    String fsxml = parse2fsxml(response);

    logger.debug("result fsxml is " + fsxml);

    // delete old
    FSXMLRequestHandler.instance().handleDELETE(script.getID() + "/output/" + id + "/result", null);

    // save fsxml in output
    script.getOutput().setOutput(fsxml);

    return null;
}

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

License:Open Source License

private void initCommandList() {
    File file = new File(GlobalConfig.instance().getBaseDir() + "conf/" + CONFIG_FILE);
    logger.info("Initializing command list: " + file.getAbsolutePath());
    Document doc = XMLHelper.getXmlFromFile(file);
    if (doc != null) {
        List<Node> nl = doc.selectNodes("//command");
        for (Node n : nl) {
            if (n instanceof Element) {
                if (n.getName() != null && n.getName().equals("command")) {
                    Node idn = n.selectSingleNode("./id");
                    Node cln = n.selectSingleNode("./class");
                    Node jn = n.selectSingleNode("./jar");
                    if (idn != null && cln != null) {

                        String id = idn.getText();
                        String cl = cln.getText();
                        String jar = null;
                        if (jn != null && cl != null) {
                            jar = jn.getText();
                        }//from www. ja v a2s .c om
                        if (id != null && cl != null) {
                            try {
                                if (jar != null) {
                                    logger.info("Loading jar " + jar + " for class " + cl);
                                    Class<?> commandClass = loadJar(jar, cl);
                                    if (commandClass != null) {
                                        Command o = (Command) commandClass.newInstance();
                                        commands.put(id, o);
                                    }
                                } else {
                                    Class c = Class.forName(cl);
                                    Object o = c.newInstance();
                                    if (o instanceof Command) {
                                        commands.put(id, (Command) o);
                                    }
                                }
                            } catch (Exception e) {
                                System.out.println("Problem with loading " + cl);
                            }
                        }
                    }
                }
            }
        }
    }
}

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

License:Open Source License

/**
 * Load a specific command/*from   w  ww.ja v a  2s .  c  o  m*/
 * @param cid the command to load
 * @return the command object loaded
 */
private Command loadCommand(String cid) {
    File file = new File(GlobalConfig.instance().getBaseDir() + "conf/" + CONFIG_FILE);
    Document doc = XMLHelper.getXmlFromFile(file);
    if (doc != null) {
        List<Node> nl = doc.selectNodes("//command");
        for (Node n : nl) {
            if (n instanceof Element) {
                if (n.getName() != null && n.getName().equals("command")) {
                    Node idn = n.selectSingleNode("./id");
                    Node cln = n.selectSingleNode("./class");
                    Node jn = n.selectSingleNode("./jar");
                    if (idn != null && cln != null) {
                        String id = idn.getText();
                        String cl = cln.getText();
                        String jar = null;

                        if (id != null && cl != null && id.equals(cid)) {
                            if (jn != null && cl != null) {
                                jar = jn.getText();
                            }
                            try {
                                if (jar != null) {
                                    logger.info("Loading jar " + jar + " for class " + cl);
                                    Class<?> commandClass = loadJar(jar, cl);
                                    if (commandClass != null) {
                                        Command o = (Command) commandClass.newInstance();
                                        commands.put(id, o);
                                    }
                                } else {
                                    Class c = Class.forName(cl);
                                    Object o = c.newInstance();
                                    if (o instanceof Command) {
                                        commands.put(id, (Command) o);
                                    }
                                }
                            } catch (ClassNotFoundException e) {
                                logger.error("", e);
                            } catch (InstantiationException e) {
                                logger.error("", e);
                            } catch (IllegalAccessException e) {
                                logger.error("", e);
                            }
                        }
                    }
                }
            }
        }
    }
    return commands.get(cid);
}

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

License:Open Source License

/**
 * /*w  w w .  ja v a 2 s  .  c  om*/
 * @param uri
 * @return
 */
private Document getPropertiesOfUri(String uri, int depth) {
    // refactor uri
    String cp = URIParser.getCurrentUriPart(uri);
    if (cp.equals(FSXMLHelper.XML_PROPERTIES)) {
        uri = URIParser.getParentUri(uri);
    }

    // get complete
    Document pDoc = null;
    if (depth == -1) {
        pDoc = rHandler.getNodeProperties(uri, true);
    } else {
        pDoc = rHandler.getNodeProperties(uri, depth, true);
    }

    // loop through xml and check referid's
    List<Node> rNodes = pDoc.selectNodes("//@referid");
    logger.debug("rNodes: " + rNodes);
    for (Iterator<Node> iter = rNodes.iterator(); iter.hasNext();) {
        // get referid attribute and parent node
        Node node = iter.next();
        String referid = node.getText();
        Element parent = node.getParent();
        logger.debug("parent: " + parent.asXML() + ", refer: " + referid);

        // get properties of referid
        Document rDoc = rHandler.getNodeProperties(referid, 0, false);
        logger.debug("rDoc: " + rDoc.asXML());
        Node properties = rDoc.selectSingleNode("//properties");
        List<Node> pNodes = properties.selectNodes("child::*");
        logger.debug("pNodes: " + pNodes);
        for (Iterator<Node> iter2 = pNodes.iterator(); iter2.hasNext();) {
            // select the same property elements that are in parent element and refer properties
            Node prop = iter2.next();
            List<Node> parentPNodes = parent.selectNodes("properties/child::*");
            for (Node parentPropNode : parentPNodes) {
                if (parentPropNode.getName().equals(prop.getName())
                        && parentPropNode.getText().equals(prop.getText())) {
                    logger.debug("removing: " + parentPropNode.asXML());
                    parentPropNode.detach();
                }
            }
        }
    }

    return pDoc;
}

From source file:com.noterik.bart.fs.fscommand.dynamic.collection.config.wizard.java

License:Open Source License

public String run(String uri, String xml) {
    logger.debug("start dynamic/collection/config/wizard");

    Document doc = XMLHelper.asDocument(xml);

    if (doc == null) {
        return FSXMLBuilder.getErrorMessage("403", "The value you sent is not valid",
                "You have to POST a valid command XML", "http://teamelements.noterik.nl/team");
    }/* ww  w .  j a  v  a 2s  .com*/

    String user = doc.selectSingleNode("//properties/user") == null ? ""
            : doc.selectSingleNode("//properties/user").getText();
    String ticket = doc.selectSingleNode("//properties/ticket") == null ? ""
            : doc.selectSingleNode("//properties/ticket").getText();

    //TODO: validate user/ticket

    //get collection
    Document collection = FSXMLRequestHandler.instance().getNodeProperties(uri, false);
    logger.debug(collection.asXML());

    //get roles
    Element wizard;
    List<Node> wizards = collection.selectNodes("//config[@id='1']/wizard");
    Node userRole = collection
            .selectSingleNode("//config[@id='roles']/user[@id='" + user + "']/properties/wizard");

    if (userRole == null) {
        logger.debug("user not found --> default wizard");
        // Loop all wizards
        for (Iterator<Node> iter = wizards.iterator(); iter.hasNext();) {
            wizard = (Element) iter.next();

            String wizardId = wizard.attribute("id") == null ? "" : wizard.attribute("id").getText();
            if (!wizardId.equals("1")) {
                logger.debug("detach wizard with id " + wizardId);
                wizard.detach();
            }
        }
    } else {
        logger.debug("user found " + userRole.asXML());
        String roles = userRole.getText();
        String[] results = roles.split(",");

        // Loop all wizards
        for (Iterator<Node> iter = wizards.iterator(); iter.hasNext();) {
            wizard = (Element) iter.next();

            String wizardId = wizard.attribute("id") == null ? "" : wizard.attribute("id").getText();
            if (!inArray(results, wizardId)) {
                logger.debug("detach wizard with id " + wizardId);
                wizard.detach();
            }
        }
    }

    //detach config roles
    Node configRoles = collection.selectSingleNode("//config[@id='roles']");
    configRoles.detach();

    return collection.asXML();
}

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

License:Open Source License

public String execute(String url, String xml) {
    logger.debug("Updating properties of presentation " + url);
    logger.debug("Updating properties xml " + xml);

    Document doc = XMLHelper.asDocument(xml);
    List<Node> properties;

    //TODO: validate ticket

    //add every property in the xml supplied      
    properties = doc.selectNodes("//properties/*");

    for (Iterator<Node> it = properties.iterator(); it.hasNext();) {
        Node property = it.next();

        if (!property.getName().equals("ticket")) {
            logger.debug("updating property " + property.getName() + " with value " + property.getText());

            FSXMLRequestHandler.instance().handlePUT(url + "/properties/" + property.getName(),
                    property.getText());
        }/*w w w .j av a2 s .com*/
    }
    return FSXMLBuilder.getFSXMLStatusMessage("The properties where successfully added", "", "");
}

From source file:com.noterik.bart.fs.fsxml.FSXMLRequestHandler.java

License:Open Source License

/**
 * Get pruning parameters from request body
 * /*from w  w  w. ja va  2 s  .c  om*/
 * @param value
 * @return
 */
private Map<String, String> getParameters(String value) {
    Map<String, String> params = new HashMap<String, String>();

    // parse request body
    Node start = null, limit = null, depth = null;
    try {
        Document doc = DocumentHelper.parseText(value);
        start = doc.selectSingleNode("//properties/start");
        limit = doc.selectSingleNode("//properties/limit");
        depth = doc.selectSingleNode("//properties/depth");
    } catch (Exception e) { /*
                            * request body empty or request body could not
                            * be parsed
                            */
    }

    // add to params
    if (start != null) {
        params.put("start", start.getText());
    }
    if (limit != null) {
        params.put("limit", limit.getText());
    }
    if (depth != null) {
        params.put("depth", depth.getText());
    }

    return params;
}

From source file:com.noterik.bart.fs.ingest.SimpleIngestHandler.java

License:Open Source License

/**
 * only used in OU//  w w w  . j  a va 2s  .c om
 * creates the raw images for the nelson jobs (thumbnails)
 * @param uri
 */

// not used anymore !!
public void createImageRawsForOU(String uri) {

    String domain = URIParser.getDomainFromUri(uri);

    String configUri = "/domain/" + domain + "/config/image";
    Document doc = FSXMLRequestHandler.instance().getNodeProperties(configUri, false);

    List<Element> raws = (List<Element>) doc.selectNodes("//rawimage");
    logger.debug("OU image config\n" + doc.asXML());
    // go through all elements
    for (Element raw : raws) {
        String id = raw.valueOf("@id");
        String rawUri = uri.substring(0, uri.lastIndexOf("/") + 1) + id + "/properties";
        Element props = (Element) raw.selectSingleNode("./properties");
        StringBuffer fsxml = null;
        // create the raw
        if (props != null) {
            fsxml = new StringBuffer("<fsxml><properties>");
            Node child = null;
            for (Iterator i = ((Element) props).nodeIterator(); i.hasNext();) {
                child = (Node) i.next();
                fsxml.append("<" + child.getName() + ">" + child.getText() + "</" + child.getName() + ">");
            }
            fsxml.append("</properties></fsxml>");
            logger.debug("ou uri: " + rawUri + " xml\n" + fsxml.toString());
            FSXMLRequestHandler.instance().saveFsXml(rawUri, fsxml.toString(), "PUT", true);
        }
    }
}