Example usage for org.dom4j Element addAttribute

List of usage examples for org.dom4j Element addAttribute

Introduction

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

Prototype

Element addAttribute(QName qName, String value);

Source Link

Document

Adds the attribute value of the given fully qualified name.

Usage

From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java

License:Open Source License

/**
 * Rendering the build node into XML string. 
 *///from  w ww  .  j a v a  2s  .  co  m
public String toString() {
    // Creating the XML document
    Document document = DocumentHelper.createDocument();
    Element statistics = document.addElement("statistics");
    statistics.addAttribute("version", "1.1");

    // Creating the document content.
    insertDatabase(statistics);
    createTargets(statistics);
    createAsserts(statistics);
    createExecutionTree(statistics);
    createProperties(statistics);
    try {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        XMLWriter out = new XMLWriter(output, OutputFormat.createPrettyPrint());
        out.write(document);
        return output.toString();
    } catch (UnsupportedEncodingException exc) {
        return document.asXML();
    } catch (IOException exc) {
        return document.asXML();
    }
}

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

License:Open Source License

private void makeTypeFromCollection(Map<String, Object> collectionDetails) {
    typeDocument.clearContent();/*ww w  . j  av  a  2  s .  c  o  m*/
    Element fsxml = typeDocument.addElement("fsxml");
    Element type = fsxml.addElement(indexSaveType);

    //add refer to original collection
    Element referCollectionPresentation = type.addElement("collectionrefer");
    referCollectionPresentation.addAttribute("id", "1");
    referCollectionPresentation.addAttribute("referid", (String) collectionDetails.get("collectionUri"));

    Element properties = type.addElement("properties");
    //add standard properties
    properties.addElement("collection").addText((String) collectionDetails.get("collectionUri"));

    //add user configured properties
    Map<String, String> items = userConfigMemory.get(domainid + ":" + userid);

    for (String item : items.keySet()) {
        if (item.equals("collectiontitle") || item.equals("collectiondescription")
                || item.equals("collectionstatus")) {
            properties.addElement(item).addText((String) collectionDetails.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(indexUri, typeDocument.asXML(), "PUT", true);
}

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

License:Open Source License

private void makeType(Element typeContent, Map<String, Object> collectionDetails) {
    // create new type
    typeDocument.clearContent();/*w  w  w  . j av a2  s.c o  m*/
    Element fsxml = typeDocument.addElement("fsxml");
    Element type = fsxml.addElement(indexSaveType);

    // add refer to original collection
    Element referCollectionPresentation = type.addElement("collectionrefer");
    referCollectionPresentation.addAttribute("id", "1");
    referCollectionPresentation.addAttribute("referid", (String) collectionDetails.get("collectionUri"));

    Element properties = type.addElement("properties");
    //add standard properties
    properties.addElement("collection").addText((String) collectionDetails.get("collectionUri"));

    //add user configured properties
    Map<String, String> items = userConfigMemory.get(domainid + ":" + userid);

    for (String item : items.keySet()) {
        if (item.equals("collectiontitle") || item.equals("collectiondescription")
                || item.equals("collectionstatus")) {
            properties.addElement(item).addText((String) collectionDetails.get(item));
        }
    }
    long timestamp = new Date().getTime();
    type.addAttribute("id", String.valueOf(timestamp));

    logger.debug("about to PUT to uri " + indexUri + " this xml: " + typeDocument.asXML());

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

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

License:Open Source License

/**
 * Create XML for an index/*  w  ww  .  j  a  v  a2s  .c om*/
 * 
 * @param objectUri
 * @param objectDetails
 * @param collectionDetails
 * @param iConfig
 */
private static void makeTypeFromObject(String objectUri, Map<String, Object> objectDetails,
        Map<String, Object> collectionDetails, IndexConfig iConfig) {
    Document typeDocument = DocumentHelper.createDocument();
    Element fsxml = typeDocument.addElement("fsxml");
    Element type = fsxml.addElement(iConfig.getIndexType());

    String objectType = iConfig.getIndexObject();

    // add refer to original object
    Element referObject = type.addElement(objectType);
    referObject.addAttribute("id", "1");
    referObject.addAttribute("referid", objectUri);

    //add refer to original collection, remove trailing slash, otherwise refer cannot be found!
    Element referCollectionObject = type.addElement("collection" + objectType);
    referCollectionObject.addAttribute("id", "1");
    String collectionObject = (String) collectionDetails.get("object");
    collectionObject = collectionObject.substring(0, collectionObject.length() - 1);
    referCollectionObject.addAttribute("referid", collectionObject);

    Element properties = type.addElement("properties");
    //add standard properties      
    properties.addElement(objectType).addText((String) collectionDetails.get("object"));
    properties.addElement(objectType + "uri").addText(objectUri + "/");
    properties.addElement(objectType + "title").addText((String) objectDetails.get(objectType + "title"));
    properties.addElement(objectType + "description")
            .addText((String) objectDetails.get(objectType + "description"));
    properties.addElement(objectType + "screenshot")
            .addText((String) objectDetails.get(objectType + "screenshot"));
    //properties.addElement(objectType+"type").addText((String) objectDetails.get(objectType+"type"));
    //properties.addElement(objectType+"author").addText((String) objectDetails.get(objectType+"author"));
    //properties.addElement(objectType+"copyright").addText((String) objectDetails.get(objectType+"copyright"));
    //properties.addElement(objectType+"website").addText((String) objectDetails.get(objectType+"website"));

    properties.addElement("collection").addText((String) collectionDetails.get("collection"));

    //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(objectType + "duration") || item.equals(objectType + "theme")
                || item.equals(objectType + "location") || item.equals(objectType + "date")
                || item.equals(objectType + "date_original") || item.equals(objectType + "public")
                || item.equals("sponsor")) {
            properties.addElement(item).addText((String) objectDetails.get(item));
        } else if (item.equals("title") || item.equals("name")) {
            properties.addElement(item).addText((String) objectDetails.get(objectType + "title"));
        } else if (item.equals("description")) {
            properties.addElement(item).addText((String) objectDetails.get(objectType + "description"));
        } else if (item.equals("screenshot")) {
            properties.addElement(item).addText((String) objectDetails.get(objectType + "screenshot"));
        } else if (item.equals("rank")) {
            properties.addElement(item).addText("5");
        } else if (item.equals("peercomments")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType),
                    "peercomments", 0.0, 86400000.0, new String[] { "comment" }));
        } else if (item.equals("bookmark")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "bookmark",
                    0.0, 86400000.0, new String[] { "title", "description", "creator" }));
        } else if (item.equals("webtv_item_id") || item.equals(objectType + "livestate")) {
            properties.addElement(item).addText((String) objectDetails.get(item));
        } else if (item.equals(objectType + "status") || item.equals(objectType + "theme")
                || item.equals(objectType + "time")) {
            properties.addElement(item).addText((String) objectDetails.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.GenericIndexAction.java

License:Open Source License

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

    String objectType = iConfig.getIndexObject();

    // add refer to original object
    Element referObject = type.addElement(objectType);
    referObject.addAttribute("id", "1");
    referObject.addAttribute("referid", objectUri);

    // add refer to original collection
    Element referCollectionObject = type.addElement("collection" + objectType);
    referCollectionObject.addAttribute("id", "1");
    String collectionObject = (String) collectionDetails.get("object");
    collectionObject = collectionObject.substring(0, collectionObject.length() - 1);
    referCollectionObject.addAttribute("referid", (String) collectionObject);

    Element properties = type.addElement("properties");
    //add standard properties
    properties.addElement(objectType).addText((String) collectionDetails.get("object"));
    properties.addElement(objectType + "uri").addText(objectUri + "/");
    properties.addElement("collection").addText((String) collectionDetails.get("collection"));
    properties.addElement(objectType + "title").addText((String) objectDetails.get(objectType + "title"));
    properties.addElement(objectType + "description")
            .addText((String) objectDetails.get(objectType + "description"));
    properties.addElement(objectType + "screenshot")
            .addText((String) objectDetails.get(objectType + "screenshot"));
    //properties.addElement(objectType+"type").addText((String) objectDetails.get(objectType+"type"));
    //properties.addElement(objectType+"author").addText((String) objectDetails.get(objectType+"author"));
    //properties.addElement(objectType+"copyright").addText((String) objectDetails.get(objectType+"copyright"));
    //properties.addElement(objectType+"website").addText((String) objectDetails.get(objectType+"website"));

    //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(objectType + "duration") || item.equals(objectType + "theme")
                || item.equals(objectType + "location") || item.equals(objectType + "date")
                || item.equals(objectType + "date_original") || item.equals(objectType + "public")
                || item.equals("sponsor")) {
            properties.addElement(item).addText((String) objectDetails.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) objectDetails.get(objectType),
                    start, (String) objectDetails.get(objectType + "screenshot")));
        } else if (item.equals("rank")) {
            properties.addElement(item)
                    .addText(String.valueOf(getRankBasedOnLockmode((String) objectDetails.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) objectDetails.get(objectType), "location",
                    start, duration, new String[] { "name" }));
        } else if (item.equals("dates")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "date", start,
                    duration, new String[] { "start", "end" }));
        } else if (item.equals("keywords")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "keyword",
                    start, duration, new String[] { "name" }));
        } else if (item.equals("persons")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "person",
                    start, duration, new String[] { "name" }));
        } else if (item.equals("periods")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "period",
                    start, duration, new String[] { "name" }));
        } else if (item.equals("speakers")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "speakers",
                    start, duration, new String[] { "firstname", "lastname", "organization" }));
        } else if (item.equals("topics")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "topics",
                    start, duration, new String[] { "name" }));
        } else if (item.equals("peercomments")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType),
                    "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(objectType + iConfig.getIndexType())) {
            properties.addElement(item).addText(getTypeUri(typeContent, objectUri, iConfig));
        } else if (item.equals("bookmark")) {
            properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "bookmark",
                    0.0, 86400000.0, new String[] { "title", "description", "creator" }));
        } else if (item.equals("webtv_item_id") || item.equals(objectType + "livestate")) {
            properties.addElement(item).addText((String) objectDetails.get(item));
        } else if (item.equals(objectType + "status") || item.equals(objectType + "theme")
                || item.equals(objectType + "time") || item.equals(objectType + "type")) {
            properties.addElement(item).addText((String) objectDetails.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.GenericIndexQueueAction.java

License:Open Source License

private void addJob(String objectUri, String eventUri) {
    /* only add valid object */
    if (objectUri.startsWith("/")) {
        long timestamp = new Date().getTime();

        Document xml = DocumentFactory.getInstance().createDocument();
        Element fsxml = xml.addElement("fsxml");
        Element properties = fsxml.addElement("properties");
        properties.addElement(type).addText(objectUri);
        properties.addElement("priority").addText(String.valueOf(getPriority(eventUri)));
        properties.addElement("timestamp").addText(String.valueOf(timestamp));
        properties.addElement("type").addText(type);
        Element object = fsxml.addElement(type);
        object.addAttribute("id", "1");
        object.addAttribute("referid", objectUri);

        logger.debug(xml.asXML());/*from w  w w  . ja v  a2  s  .c  om*/
        logger.debug(queueUri);

        FSXMLRequestHandler.instance().handlePOST(queueUri, xml.asXML());
    }
}

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   w w  w  . j a v  a  2s.  c  o  m*/
            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  av a  2s.  co  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/*  w w w .  j  a v a 2 s  . c  o 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 ww  w .  j a v  a  2  s  . c o  m
 * 
 * @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);
}