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.fscommand.dynamic.presentation.playout.flash.java
License:Open Source License
public synchronized String run(String uri, String xml) { logger.debug("start dynamic/presentation/playout/flash"); logger.debug("qpr url=" + uri); long timer_start = new Date().getTime(); Document returnXml = DocumentHelper.createDocument(); Element fsxml = returnXml.addElement("fsxml"); fsxml.addElement("properties"); String domain = URIParser.getDomainIdFromUri(uri); String user = URIParser.getUserIdFromUri(uri); String selectedplaylist = ""; Element handlerparams = null; int pos = xml.indexOf("<virtualpath>"); if (pos != -1) { selectedplaylist = xml.substring(pos + 13 + 14); pos = selectedplaylist.indexOf("</virtualpath>"); if (pos != -1) { selectedplaylist = selectedplaylist.substring(0, pos); try { handlerparams = (Element) DocumentHelper.parseText(xml).getRootElement(); } catch (Exception docerror) { logger.error("invalid parameters in xml"); }//from w ww . j a v a 2 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. ja v a 2s. c o 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; }
From source file:com.noterik.bart.fs.fscommand.ShowSponsorsCommand.java
License:Open Source License
public String execute(String uri, String xml) { int numSponsors = 0; Element user;/* w w w .j av a 2s . c o m*/ Document typeDocument = DocumentHelper.createDocument(); Element fsxml = typeDocument.addElement("fsxml"); Element properties = fsxml.addElement("properties"); String domain = URIParser.getDomainFromUri(uri); String userUri = "/domain/" + domain + "/user"; Document userDoc = FSXMLRequestHandler.instance().getNodePropertiesByType(userUri, 0, 0, 999999); List<Node> users = userDoc.selectNodes("//user"); logger.debug("# of users = " + users.size()); //loop over all users of domain for (Iterator<Node> iter = users.iterator(); iter.hasNext();) { user = (Element) iter.next(); String userid = user.selectSingleNode("@id") == null ? "" : user.selectSingleNode("@id").getText(); logger.debug("user = " + userid); String sponsorUri = "/domain/" + domain + "/user/" + userid + "/sponsor"; Document sponsor = FSXMLRequestHandler.instance().getNodePropertiesByType(sponsorUri, 0, 0, 1); int sponsorItems = sponsor.selectSingleNode("//totalResultsAvailable") == null ? 0 : Integer.parseInt(sponsor.selectSingleNode("//totalResultsAvailable").getText()); if (sponsorItems > 0) { logger.debug(userid + " sponsors " + sponsorItems); numSponsors++; fsxml.addElement("sponsor").addAttribute("id", userid); } } properties.addElement("totalResultsAvailable").addText(Integer.toString(numSponsors)); return typeDocument.asXML(); }
From source file:com.noterik.bart.fs.ingest.SimpleIngestHandler.java
License:Open Source License
private String saveVideoProperties(EncodingProfile ep, IngestInputData iid, String domain, String rawIndex) { String destUri = null;// w w w .java 2s . c o m String vidUri = "/domain/" + domain + "/user/" + iid.getUser() + "/video"; if (iid.getVideoId() == null) { String vidXml = "<fsxml><properties></properties></fsxml>"; logger.debug("ADD(" + vidUri + ") " + vidXml); int id = IdHandler.instance().insert(vidUri); vidUri += "/" + id; logger.debug("VID URI AFTER: " + vidUri); FSXMLRequestHandler.instance().saveFsXml(vidUri, vidXml, "POST", true); } else { vidUri += "/" + iid.getVideoId(); } destUri = vidUri + "/rawvideo/" + rawIndex; logger.debug("DEST URI BECOMES: " + destUri); String rawXml = FSXMLBuilder.getVideoPropertiesFromProfile(ep); // add original filename try { String originalFilename = iid.getSource(); originalFilename = originalFilename.substring(originalFilename.lastIndexOf("/") + 1); Document doc = DocumentHelper.parseText(rawXml); Element properties = (Element) doc.selectSingleNode("//properties"); Element oName = properties.addElement("original-filename"); oName.setText(originalFilename); rawXml = doc.asXML(); } catch (Exception e) { logger.error("Caught Exception: " + e.getMessage()); } logger.debug("ADD(" + rawXml + ") " + destUri); FSXMLRequestHandler.instance().saveFsXml(destUri + "/properties", rawXml, "PUT", true); return destUri; }
From source file:com.noterik.bart.fs.legacy.properties.PropertyHandler.java
License:Open Source License
/** * this function creates the Document where the properties will be saved in * and the first element to put in it. Then it calls the loopInIt. * * @param uri//from w w w . ja v a 2s. com * @return */ public static String getProperties(String uri) { int count = 0; String xmlProps = ""; if (hasProperties(uri)) { List<String> uris = new ArrayList<String>(); uris.add(uri); String id = uri.substring(uri.lastIndexOf("/") + 1); Document doc = DocumentHelper.createDocument(); String type = getTypefromProp(uri); Element root = doc.addElement("fsxml"); Element current = root.addElement(type).addAttribute("id", id); doc = loopInIt(doc, current, uri, count, uris); xmlProps = doc.asXML(); } return xmlProps; }
From source file:com.noterik.bart.fs.legacy.properties.PropertyHandler.java
License:Open Source License
/** * This function will walk trough all children of a given uri and add it's * properties to the Document passed as parameter. The counter sets the * number of levels it should go into//from w w w . j a va 2 s . co m * * @param doc * @param current * @param uri * @param count * @return */ public static Document loopInIt(Document doc, Element current, String uri, int count, List uris) { // the depth level it should go into if (count < 10) { count++; String xml = getXMLfromProp(uri); if (!xml.equals("")) { xml = unwrapXml(xml); } Element elem = null; // if xml is not empty add the node if (!xml.equals("")) { try { elem = (Element) DocumentHelper.parseText(xml).getRootElement().clone(); } catch (DocumentException e) { e.printStackTrace(); } current.add(elem); } else { // if it is empty, just add an empty node current.addElement("properties"); } String childUri = ""; String childId = ""; String childType = ""; // get the children for this uri (refer_uris) Map<String, Props> childs = getChildrenOfUri(uri); Iterator<String> it = childs.keySet().iterator(); // for each children do the loop while (it.hasNext()) { childUri = it.next(); // check if this uri was already processed if (!uris.contains(childUri)) { uris.add(childUri); childId = childs.get(childUri).getId(); childType = childs.get(childUri).getType(); Element newElem = current.addElement(childType).addAttribute("id", childId); doc = loopInIt(doc, newElem, childUri, count, uris); } } } return doc; }
From source file:com.noterik.bart.fs.legacy.properties.PropertyHandler.java
License:Open Source License
/** * This function will get the properties of a uri only, and not of it's * childs/* ww w .ja v a 2 s . c o m*/ * * @param uri * @return */ public static Document getPropsNoChilds(String uri) { String url = uri.substring(0, uri.lastIndexOf("/")); logger.debug("url is:" + url); Document doc = DocumentHelper.createDocument(); String id = url.substring(url.lastIndexOf("/") + 1); String type = getTypefromProp(url); Element root = doc.addElement("fsxml"); Element current = root.addElement(type).addAttribute("id", id); String xml = getXMLfromProp(url); Element elem = null; // if xml is not empty, unwrapp it and add the node if (!xml.equals("")) { xml = unwrapXml(xml); try { elem = (Element) DocumentHelper.parseText(xml).getRootElement().clone(); } catch (DocumentException e) { e.printStackTrace(); } current.add(elem); } else { // if it is empty, just add an empty node current.addElement("properties"); } return doc; }
From source file:com.noterik.bart.fs.legacy.tools.FlandersHelper.java
License:Open Source License
private static String processXml(String original, String flanders) { String xml = ""; Map<String, String> values = new HashMap<String, String>(); Document origdoc = null;//from w ww . j a v a 2 s . com Document flandoc = null; try { origdoc = DocumentHelper.parseText(original); flandoc = DocumentHelper.parseText(flanders); } catch (DocumentException e) { LOG.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); } LOG.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(); 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.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will add a property with the specified value to the xml * passed as parameter//www . j a v a 2s. c om * * @param xml * @param property * @param value * @return */ public static String addPropertyValue(String xml, String property, String value) { Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } Element elem = (Element) doc.selectSingleNode("/fsxml/properties"); elem.addElement(property).addText(value); Element fsxml = (Element) doc.selectSingleNode("/fsxml"); xml = fsxml.asXML(); return xml; }