Example usage for org.dom4j DocumentHelper createDocument

List of usage examples for org.dom4j DocumentHelper createDocument

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createDocument.

Prototype

public static Document createDocument() 

Source Link

Usage

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);//from ww  w.  ja  v a2 s . 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);
    }
}

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

License:Open Source License

private void putType(List<Node> type, String t, String[] aNames) {
    Element e;//from   w ww  . j  a  v  a 2 s. c o m
    boolean empty = true;
    Document document = DocumentHelper.createDocument();
    Element fsxml = document.addElement("fsxml");

    /* Loop all elements */
    for (Iterator<Node> iter = type.iterator(); iter.hasNext();) {
        logger.debug("looping elements of type " + t);
        e = (Element) iter.next();

        for (int i = 0; i < aNames.length; i++) {
            String name = e.element("properties").elementText(aNames[i]) == null ? ""
                    : e.element("properties").elementText(aNames[i]);

            //logger.debug("got "+t+" with value "+name);

            if (!name.equalsIgnoreCase("datatype") && !name.equals("") && !elementExists(t, name)) {
                empty = false;
                if (t.equals("keyword")) {
                    totalKeywords.add(name.toLowerCase());
                } else if (t.equals("location")) {
                    totalLocations.add(name.toLowerCase());
                } else if (t.equals("date")) {
                    totalDates.add(name.toLowerCase());
                } else if (t.equals("person")) {
                    totalPersons.add(name.toLowerCase());
                } else if (t.equals("witness")) {
                    //remove number in front of title for jhm
                    if (domainid.equals("jhm") && name.length() > 6) {
                        name = name.substring(6);
                    }
                    totalWitnesses.add(name.toLowerCase());
                } else if (t.equals("speakers")) {
                    name += e.element("properties").elementText("lastname") == null ? ""
                            : " " + e.element("properties").elementText("lastname");
                    //name += e.element("properties").elementText("organization") == null ? "" : e.element("properties").elementText("organization");
                }

                logger.debug("element exists? " + elementExists(t, name));

                if (!t.equals("speakers") || !domainid.equals("webtv")
                        || (collectionstatus.equals("published") && !elementExists(t, name))) {
                    if (t.equals("speakers") && domainid.equals("webtv")) {
                        totalSpeakers.add(name.toLowerCase());
                    }

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

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

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

License:Open Source License

/**
 * Create XML for an index//from  w  w  w.  j  a v  a2  s .co  m
 * 
 * @param presentationUri
 * @param presentationDetails
 * @param collectionDetails
 * @param iConfig
 */
private static void makeTypeFromPresentation(String presentationUri, Map<String, Object> presentationDetails,
        Map<String, Object> collectionDetails, IndexConfig iConfig) {
    Document typeDocument = DocumentHelper.createDocument();
    Element fsxml = typeDocument.addElement("fsxml");
    Element type = fsxml.addElement(iConfig.getIndexType());

    // add refer to original presentation
    Element referPresentation = type.addElement("presentation");
    referPresentation.addAttribute("id", "1");
    referPresentation.addAttribute("referid", presentationUri);

    //add refer to original collection, remove trailing slash, otherwise refer cannot be found!
    Element referCollectionPresentation = type.addElement("collectionpresentation");
    referCollectionPresentation.addAttribute("id", "1");
    String collectionPresentation = (String) collectionDetails.get("presentation");
    collectionPresentation = collectionPresentation.substring(0, collectionPresentation.length() - 1);
    referCollectionPresentation.addAttribute("referid", collectionPresentation);

    Element properties = type.addElement("properties");
    //add standard properties
    properties.addElement("presentation").addText((String) collectionDetails.get("presentation"));
    properties.addElement("presentationuri").addText(presentationUri + "/");
    properties.addElement("collection").addText((String) collectionDetails.get("collection"));
    properties.addElement("presentationtitle").addText((String) presentationDetails.get("presentationtitle"));
    properties.addElement("presentationdescription")
            .addText((String) presentationDetails.get("presentationdescription"));
    properties.addElement("presentationscreenshot")
            .addText((String) presentationDetails.get("presentationscreenshot"));
    properties.addElement("presentationtype").addText((String) presentationDetails.get("presentationtype"));
    properties.addElement("presentationauthor").addText((String) presentationDetails.get("presentationauthor"));
    properties.addElement("presentationcopyright")
            .addText((String) presentationDetails.get("presentationcopyright"));
    properties.addElement("presentationwebsite")
            .addText((String) presentationDetails.get("presentationwebsite"));

    //add user configured properties
    Map<String, String> items = iConfig.getProperties();
    for (String item : items.keySet()) {
        if (item.equals("collectiontitle") || item.equals("collectiondescription")
                || item.equals("collectionstatus")) {
            properties.addElement(item).addText((String) collectionDetails.get(item));
        } else if (item.equals("lockmode") || item.equals("date_created") || item.equals("presentationduration")
                || item.equals("presentationtheme") || item.equals("presentationlocation")
                || item.equals("presentationdate") || item.equals("presentationdate_original")
                || item.equals("presentationpublic") || item.equals("sponsor")) {
            properties.addElement(item).addText((String) presentationDetails.get(item));
        } else if (item.equals("title") || item.equals("name")) {
            properties.addElement(item).addText((String) presentationDetails.get("presentationtitle"));
        } else if (item.equals("description")) {
            properties.addElement(item).addText((String) presentationDetails.get("presentationdescription"));
        } else if (item.equals("screenshot")) {
            properties.addElement(item).addText((String) presentationDetails.get("presentationscreenshot"));
        } else if (item.equals("rank")) {
            properties.addElement(item).addText("5");
        } else if (item.equals("peercomments")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "peercomments", 0.0, 86400000.0, new String[] { "comment" }));
        } else if (item.equals("bookmark")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "bookmark", 0.0, 86400000.0, new String[] { "title", "description", "creator" }));
        } else if (item.equals("webtv_item_id") || item.equals("presentationlivestate")) {
            properties.addElement(item).addText((String) presentationDetails.get(item));
        }
    }

    long timestamp = new Date().getTime();
    type.addAttribute("id", String.valueOf(timestamp));

    // Add directly to fs so maggie get's updated with first content faster
    FSXMLRequestHandler.instance().saveFsXml(iConfig.getIndexUri(), typeDocument.asXML(), "PUT", true);
}

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

License:Open Source License

/**
 * Create XML for an index//from   w w  w .  j  a va 2 s. c om
 * 
 * @param typeContent
 * @param presentationUri
 * @param presentationDetails
 * @param collectionDetails
 * @param iConfig
 */
private static void makeType(Element typeContent, String presentationUri,
        Map<String, Object> presentationDetails, Map<String, Object> collectionDetails, IndexConfig iConfig) {
    // create new type
    Document typeDocument = DocumentHelper.createDocument();
    Element fsxml = typeDocument.addElement("fsxml");
    Element type = fsxml.addElement(iConfig.getIndexType());

    // add refer to original presentation
    Element referPresentation = type.addElement("presentation");
    referPresentation.addAttribute("id", "1");
    referPresentation.addAttribute("referid", presentationUri);

    // add refer to original collection
    Element referCollectionPresentation = type.addElement("collectionpresentation");
    referCollectionPresentation.addAttribute("id", "1");
    String collectionPresentation = (String) collectionDetails.get("presentation");
    collectionPresentation = collectionPresentation.substring(0, collectionPresentation.length() - 1);
    referCollectionPresentation.addAttribute("referid", (String) collectionPresentation);

    Element properties = type.addElement("properties");
    //add standard properties
    properties.addElement("presentation").addText((String) collectionDetails.get("presentation"));
    properties.addElement("presentationuri").addText(presentationUri + "/");
    properties.addElement("collection").addText((String) collectionDetails.get("collection"));
    properties.addElement("presentationtitle").addText((String) presentationDetails.get("presentationtitle"));
    properties.addElement("presentationdescription")
            .addText((String) presentationDetails.get("presentationdescription"));
    properties.addElement("presentationscreenshot")
            .addText((String) presentationDetails.get("presentationscreenshot"));
    properties.addElement("presentationtype").addText((String) presentationDetails.get("presentationtype"));
    properties.addElement("presentationauthor").addText((String) presentationDetails.get("presentationauthor"));
    properties.addElement("presentationcopyright")
            .addText((String) presentationDetails.get("presentationcopyright"));
    properties.addElement("presentationwebsite")
            .addText((String) presentationDetails.get("presentationwebsite"));

    //add user configured properties
    Map<String, String> items = iConfig.getProperties();

    Element typeProperties = typeContent.element("properties");

    double start = typeProperties.elementText("starttime") == null ? 0.0
            : Double.parseDouble(typeProperties.elementText("starttime"));
    double duration = typeProperties.elementText("duration") == null ? 0.0
            : Double.parseDouble(typeProperties.elementText("duration"));
    if (duration == 0.0) {
        duration = typeProperties.elementText("length") == null ? 0.0
                : Double.parseDouble(typeProperties.elementText("length"));
    }

    for (String item : items.keySet()) {
        if (item.equals("collectiontitle") || item.equals("collectiondescription")
                || item.equals("collectionstatus")) {
            properties.addElement(item).addText((String) collectionDetails.get(item));
        } else if (item.equals("lockmode") || item.equals("link") || item.equals("date_created")
                || item.equals("presentationduration") || item.equals("presentationtheme")
                || item.equals("presentationlocation") || item.equals("presentationdate")
                || item.equals("presentationdate_original") || item.equals("presentationpublic")
                || item.equals("sponsor")) {
            properties.addElement(item).addText((String) presentationDetails.get(item));
        } else if (item.equals("title") || item.equals("description") || item.equals("name")) {
            String value = typeProperties.elementText(item) == null ? "" : typeProperties.elementText(item);
            properties.addElement(item).addText(value);
        } else if (item.equals("firstnamelastname")) {
            String firstname = typeProperties.elementText("firstname") == null ? ""
                    : typeProperties.elementText("firstname");
            String lastname = typeProperties.elementText("lastname") == null ? ""
                    : typeProperties.elementText("lastname");
            properties.addElement("name").addText(firstname + " " + lastname);
        } else if (item.equals("screenshot")) {
            //former chapterscreenshot
            properties.addElement(item)
                    .addText(getTypeScreenshot((Document) presentationDetails.get("presentation"), start,
                            (String) presentationDetails.get("presentationscreenshot")));
        } else if (item.equals("rank")) {
            properties.addElement(item).addText(
                    String.valueOf(getRankBasedOnLockmode((String) presentationDetails.get("lockmode"))));
        } else if (item.equals("start")) {
            properties.addElement(item).addText(String.format(Locale.US, "%f", start));
        } else if (item.equals("duration")) {
            properties.addElement(item).addText(String.format(Locale.US, "%f", duration));
        } else if (item.equals("locations")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "location", start, duration, new String[] { "name" }));
        } else if (item.equals("dates")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "date", start, duration, new String[] { "start", "end" }));
        } else if (item.equals("keywords")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "keyword", start, duration, new String[] { "name" }));
        } else if (item.equals("persons")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "person", start, duration, new String[] { "name" }));
        } else if (item.equals("periods")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "period", start, duration, new String[] { "name" }));
        } else if (item.equals("speakers")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "speakers", start, duration, new String[] { "firstname", "lastname", "organization" }));
        } else if (item.equals("topics")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "topics", start, duration, new String[] { "name" }));
        } else if (item.equals("peercomments")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "peercomments", 0.0, 86400000.0, new String[] { "comment" }));
        } else if (item.equals("voiceindex")) {
            String voiceindex = typeProperties.elementText("voiceindex") == null ? ""
                    : typeProperties.elementText("voiceindex");
            properties.addElement(item).addText(voiceindex);
        } else if (item.equals("presentation" + iConfig.getIndexType())) {
            properties.addElement(item).addText(getTypeUri(typeContent, presentationUri, iConfig));
        } else if (item.equals("bookmark")) {
            properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"),
                    "bookmark", 0.0, 86400000.0, new String[] { "title", "description", "creator" }));
        } else if (item.equals("webtv_item_id") || item.equals("presentationlivestate")) {
            properties.addElement(item).addText((String) presentationDetails.get(item));
        }
    }
    long timestamp = new Date().getTime();
    type.addAttribute("id", String.valueOf(timestamp));

    // Add directly to fs so maggie get's updated with first content faster
    FSXMLRequestHandler.instance().saveFsXml(iConfig.getIndexUri(), typeDocument.asXML(), "PUT", true);
}

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

License:Open Source License

public synchronized String run(String uri, String xml) {
    logger.debug("start dynamic/presentation/playout/flash");
    logger.debug("qpr url=" + uri);
    long timer_start = new Date().getTime();
    Document returnXml = DocumentHelper.createDocument();
    Element fsxml = returnXml.addElement("fsxml");
    fsxml.addElement("properties");

    String domain = URIParser.getDomainIdFromUri(uri);
    String user = URIParser.getUserIdFromUri(uri);
    String selectedplaylist = "";
    Element handlerparams = null;

    int pos = xml.indexOf("<virtualpath>");
    if (pos != -1) {
        selectedplaylist = xml.substring(pos + 13 + 14);
        pos = selectedplaylist.indexOf("</virtualpath>");
        if (pos != -1) {
            selectedplaylist = selectedplaylist.substring(0, pos);
            try {
                handlerparams = (Element) DocumentHelper.parseText(xml).getRootElement();
            } catch (Exception docerror) {
                logger.error("invalid parameters in xml");
            }/*from w ww. ja v a 2s  .c o  m*/
        } else {
            logger.error("invalid virtual path");
        }
    }

    if (uri.indexOf("/collection/") == -1 || uri.indexOf("/presentation") == -1) {
        return FSXMLBuilder.getErrorMessage("403", "No collection presentation found",
                "You have to supply a valid collection presentation", "http://teamelements.noterik.nl/team");
    }

    config conf = new config(domain, user, selectedplaylist, handlerparams);

    Document presentationProperties = cache.get(uri);
    if (presentationProperties == null) {
        presentationProperties = FSXMLRequestHandler.instance().getNodeProperties(uri, false);
        if (presentationProperties == null) {
            return FSXMLBuilder.getErrorMessage("404", "Presentation not found",
                    "You have to supply an existing presentation", "http://teamelements.noterik.nl/team");
        }
        cache.put(uri, presentationProperties);
    }

    String collection = uri.substring(uri.indexOf("/collection/") + 12, uri.indexOf("/presentation/"));
    conf.setCollection(collection);

    logger.debug("presentation " + uri + " domain " + domain + " user " + user + " collection " + collection);

    Node presentationXml = getPresentation(uri);
    if (presentationXml != null) {
        fsxml.add(presentationXml);
        logger.debug("past presentation xml");
        List<Element> videos = addVideos(presentationXml);
        for (int i = 0; i < videos.size(); i++) {
            fsxml.add(videos.get(i));
        }
        logger.debug("past adding video(s)");
    }
    Node presentationConfig = getPresentationConfig(uri, presentationXml, conf);

    if (presentationConfig != null) {
        fsxml.add(presentationConfig);
        logger.debug("past presentation config");

        List<Element> players = addPlayer(presentationConfig);
        for (int j = 0; j < players.size(); j++) {
            fsxml.add(players.get(j));
        }
    }
    logger.debug("past adding player(s)");

    // moved the remapping of the presentation so we already have the video nodes.
    // Warning: This relies on the corrected presentation config (sponsor/user/collection level
    // don't move before the presentationconfig it's added to the document (dom4j issue)   !!
    presentationXml = dynamicTransform((Element) presentationXml, conf, fsxml);

    Node collectionConfig = getCollectionConfig(uri, conf);
    if (collectionConfig != null) {
        fsxml.add(collectionConfig);
    }

    logger.debug("past collection config");

    logger.debug("end dynamic/presentation/playout/flash");

    long timer_end = new Date().getTime();
    System.out.println("GENTIME=" + (timer_end - timer_start) + " CACHE AT " + cache.getPerformance() + "% req="
            + cache.getTotalRequest() + " size=" + cache.getCacheSize() + " URI=" + uri);
    return fsxml.asXML();
}

From source file:com.noterik.bart.fs.fscommand.dynamic.video.playout.flash.java

License:Open Source License

public synchronized String run(String uri, String xml) {
    logger.debug("start dynamic/video/playout/flash");

    Document returnXml = DocumentHelper.createDocument();
    Element fsxml = returnXml.addElement("fsxml");
    fsxml.addElement("properties");

    String domain = URIParser.getDomainIdFromUri(uri);
    String user = URIParser.getUserIdFromUri(uri);
    String selectedplaylist = "";
    Element handlerparams = null;

    config conf = new config(domain, user, selectedplaylist, handlerparams);

    Document videoProperties = cache.get(uri);
    if (videoProperties == null) {
        videoProperties = FSXMLRequestHandler.instance().getNodeProperties(uri, false);
        if (videoProperties == null) {
            return FSXMLBuilder.getErrorMessage("404", "Video not found",
                    "You have to supply an existing video", "http://teamelements.noterik.nl/team");
        }/*from  w  w  w  . ja v  a2  s .c om*/
        cache.put(uri, videoProperties);
    }

    Node videoXml = getVideo(uri);
    fsxml.add(videoXml);
    Node videoConfig = getVideoConfig(uri, videoXml, conf);

    //add fake presentation as placeholder for the video
    Element presentation = addPlaceholderPresentation(uri);
    fsxml.add(presentation);

    if (videoConfig != null) {
        fsxml.add(videoConfig);
        logger.debug("past video config");

        List<Element> players = addPlayer(videoConfig);
        for (int j = 0; j < players.size(); j++) {
            fsxml.add(players.get(j));
        }
    }
    logger.debug("past adding player(s)");

    return fsxml.asXML();
}

From source file:com.noterik.bart.fs.fscommand.dynamic.video.playout.flash.java

License:Open Source License

private static Element addPlaceholderPresentation(String uri) {
    Document xml = DocumentHelper.createDocument();

    Element presentation = xml.addElement("presentation");
    presentation.addAttribute("id", "1");
    String baseUri = uri.substring(0, uri.lastIndexOf("/video/"));
    presentation.addAttribute("fullid", baseUri + "/presentation/1");
    Element properties = presentation.addElement("properties");
    properties.addEntity("title", "test title");
    properties.addEntity("description", "test description");
    Element videoplaylist = presentation.addElement("videoplaylist");
    videoplaylist.addAttribute("id", "1");
    videoplaylist.addElement("properties");
    Element vid = videoplaylist.addElement("video");
    vid.addAttribute("id", "1");
    vid.addAttribute("referid", uri);

    return presentation;
}

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

License:Open Source License

public String execute(String uri, String xml) {
    int numSponsors = 0;
    Element user;/*from  w  ww.j  a  va  2  s . c  o  m*/
    Document typeDocument = DocumentHelper.createDocument();

    Element fsxml = typeDocument.addElement("fsxml");
    Element properties = fsxml.addElement("properties");

    String domain = URIParser.getDomainFromUri(uri);
    String userUri = "/domain/" + domain + "/user";

    Document userDoc = FSXMLRequestHandler.instance().getNodePropertiesByType(userUri, 0, 0, 999999);
    List<Node> users = userDoc.selectNodes("//user");

    logger.debug("# of users = " + users.size());

    //loop over all users of domain
    for (Iterator<Node> iter = users.iterator(); iter.hasNext();) {
        user = (Element) iter.next();
        String userid = user.selectSingleNode("@id") == null ? "" : user.selectSingleNode("@id").getText();

        logger.debug("user = " + userid);
        String sponsorUri = "/domain/" + domain + "/user/" + userid + "/sponsor";
        Document sponsor = FSXMLRequestHandler.instance().getNodePropertiesByType(sponsorUri, 0, 0, 1);
        int sponsorItems = sponsor.selectSingleNode("//totalResultsAvailable") == null ? 0
                : Integer.parseInt(sponsor.selectSingleNode("//totalResultsAvailable").getText());

        if (sponsorItems > 0) {
            logger.debug(userid + " sponsors " + sponsorItems);
            numSponsors++;
            fsxml.addElement("sponsor").addAttribute("id", userid);
        }
    }
    properties.addElement("totalResultsAvailable").addText(Integer.toString(numSponsors));
    return typeDocument.asXML();
}

From source file:com.noterik.bart.fs.legacy.properties.PropertyHandler.java

License:Open Source License

/**
 * this function creates the Document where the properties will be saved in
 * and the first element to put in it. Then it calls the loopInIt.
 *
 * @param uri/* ww w . j  a v  a2 s .co m*/
 * @return
 */
public static String getProperties(String uri) {
    int count = 0;
    String xmlProps = "";
    if (hasProperties(uri)) {
        List<String> uris = new ArrayList<String>();
        uris.add(uri);
        String id = uri.substring(uri.lastIndexOf("/") + 1);
        Document doc = DocumentHelper.createDocument();
        String type = getTypefromProp(uri);
        Element root = doc.addElement("fsxml");
        Element current = root.addElement(type).addAttribute("id", id);
        doc = loopInIt(doc, current, uri, count, uris);
        xmlProps = doc.asXML();
    }
    return xmlProps;
}

From source file:com.noterik.bart.fs.legacy.properties.PropertyHandler.java

License:Open Source License

/**
 * This function will get the properties of a uri only, and not of it's
 * childs/*  w  w w  . j  a va  2s. c  o m*/
 *
 * @param uri
 * @return
 */
public static Document getPropsNoChilds(String uri) {
    String url = uri.substring(0, uri.lastIndexOf("/"));
    logger.debug("url is:" + url);
    Document doc = DocumentHelper.createDocument();
    String id = url.substring(url.lastIndexOf("/") + 1);
    String type = getTypefromProp(url);
    Element root = doc.addElement("fsxml");
    Element current = root.addElement(type).addAttribute("id", id);
    String xml = getXMLfromProp(url);
    Element elem = null;
    // if xml is not empty, unwrapp it and add the node
    if (!xml.equals("")) {
        xml = unwrapXml(xml);
        try {
            elem = (Element) DocumentHelper.parseText(xml).getRootElement().clone();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        current.add(elem);
    } else {
        // if it is empty, just add an empty node
        current.addElement("properties");
    }
    return doc;
}