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.nokia.helium.antlint.checks.CheckScriptSize.java

License:Open Source License

/**
 * Check against the given node.//w w  w .  j  a v  a 2 s  .c o  m
 * 
 * @param node is the node to check.
 */
@SuppressWarnings("unchecked")
private void checkSizeOfScript(Element node) {
    String target = node.attributeValue("name");

    List<Node> statements = node.selectNodes("//target[@name='" + target + "']/script | //target[@name='"
            + target + "']/*[name()=\"hlm:python\"]");

    for (Node statement : statements) {
        int size = statement.getText().length();
        if (size > 1000) {
            log("Target " + target + " has a script with " + size
                    + " characters, code should be inside a python file");
        }
    }
}

From source file:com.nokia.helium.antlint.checks.CheckTabCharacter.java

License:Open Source License

/**
 * Check against the given node./*www .  ja  v a 2 s .  c o m*/
 * 
 * @param node
 *            is the node to check.
 */
@SuppressWarnings("unchecked")
private void checkTabsInScript(Element node) {
    if (node.getName().equals("target")) {
        String target = node.attributeValue("name");

        List<Node> statements = node.selectNodes("//target[@name='" + target + "']/script | //target[@name='"
                + target + "']/*[name()=\"hlm:python\"]");

        for (Node statement : statements) {
            if (statement.getText().contains("\t")) {
                log("Target " + target + " has a script with tabs");
            }
        }
    }
}

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

License:Open Source License

private int getNumberOfCollections(String collectionUri) {
    Document collections = FSXMLRequestHandler.instance().getNodePropertiesByType(collectionUri, 0, 0, 1);
    Node resultsAvailable = collections.selectSingleNode("//properties/totalResultsAvailable");
    return Integer.parseInt(resultsAvailable.getText());
}

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

License:Open Source License

@Override
public String run() {

    logger.debug("**************************** starting CreatePresentationAction ************************");

    String requestBody = event.getRequestData();
    logger.debug("request body: " + requestBody);

    String vidUri = "";

    try {/* w w w  .j av  a2 s. co m*/
        Document doc = DocumentHelper.parseText(requestBody);
        Node vidNode = doc.selectSingleNode("//referid");

        if (vidNode != null) {
            vidUri = vidNode.getText();
        }
    } catch (Exception e) {
        logger.error("", e);
    }

    String vidId = vidUri.substring(vidUri.lastIndexOf("/") + 1);
    String userUri = vidUri.substring(0, vidUri.lastIndexOf("/video"));

    logger.debug("video uri: " + vidUri);
    logger.debug("video id: " + vidId);
    logger.debug("user uri: " + userUri);

    // check if presentation already exists
    String presUri = userUri + "/presentation/p" + vidId;
    logger.debug("presentation uri: " + presUri);

    Boolean has = FSXMLRequestHandler.instance().hasProperties(presUri);
    if (has) {
        logger.debug("presentation already exists, no need to create.");
        return null;
    }

    String title = "";
    // get video properties
    Document vidDoc = FSXMLRequestHandler.instance().getNodeProperties(vidUri, false);
    Node titleNode = vidDoc.selectSingleNode(".//title");

    if (titleNode != null) {
        title = titleNode.getText();
    }

    String presxml = buildPresXML(vidUri, title);
    logger.debug("xml to create presentation: " + presxml);

    // create the presentation
    String presPropsUri = presUri + "/properties";

    logger.debug("about to set xml for presentation: " + presxml + " into url: " + presPropsUri);
    FSXMLRequestHandler.instance().handlePUT(presPropsUri, presxml);

    // create link in collection
    List<String> uris = FSXMLRequestHandler.instance().getReferParents(vidUri);

    Iterator<String> i = uris.iterator();
    while (i.hasNext()) {
        String uri = i.next();

        if (uri.indexOf(userUri) != -1 && uri.indexOf("collection") != -1) {

            String colUri = uri.substring(0, uri.lastIndexOf("/video"));
            // insert presentation in collection
            String colxml = buildColXML(presUri);
            String colAttrUri = colUri + "/presentation/p" + vidId + "/attributes";

            logger.debug("about to set xml for collection: " + colxml + " into url: " + colAttrUri);
            FSXMLRequestHandler.instance().handlePUT(colAttrUri, colxml);

            return null;
        }
        logger.error("None of the uris was either a collection or belonged to this user.");
        return null;
    }
    logger.error("there was no uri refering to the requested video.");
    return null;

}

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

License:Open Source License

@Override
public String run() {
    logger.debug("\n\n ######### starting create momar raw action ######\n\n");
    String requestBody = event.getRequestData();
    logger.debug("\n\nRequest Data: " + requestBody);
    String mount = null, original = null, batchFile = null;
    Document doc = null;//  w  w  w. jav a2s.  c  om

    try {
        if (requestBody != null) {
            doc = DocumentHelper.parseText(requestBody);
            Node node1 = doc.selectSingleNode("//properties/mount");
            Node node2 = doc.selectSingleNode("//properties/original");
            Node node3 = doc.selectSingleNode("//properties/transcoder");
            Node node4 = doc.selectSingleNode("//properties/batchfile");
            if (node3 != null && node3.getText() != null && node3.getText().equals("apu")) {
                logger.debug("The video was already transcoded by apu, skipping raw2 creation");
                return null;
            }
            if (node4 != null && node4.getText() != null) {
                //encoding using specified batchfile
                batchFile = node4.getText();
            }

            //Node useMomar = doc.selectSingleNode("//properties/momar");

            //if(useMomar != null && useMomar.getText().toLowerCase().equals("false")){
            //   logger.debug("\n\n Momar tag is false ! Will not create Momar Job !!\n");
            //   return null;
            //}

            if (node1 != null) {
                mount = node1.getText();
                logger.debug("\n\n\n\n\nFOUND MOUNT: " + mount);
            } else {
                logger.debug("\n\n\n\n\nNO MOUNT FOUND IN PROPERTIES");
            }

            if (node2 != null) {
                original = node2.getText();
                logger.debug("\n\n\n\n\nFOUND ORIGINAL: " + original);
            } else {
                logger.debug(
                        "\n\n\n\n\nNO ORIGINAL FOUND IN PROPERTIES, WHICH MEANS APU UPLOAD, CREATE ORIGINAL ANYWAYS ;)");
                createOriginalTagAfterApuUpload();
                return null;
            }
        }
    } catch (DocumentException e) {
        logger.error("", e);
    }
    String uri = event.getUri();
    logger.debug("CREATE RAW 2 ACTION:\nURI: " + uri);
    String raw2Uri = uri.substring(0, uri.lastIndexOf("/")) + "/2";
    if (!FSXMLRequestHandler.instance().hasProperties(raw2Uri) && mount != null) {
        createRaw2Properties(raw2Uri, mount, batchFile);
    }
    return null;
}

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

License:Open Source License

@Override
public String run() {
    logger.debug("Starting to create all required raws");
    String uri = event.getUri();/*from w w w.j  av a  2  s  . c o  m*/
    String requestBody = event.getRequestData();
    logger.debug("\n\nRequest Data: " + requestBody);
    String mount = null, original = null;
    Document originalDoc = null;

    try {
        if (requestBody != null) {
            originalDoc = DocumentHelper.parseText(requestBody);
            Node mountNode = originalDoc.selectSingleNode("//properties/mount");
            Node originalNode = originalDoc.selectSingleNode("//properties/original");
            Node transcoderNode = originalDoc.selectSingleNode("//properties/transcoder");
            if (transcoderNode != null && transcoderNode.getText() != null
                    && transcoderNode.getText().equals("apu")) {
                logger.debug("The video was already transcoded by apu, skipping raw2 creation");
                return null;
            }

            if (mountNode != null && mountNode.getText() != null) {
                mount = mountNode.getText();
                logger.debug("\n\n\n\n\nFOUND MOUNT: " + mount);
            } else {
                logger.debug("\n\n\n\n\nNO MOUNT FOUND IN PROPERTIES");
            }

            if (originalNode != null && originalNode.getText() != null) {
                original = originalNode.getText();
                logger.debug("\n\n\n\n\nFOUND ORIGINAL: " + original);
            } else {
                logger.debug(
                        "\n\n\n\n\nNO ORIGINAL FOUND IN PROPERTIES, WHICH MEANS APU UPLOAD, CREATE ORIGINAL ANYWAYS ;)");
                createOriginalTagAfterApuUpload();
                return null;
            }
        }
    } catch (DocumentException e) {
        logger.error("", e);
    }

    //get config and number of raws to work on
    Map<String, EncodingProfile> profiles = getConfigs(uri);
    String[] ids = new String[profiles.size()];
    logger.debug("number of profiles = " + profiles.size());
    int h = 0;

    for (Iterator i = profiles.keySet().iterator(); i.hasNext();) {
        ids[h] = (String) i.next();
        h++;
    }
    //sorting using natural order!! so 11 < 2
    Arrays.sort(ids);

    for (int j = 0; j < ids.length; j++) {
        String id = ids[j];
        logger.debug("found video config " + id);
        String rawUri = uri.substring(0, uri.lastIndexOf("/")) + "/" + id + "/properties";

        if (FSXMLRequestHandler.instance().getPropertyValue(rawUri + "/reencode") == null && mount != null) {
            //if (!FSXMLRequestHandler.instance().hasProperties(rawUri) && mount != null) {         
            createRawProperties(rawUri, mount, profiles.get(id));
        }
    }
    return null;
}

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

License:Open Source License

@Override
public String run() {
    // parse request
    String requestBody = event.getRequestData();
    String requestUri = event.getUri();

    try {/*from   w w  w.ja  v  a2  s.  c o  m*/
        Document doc = DocumentHelper.parseText(requestBody);
        Node statusNode = doc.selectSingleNode("//properties/status");
        Node flandersNode = doc.selectSingleNode("//properties/metadata_file"); // created by flanders

        // check if status was done
        if (statusNode == null || !statusNode.getText().toLowerCase().equals(DONE) || flandersNode != null) {
            logger.debug("Not sending to flanders");
            return null;
        } else {
            logger.debug("Sending request to flanders (" + requestUri + ")");
            String newProperties = processRaw(requestUri, requestBody);
            FSXMLRequestHandler.instance().saveFsXml(requestUri, newProperties, "PUT", true);
        }
    } catch (Exception e) {
        logger.error("Could not parse request data");
    }

    return null;
}

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

License:Open Source License

private String processRaw(String uri, String xml) {
    // parse document
    Document doc = null;//from  www  .jav  a  2 s.  c o m
    try {
        doc = DocumentHelper.parseText(xml);
    } catch (DocumentException e) {
        logger.error("Could not parse xml", e);
        return null;
    }

    // check mount property
    Node mountNode = doc.selectSingleNode("//mount");
    if (mountNode == null) {
        logger.error("No mount property was set");
        return null;
    }

    // extract single mount
    String mount = null;
    String mounts = mountNode.getText();
    if (mounts != null && !mounts.equals("")) {
        mount = mounts.indexOf(",") != -1 ? mounts.substring(0, mounts.indexOf(",")) : mounts;
    }

    // determine external or local stream
    String flandersXml = null;
    if (mount.toLowerCase().startsWith("rtmp")) {
        logger.debug("External stream");
        Node filenameNode = doc.selectSingleNode("//filename");
        if (filenameNode != null) {
            String filename = filenameNode.getText();
            flandersXml = getXmlFromFlandersExternal(filename, mount);
        }
    } else if (mount.toLowerCase().indexOf("drm://") != -1) {
        logger.debug("DRM stream");
        Node filenameNode = doc.selectSingleNode("//filename");
        if (filenameNode != null) {
            String filename = filenameNode.getText();
            flandersXml = getXmlFromFlandersBgDrm(filename, mount);
        }
    } else {
        logger.debug("Local stream");
        Node extNode = doc.selectSingleNode("//extension");
        Node filenameNode = doc.selectSingleNode("//filename");
        if (filenameNode != null) {
            String filename = filenameNode.getText();
            flandersXml = getXmlFromFlandersLocal(filename, mount);
        } else if (extNode != null) {
            String extension = extNode.getText();
            String filename = uri + "/raw." + extension;
            flandersXml = getXmlFromFlandersLocal(filename, mount);
        } else {
            logger.error("Extension property was not set");
            return null;
        }
    }

    logger.debug("FLANDERS XML: " + flandersXml);
    xml = processXml(xml, flandersXml);
    return xml;
}

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

License:Open Source License

private static int getNumberOfCollections(String collectionUri) {
    Document collections = FSXMLRequestHandler.instance().getNodePropertiesByType(collectionUri, 0, 0, 1);
    Node resultsAvailable = collections.selectSingleNode("//properties/totalResultsAvailable");
    return Integer.parseInt(resultsAvailable.getText());
}

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

License:Open Source License

private void rebuildMenuIndex(String uri) {
    totalKeywords = new ArrayList<String>();
    totalLocations = new ArrayList<String>();
    totalDates = new ArrayList<String>();
    totalWitnesses = new ArrayList<String>();
    totalPersons = new ArrayList<String>();
    totalSpeakers = new ArrayList<String>();

    /* Delete current index */
    FSXMLRequestHandler.instance().deleteNodeProperties(indexUri, true);

    String collectionUri = getSubUri(uri, 4) + "/collection";

    /* Determine total number of collections */
    Document collections = FSXMLRequestHandler.instance().getNodePropertiesByType(collectionUri, 0, 0, 1);
    Node resultsAvailable = collections.selectSingleNode("//properties/totalResultsAvailable");
    int numCollections = Integer.parseInt(resultsAvailable.getText());

    logger.debug("num collections = " + numCollections);
    FSXMLRequestHandler.instance().handlePUT(indexUri + "/properties", "<fsxml><properties><lastupdate>"
            + String.valueOf(new Date().getTime()) + "</lastupdate></properties></fsxml>");

    /* Loop over all collections */
    for (int i = 0; i < numCollections; i++) {
        logger.debug("collection " + i);
        Document collection = FSXMLRequestHandler.instance().getNodePropertiesByType(collectionUri, 10, i, 1);

        String cId = collection.selectSingleNode("//collection/@id").getText();
        List<Node> presentations = collection.selectNodes("//presentation");

        if (domainid.equals("webtv")) {
            Document coll = FSXMLRequestHandler.instance().getNodeProperties(collectionUri + "/" + cId, 1,
                    false);// w w  w  .ja  v a2s  .  c om
            collectionstatus = coll.selectSingleNode("//properties/publicationstatus") == null ? ""
                    : coll.selectSingleNode("//properties/publicationstatus").getText();
            logger.debug("collectionstatus = " + collectionstatus);
        }

        /* loop over all presentations from collection */
        for (Iterator<Node> iter = presentations.iterator(); iter.hasNext();) {
            Element pres = (Element) iter.next();
            String collectionPresentationUri = collectionUri + "/" + cId + "/presentation/"
                    + pres.attributeValue("id");
            String presentationUri = pres.attributeValue("referid");
            logger.debug("presentation uri = " + presentationUri);

            /* since getnodeproperties is not possible on an id node do a get and convert that to a document */
            //Document presentation = FSXMLRequestHandler.instance().getNodePropertiesByType(presentationUri, 10, 0, 1);
            String pr = null;
            try {
                //FSXMLRequestHandler.instance().getNodeProperties(presentationUri, false);
                pr = FSXMLRequestHandler.instance().handleGET(presentationUri, null).getText();
            } catch (Exception e) {
            }

            Document presentation = null;
            try {
                presentation = DocumentHelper.parseText(pr);
            } catch (Exception e) {
            }

            String pId = presentation.selectSingleNode("//presentation/@id") == null ? ""
                    : presentation.selectSingleNode("//presentation/@id").getText();

            /*JHM hack */
            if (domainid.equals("jhm")) {
                String lockmode = presentation.selectSingleNode("//presentation/properties/lockmode") == null
                        ? ""
                        : presentation.selectSingleNode("//presentation/properties/lockmode").getText();
                if (lockmode.equals("Finished / Approved")) {
                    presentationResults(presentation);
                }
            } else if (!domainid.equals("lhwebtv") || pId.indexOf("p") > -1 || Integer.parseInt(pId) > 240) {
                presentationResults(presentation);
            }
        }
    }
    //add jhm keywords from config
    if (domainid.equals("jhm")) {
        Document document = DocumentHelper.createDocument();
        Element fsxml = document.addElement("fsxml");

        Document db = FSXMLRequestHandler.instance().getNodePropertiesByType(
                "/domain/jhm/config/presentation/filesystem/1/layer/4/database/1/keyword", 10, 0, 1000);

        logger.debug(db.asXML());

        List<Node> keywords = db.selectNodes("//keyword/properties/name");

        logger.debug("nr of keywords = " + keywords.size());

        /* loop over all keywords */
        for (Iterator<Node> iter = keywords.iterator(); iter.hasNext();) {
            Element e = (Element) iter.next();

            String keyword = e.getText();

            logger.debug("add " + keyword);

            Element menuitem = fsxml.addElement("item");
            Element properties = menuitem.addElement("properties");
            properties.addElement("keyword").addText(keyword);

            /* Unique chapter id */
            long timestamp = new Date().getTime();
            menuitem.addAttribute("id", String.valueOf(timestamp));
            try {
                Thread.sleep(1);
            } catch (InterruptedException exc) {
                logger.error("", exc);
            }
        }
        logger.debug("going to save " + document.asXML());
        FSXMLRequestHandler.instance().saveFsXml(indexUri, document.asXML(), "PUT", true);
    }
}