List of usage examples for org.dom4j Document 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.GenericIndexAction.java
License:Open Source License
/** * Create XML for an index/*from w w w .ja va 2 s . c om*/ * * @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 a v a 2 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 www . jav a 2 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. jav a 2 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// w w w . ja v a 2s.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 ww .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); }
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());/*from ww w . ja v a 2 s . c o m*/ logger.debug(queueUri); FSXMLRequestHandler.instance().handlePOST(queueUri, xml.asXML()); } }
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 w w . j a v a2 s . 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 ww w.j a v a 2 s. co m*/ 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; }