List of usage examples for org.dom4j Element addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:com.noterik.bart.fs.action.FlandersAction.java
License:Open Source License
private String processXml(String original, String flanders) { String xml = ""; Map<String, String> values = new HashMap<String, String>(); Document origdoc = null;//from www . j a v a 2 s .c om Document flandoc = null; try { origdoc = DocumentHelper.parseText(original); flandoc = DocumentHelper.parseText(flanders); } catch (DocumentException e) { logger.error("", e); } Element origProp = (Element) origdoc.selectSingleNode("//properties"); Iterator i = origProp.elementIterator(); while (i.hasNext()) { Element prop = (Element) i.next(); String name = prop.getName(); String value = prop.getText(); values.put(name, value); } logger.debug("\n flandProp = " + flandoc.asXML()); Element flandProp = (Element) flandoc.selectSingleNode("/meta-data"); Iterator j = flandProp.elementIterator(); while (j.hasNext()) { Element prop = (Element) j.next(); String name = prop.getName(); String value = prop.getText(); //For marin there metadata is leading if (values.containsKey("mount") && values.get("mount").toLowerCase().equals("marin")) { if (!values.containsKey(name)) { values.put(name, value); } } else { values.put(name, value); } } Element finalEl = DocumentHelper.createElement("fsxml"); Element propsEl = finalEl.addElement("properties"); Iterator<String> it = values.keySet().iterator(); while (it.hasNext()) { String name = it.next(); String value = values.get(name); propsEl.addElement(name).addText(value); } xml = finalEl.asXML(); return xml; }
From source file:com.noterik.bart.fs.action.GenericIndexAction.java
License:Open Source License
/** * Create XML for an index// ww w. j ava 2s.c o m * * @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/* ww w. j ava 2s . co 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 ww w. j ava2 s .com*/ 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 . ja v a 2 s .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 ww w . ja va2 s . c om*/ 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 ww w .j av a2 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// ww w . ja 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); }
From source file:com.noterik.bart.fs.action.PresentationIndexQueueAction.java
License:Open Source License
private void addJob(String presentationUri, String eventUri) { /* only add valid presentations */ if (presentationUri.startsWith("/")) { long timestamp = new Date().getTime(); Document xml = DocumentFactory.getInstance().createDocument(); Element fsxml = xml.addElement("fsxml"); Element properties = fsxml.addElement("properties"); properties.addElement("presentation").addText(presentationUri); properties.addElement("priority").addText(String.valueOf(getPriority(eventUri))); properties.addElement("timestamp").addText(String.valueOf(timestamp)); Element presentation = fsxml.addElement("presentation"); presentation.addAttribute("id", "1"); presentation.addAttribute("referid", presentationUri); logger.debug(xml.asXML());//w w w.j a v a 2s . co m logger.debug(queueUri); FSXMLRequestHandler.instance().handlePOST(queueUri, xml.asXML()); } }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.TimeLine.java
License:Open Source License
public void remapOldEvents() { Element pl = (Element) _presentation.selectSingleNode("videoplaylist"); //System.out.println("PLNODE="+pl); float offset = 0; int mapcounter = 0; for (Iterator<Node> iter = pl.elements().iterator(); iter.hasNext();) { Element node = (Element) iter.next(); if (node.getName().equals("video")) { //System.out.println("V1="+node.asXML()); float starttime = 0; if (node.selectSingleNode("properties/starttime") != null && !node.selectSingleNode("properties/starttime").getText().equals("")) { starttime = Float.valueOf(node.selectSingleNode("properties/starttime").getText()); }/* w w w.j a v a 2s .co m*/ float duration = 999999999; // a bit of a hack if (node.selectSingleNode("properties/duration") != null && !node.selectSingleNode("properties/duration").getText().equals("")) { duration = Float.valueOf(node.selectSingleNode("properties/duration").getText()); } for (Iterator<Node> viter = oldnodes.iterator(); viter.hasNext();) { Element lnode = (Element) viter.next(); String name = lnode.getName(); if (!name.equals("properties") && !name.equals("rawvideo") && !name.equals("screens")) { // so we have a node lets remap it and place it in the timeline Element nnode = (Element) lnode.clone(); float ns = 0L; float nd = 0L; if (nnode.selectSingleNode("properties/starttime") != null && nnode.selectSingleNode("properties/starttime").getText() != null) { try { ns = Float.valueOf(nnode.selectSingleNode("properties/starttime").getText()); } catch (Exception e) { //System.out.println("NS="+nnode.selectSingleNode("properties/starttime").getText()); //e.printStackTrace(); } } else { Element nnnode = (Element) nnode.selectSingleNode("//properties"); nnnode.addElement("starttime").addText(Float.toString(ns)); } if (nnode.selectSingleNode("properties/duration") != null && nnode.selectSingleNode("properties/duration").getText() != null) { try { nd = Float.valueOf(nnode.selectSingleNode("properties/duration").getText()); } catch (Exception e) { /* ignore */ } } else { Element nnnode = (Element) nnode.selectSingleNode("//properties"); nnnode.addElement("duration").addText(Float.toString(nd)); } // is this block used in this video's start/duration range ? if ((ns >= starttime && ns <= (starttime + duration)) || ((ns + nd) > starttime)) { // we need to shift the starttime by both the offset and starttime // does the end point also fall in the range, if not we need to shorten it float newstart = ((ns - starttime) + offset); /* Daniel/Pieter removed because not sure what it did, first check if trouble. if(((ns+nd)>starttime)) { newstart = starttime + offset; } */ if ((ns + nd) < (starttime + duration)) { // yes no need to cut nnode.selectSingleNode("properties/starttime").setText("" + newstart); } else { //System.out.println("LN="+lnode.getName()+" "+lnode.asXML()); //System.out.println("NEED CUT "+ns+" "+nd+" "+starttime+" "+duration+" "+newstart); //System.out.println("NEW DUR "+(nd-((ns+nd)-(starttime+duration)))); nnode.selectSingleNode("properties/starttime").setText("" + newstart); nnode.selectSingleNode("properties/duration") .setText("" + (nd - ((ns + nd) - (starttime + duration)))); } newnodes.add(nnode); mapcounter++; } } } offset += duration; // shift the offset so all the events of the next video are shifted } } //System.out.println("MAPCOUNTER OLD="+mapcounter); }