List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.flash.java
License:Open Source License
private static void handleIncludeExcludeNodes(Document conf, Document tmpConf) { List<Node> includeNodes = tmpConf .selectNodes("/fsxml/filesystem[@id='1']/*[@id and not(ends-with(@id,'_exclude'))]"); List<Node> excludeNodes = tmpConf.selectNodes("/fsxml/filesystem[@id='1']/*[ends-with(@id,'_exclude')]"); logger.debug("number of includeNodes = " + includeNodes.size()); for (int j = 0; j < includeNodes.size(); j++) { logger.debug(j + " = " + includeNodes.get(j).toString()); }/*from www. j a va 2 s. c o m*/ logger.debug("number of excludeNodes = " + excludeNodes.size()); for (int j = 0; j < excludeNodes.size(); j++) { logger.debug(j + " = " + excludeNodes.get(j).toString()); } Element base = (Element) conf.selectSingleNode("/fsxml/filesystem[@id='1']"); if (includeNodes != null) { for (int i = 0; i < includeNodes.size(); i++) { String nodename = includeNodes.get(i).getName(); String nodeid = includeNodes.get(i).valueOf("@id"); logger.debug("check if node exists " + nodename + " id " + nodeid); Node existingNode = base.selectSingleNode(nodename + "[@id='" + nodeid + "']"); if (existingNode != null) { logger.debug("node exists, replace"); List contentOfBase = base.content(); int index = contentOfBase.indexOf(existingNode); contentOfBase.set(index, includeNodes.get(i).detach()); } else { base.add(includeNodes.get(i).detach()); } } } if (excludeNodes != null) { logger.debug("handling exclude nodes for user"); for (int i = 0; i < excludeNodes.size(); i++) { logger.debug("handling exclude node nr " + i); String nodename = excludeNodes.get(i).getName(); String nodeid = excludeNodes.get(i).valueOf("@id"); nodeid = nodeid.substring(0, nodeid.lastIndexOf("_exclude")); logger.debug("about to exclude " + nodename + " with id " + nodeid); Node remove = base.selectSingleNode(nodename + "[@id='" + nodeid + "']"); if (remove != null) { logger.debug("node to exclude found, detach"); remove.detach(); } } } }
From source file:com.noterik.bart.fs.fscommand.dynamic.video.playout.flash.java
License:Open Source License
public synchronized String run(String uri, String xml) { logger.debug("start dynamic/video/playout/flash"); Document returnXml = DocumentHelper.createDocument(); Element fsxml = returnXml.addElement("fsxml"); fsxml.addElement("properties"); String domain = URIParser.getDomainIdFromUri(uri); String user = URIParser.getUserIdFromUri(uri); String selectedplaylist = ""; Element handlerparams = null; config conf = new config(domain, user, selectedplaylist, handlerparams); Document videoProperties = cache.get(uri); if (videoProperties == null) { videoProperties = FSXMLRequestHandler.instance().getNodeProperties(uri, false); if (videoProperties == null) { return FSXMLBuilder.getErrorMessage("404", "Video not found", "You have to supply an existing video", "http://teamelements.noterik.nl/team"); }/*from w w w . jav a 2s . c om*/ cache.put(uri, videoProperties); } Node videoXml = getVideo(uri); fsxml.add(videoXml); Node videoConfig = getVideoConfig(uri, videoXml, conf); //add fake presentation as placeholder for the video Element presentation = addPlaceholderPresentation(uri); fsxml.add(presentation); if (videoConfig != null) { fsxml.add(videoConfig); logger.debug("past video config"); List<Element> players = addPlayer(videoConfig); for (int j = 0; j < players.size(); j++) { fsxml.add(players.get(j)); } } logger.debug("past adding player(s)"); return fsxml.asXML(); }
From source file:com.noterik.bart.fs.fscommand.ResolutionMetaCommand.java
License:Open Source License
private Element createMeta(String input) { String basePath = "/springfield/smithers/data/"; if (LazyHomer.isWindows()) { basePath = "c:\\springfield\\smithers\\data\\"; }/* w w w . j ava 2 s .co m*/ File srcFolder = new File(basePath + input); if (!srcFolder.exists()) return null; if (!srcFolder.isDirectory()) return null; File[] metafiles = srcFolder.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.equals(".") || name.equals("..")) { return false; } if (name.toUpperCase().endsWith(".META")) { return true; } return false; } }); Element metanode = DocumentHelper.createElement("resolutionmeta"); // set the id and aim it to our original video metanode.addAttribute("id", "1"); // create the properties and set them (this can be done easer?) Element p = DocumentHelper.createElement("properties"); Element dataunits = DocumentHelper.createElement("dataunits"); //Element availableinputs = DocumentHelper.createElement("inputs"); String body = "<![CDATA["; String sep = ""; body += "{"; for (int i = 0; i < metafiles.length; i++) { File f = metafiles[i]; Properties meta = readMetaFile(f); String filename = f.getName(); String name = filename.substring(0, filename.lastIndexOf(".")); if (meta.getProperty("startmeasurement") != null) { body += sep + "\"" + name + "\" : { \"name\" : \"" + meta.getProperty("name") + "\", \"unit\" : \"" + meta.getProperty("unit") + "\", \"startmeasurement\" : \"" + meta.getProperty("startmeasurement") + "\", \"endmeasurement\" : \"" + meta.getProperty("endmeasurement") + "\"}"; } else { body += sep + "\"" + name + "\" : { \"name\" : \"" + meta.getProperty("name") + "\", \"unit\" : \"" + meta.getProperty("unit") + "\"}"; } sep = ","; } body += "}"; body += "]]>"; dataunits.setText(body); body = ""; sep = ""; for (inputs val : inputs.values()) { body += sep + val; sep = ","; } //availableinputs.setText(body); //p.add(availableinputs); p.add(dataunits); // add the properties to the video node so it plays just that part. metanode.add(p); return metanode; }
From source file:com.noterik.bart.fs.fscommand.ResolutionMetaCommand.java
License:Open Source License
private Element createMeta(String sbfFile, inputs input) { SBFReader sbfr = new SBFReader(sbfFile); Element metanode = DocumentHelper.createElement("resolutionmeta"); // set the id and aim it to our original video metanode.addAttribute("id", "1"); // create the properties and set them (this can be done easer?) Element p = DocumentHelper.createElement("properties"); Element dataunits = DocumentHelper.createElement("dataunits"); Element availableinputs = DocumentHelper.createElement("inputs"); String body = ""; SBFile dataFile = sbfr.getDataFile(); int cols = (int) dataFile.getColumnCount(); String sep = ""; body += "{";//from w w w . ja va2 s .c o m for (int i = 1; i < cols; i++) { body += sep + "\"" + input + "_" + Integer.toString(i) + "\" : { \"name\" : \"" + dataFile.getDataColumns(i) + "\", \"unit\" : \"" + dataFile.getUnitColumns(i) + "\"}"; sep = ","; } body += "}"; sbfr = null; dataunits.setText(body); body = ""; sep = ""; for (inputs val : inputs.values()) { body += sep + val; sep = ","; } availableinputs.setText(body); p.add(availableinputs); p.add(dataunits); // add the properties to the video node so it plays just that part. metanode.add(p); return metanode; }
From source file:com.noterik.bart.fs.ingest.IngestHandler.java
License:Open Source License
public String ingestVideo(String uri, String domain, String xml) { String response = null;// w w w . j a v a 2 s .c o m String origin = ""; String destination = ""; // get the settings file to see what to do with this video ingest String domIngest = "/domain/" + domain + "/settings/ingest"; String ingest = PropertyHandler.getXMLfromProp(domIngest); // determine the path to the video file String fileName = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DATA); String extension = fileName.substring(fileName.lastIndexOf(".") + 1); origin = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/video/basedir") + uri + "/" + fileName; // where to store the video in the file system String url = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DESTINATION); String rawIndex = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_RAW_INDEX); String dest = url + "/rawvideo/1"; // whether to store in the old FS (b10) or the new one (use ftp) if (XmlHelper.useFtp(ingest, "video")) { String backupMount = null; String mount = null; String collection = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_COLLECTION); String offPath = "/fsxml/properties/video/ftp/offset"; String servPath = "/fsxml/properties/video/ftp/servers"; String prefPath = "/fsxml/properties/video/ftp/prefix"; String sufPath = "/fsxml/properties/video/ftp/suffix"; String mtnPath = "/fsxml/properties/video/ftp/mount"; String offset = XmlHelper.getValueFromIngest(ingest, offPath); String servers = XmlHelper.getValueFromIngest(ingest, servPath); String prefix = XmlHelper.getValueFromIngest(ingest, prefPath); String suffix = XmlHelper.getValueFromIngest(ingest, sufPath); String mountprf = XmlHelper.getValueFromIngest(ingest, mtnPath); int servs = Integer.valueOf(servers); int offs = Integer.valueOf(offset); if (extension.toLowerCase().equals("flv")) { dest = url + "/rawvideo/1"; } else { dest = url + "/rawvideo/2"; } // if the rawindex is specified in the request xml, put the video at // this rawvideo index if (rawIndex != null) { dest = rawIndex.equals("") ? dest : url + "/rawvideo/" + rawIndex; } logger.debug("Copying file to new FS (using FTP) into: " + dest + " rawindex(" + rawIndex + ")"); int sid = getFTPServerIdForCollectionVideo(url, collection, servs, offs); if (sid != -1) { int bid = getBackupFTPServerId(sid, servs, offs); String sHostBase = prefix + sid; String bHostBase = prefix + bid; String ftpServer = sHostBase + suffix; String backupFtpServer = bHostBase + suffix; logger.debug("FTP SERVER: " + ftpServer); logger.debug("BACKUP FTP SERVER: " + backupFtpServer); logger.debug("INPUT FILE: " + origin); logger.debug("DESTINATION: " + dest); if (FtpHelper.sendFileWithFtp(origin, dest, ftpServer, sHostBase, sHostBase, false)) { mount = mountprf + sid; } if (FtpHelper.sendFileWithFtp(origin, dest, backupFtpServer, bHostBase, bHostBase, true)) { backupMount = mountprf + bid; } if (mount == null && backupMount == null) { response = FSXMLBuilder.getErrorMessage( "500", "Could not transfer the ingest file to the FS", "The file: " + origin + " could not be sent to either: " + sHostBase + " or " + bHostBase, "http://teamelements.noterik.com/team"); } } else { response = FSXMLBuilder.getErrorMessage("500", "Invalid destination URL parameter", "The destination URL: " + url + " is invalid", "http://teamelements.noterik.com/team"); } if (response == null) { logger.debug("response was null, properties will be set now !!"); String properties = XmlHelper.getPropsFromXml(xml); String type = "rawvideo"; if (mount != null || backupMount != null) { String m = mount; if (backupMount != null) { m = m == null ? backupMount : m + "," + backupMount; } properties = XmlHelper.setMountProperty(properties, m); } logger.debug("xml before Flanders is: " + properties); // update the properties with information from flanders properties = FlandersHelper.processRaw(dest, properties); logger.debug("xml after Flanders is: " + properties); // add the properties to data base PropertyHandler.saveProperties(dest, type, properties); response = FSXMLBuilder.getStatusMessage("The file was succesfully ingested into the FS", "", ""); } else { logger.error(response); } } else { String transPath = "/fsxml/properties/transcode"; String transcode = XmlHelper.getValueFromIngest(ingest, transPath); logger.debug("Copying file to FS on b10 (old file system)"); destination = GlobalConfig.instance().getIngestBaseDir() + dest + "/raw." + extension; if (!FileHelper.copyFile(origin, destination)) { response = FSXMLBuilder.getErrorMessage("500", "Could not transfer the ingest file to the old (b10) FS", "The file: " + origin + " could not be sent to the old (b10) FS", "http://teamelements.noterik.com/team"); } else { // file was copied successfully, now setting properties String type = "rawvideo"; String properties = XmlHelper.getPropsFromXml(xml); logger.debug("xml before Flanders is: " + properties); // update the properties with information from flanders properties = FlandersHelper.processRaw(dest, properties); logger.debug("xml after Flanders is: " + properties); PropertyHandler.saveProperties(dest, type, properties); } // creating unhappy files if (transcode.equals("true")) { String type = "rawvideo"; List<Element> elems = XmlHelper.getRaws(ingest, "video"); if (elems.size() != 0) { Iterator<Element> it = elems.iterator(); Element elem = null; while (it.hasNext()) { elem = it.next(); String id = elem.attributeValue("id"); Element propsElem = (Element) elem.selectSingleNode("/properties"); Element fsxml = DocumentHelper.createElement("fsxml"); fsxml.add((Element) propsElem.clone()); String props = fsxml.asXML(); url = uri + "/rawvideo/" + id; PropertyHandler.saveProperties(url, type, props); } } String newUrl = url.substring(1); String TEFurl = "http://cw2.noterik.com:10001/domain/emails/fsorders"; String finalUrl = TEFurl + "?res=" + newUrl; HttpHelper.sendRequest("GET", finalUrl, null, null); } } return response; }
From source file:com.noterik.bart.fs.ingest.IngestHandler.java
License:Open Source License
public String ingestImage(String uri, String domain, String xml) { logger.debug("Processing image ingest..."); String domIngest = "/domain/" + domain + "/settings/ingest"; String ingest = PropertyHandler.getXMLfromProp(domIngest); String origin = ""; String fileName = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DATA); String extension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); origin = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/basedir") + uri + "/" + fileName; String url = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DESTINATION); String dest = url + "/rawimage/1"; String response = null;/*from w w w . j ava 2s. com*/ String type = "rawimage"; String imagePath = ""; String prefix = ""; String suffix = ""; String user = ""; String pass = ""; String server = ""; String backImagePath = ""; String backServer = ""; String backUser = ""; String backPass = ""; String mount = null; String backMount = null; boolean useFtp = XmlHelper.useFtp(ingest, "image"); if (useFtp) { String prefixPath = "/fsxml/properties/image/ftp/prefix"; String suffixPath = "/fsxml/properties/image/ftp/suffix"; String userPath = "/fsxml/properties/image/ftp/user"; String passPath = "/fsxml/properties/image/ftp/pass"; prefix = XmlHelper.getValueFromIngest(ingest, prefixPath); suffix = XmlHelper.getValueFromIngest(ingest, suffixPath); user = XmlHelper.getValueFromIngest(ingest, userPath) + "1"; pass = XmlHelper.getValueFromIngest(ingest, passPath) + "1"; imagePath = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/ftp/path") + "1"; server = prefix + "1" + suffix; backServer = prefix + "2" + suffix; backUser = XmlHelper.getValueFromIngest(ingest, userPath) + "2"; backPass = XmlHelper.getValueFromIngest(ingest, passPath) + "2"; backImagePath = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/ftp/path") + "2"; } else { imagePath = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/basedir"); } String newDest = imagePath + dest; String backNewDest = backImagePath + dest; List<Element> elems = XmlHelper.getRaws(ingest, "image"); logger.debug("NUMBER OF RAWS: " + elems.size()); if (elems.size() != 0) { Iterator<Element> it = elems.iterator(); while (it.hasNext()) { Element elem = (Element) it.next().clone(); String id = elem.attributeValue("id"); String thumbDest = url + "/rawimage/" + id; logger.debug("ELEMENT FOUND:\n\n" + elem.asXML()); Element propsElem = (Element) elem.selectSingleNode("./properties"); logger.debug("PROPS ELEMENT:\n" + propsElem.asXML()); if (propsElem != null) { String width = propsElem.selectSingleNode("./width").getText(); String heigth = propsElem.selectSingleNode("./height").getText(); int tWidth = Integer.valueOf(width); int tHeight = Integer.valueOf(heigth); String onlyName = fileName.substring(0, fileName.indexOf(".")); String thumbLocation = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/basedir") + uri + "/thumb" + onlyName + ".jpg"; if (createThumb(tWidth, tHeight, origin, thumbLocation)) { Element fsxml = DocumentHelper.createElement("fsxml"); fsxml.add((Element) propsElem.clone()); if (useFtp) { //send to images1 String thumbNewDest = imagePath + thumbDest; logger.debug("FTP HOST: " + server); logger.debug("INPUT FILE: " + thumbLocation); logger.debug("DESTINATION: " + thumbNewDest); if (FtpHelper.sendFileWithFtp(thumbLocation, thumbNewDest, server, user, pass, false)) { mount = "images1"; } //send to images2 String backThumbDest = backImagePath + thumbDest; logger.debug("FTP HOST: " + backServer); logger.debug("INPUT FILE: " + thumbLocation); logger.debug("DESTINATION: " + backThumbDest); if (FtpHelper.sendFileWithFtp(thumbLocation, backThumbDest, backServer, backUser, backPass, true)) { backMount = "images2"; } String props = fsxml.asXML(); if (mount != null || backMount != null) { String m = mount; if (backMount != null) { m = m == null ? backMount : m + "," + backMount; } props = XmlHelper.setMountProperty(props, m); } PropertyHandler.saveProperties(thumbDest, type, props); } else { String thumbNewDest = imagePath + thumbDest; if (!FileHelper.copyFile(thumbLocation, thumbNewDest)) { response = FSXMLBuilder.getErrorMessage("500", "Could not transfer the ingest file to the old (b10) FS", "The file: " + origin + " could not be sent to the old (b10) FS", "http://teamelements.noterik.com/team"); } else { String props = fsxml.asXML(); PropertyHandler.saveProperties(thumbDest, type, props); } } } else { logger.error("There was an error creating thumbnail " + id); } } else { logger.error("The ingest settings xml is not properly configured"); } } } if (useFtp) { //send to images1 logger.debug("FTP HOST: " + server); logger.debug("INPUT FILE: " + origin); logger.debug("DESTINATION: " + newDest); if (FtpHelper.sendFileWithFtp(origin, newDest, server, user, pass, false)) { mount = "images1"; } //send to images2 logger.debug("FTP HOST: " + backServer); logger.debug("INPUT FILE: " + origin); logger.debug("DESTINATION: " + backNewDest); if (FtpHelper.sendFileWithFtp(origin, backNewDest, backServer, backUser, backPass, true)) { backMount = "images2"; } String props = "<fsxml>" + "<properties>" + "<extension>" + extension + "</extension></properties>" + "</fsxml>"; if (mount != null || backMount != null) { String m = mount; if (backMount != null) { m = m == null ? backMount : m + "," + backMount; } props = XmlHelper.setMountProperty(props, m); } PropertyHandler.saveProperties(dest, type, props); } else { if (!FileHelper.copyFile(origin, newDest)) { response = FSXMLBuilder.getErrorMessage("500", "Could not transfer the ingest file to the old (b10) FS", "The file: " + origin + " could not be sent to the old (b10) FS", "http://teamelements.noterik.com/team"); } else { String prop = "<fsxml>" + "<properties>" + "<extension>" + extension + "</extension>" + "</properties>" + "</fsxml>"; PropertyHandler.saveProperties(dest, type, prop); } } return response; }
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/* www . ja v a2 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/*from w w w . j a v a 2 s . co 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.XmlHelper.java
License:Open Source License
/** * This function returns a Document with the value of the property set by * path/*w w w . j a v a 2s. c o m*/ * * @param xml * String containing the property file * @param path * The path for the desired value * @return Document with the value of the property */ public static Document getValueOfProperty(String xml, String path) { String xpath = "/fsxml/" + path; Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } Element elem = (Element) doc.selectSingleNode(xpath).clone(); Document newDoc = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("fsxml"); newDoc.setRootElement(root); Element fsxml = (Element) newDoc.selectSingleNode("/fsxml"); fsxml.add(elem); return newDoc; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
/** * This function will extract the props part of the xml String * passed as parameter and return it as fsxml compatible properties. * * If the node is not found, a default (empty) node will be returned * * @param xml/*w w w .j av a 2 s . c o m*/ * @return */ public static String getPropsFromXml(String xml) { String props = "<fsxml>" + "<properties>" + "</properties>" + "</fsxml>"; Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { logger.error("", e); } Element properties = (Element) doc.selectSingleNode("/fsxml/ingest/props/properties").clone(); if (properties != null) { Document newDoc = DocumentHelper.createDocument(); Element fsxml = (Element) newDoc.addElement("fsxml"); fsxml.add(properties); props = fsxml.asXML(); } return props; }