List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:com.nokia.helium.antlint.checks.CheckScriptDef.java
License:Open Source License
/** * Check against the given node.//from w w w .j a va 2 s. c o m * * @param node * is the node to check. */ @SuppressWarnings("unchecked") public void checkScriptDef(String name, Node node) { List<Node> statements = node.selectNodes("//scriptdef[@name='" + name + "']/attribute"); Pattern p1 = Pattern.compile("attributes.get\\([\"']([^\"']*)[\"']\\)"); Matcher m1 = p1.matcher(node.getText()); ArrayList<String> props = new ArrayList<String>(); while (m1.find()) { props.add(m1.group(1)); } if (!statements.isEmpty() && !props.isEmpty()) { for (Node statement : statements) { if (!props.contains(statement.valueOf("@name"))) { // for (String x : props) // log(x); log("Scriptdef " + name + " does not use " + statement.valueOf("@name")); } } } }
From source file:com.nokia.helium.antlint.checks.CheckScriptDefNameAttributes.java
License:Open Source License
/** * Check against the given node./*from w w w .ja v a2s . c o m*/ * * @param node * is the node to check. */ @SuppressWarnings("unchecked") public void checkScriptDefNameAttributes(String name, Node node) { List<Node> statements = node.selectNodes("//scriptdef[@name='" + name + "']/attribute"); Pattern p1 = Pattern.compile("attributes.get\\([\"']([^\"']*)[\"']\\)"); Matcher m1 = p1.matcher(node.getText()); ArrayList<String> props = new ArrayList<String>(); while (m1.find()) { props.add(m1.group(1)); } ArrayList<String> attributes = new ArrayList<String>(); for (Node statement : statements) { attributes.add(statement.valueOf("@name")); } for (String x : props) { if (!attributes.contains(x)) { log("Scriptdef " + name + " does not have attribute " + x); } } }
From source file:com.nokia.helium.antlint.checks.CheckScriptDefStyle.java
License:Open Source License
/** * Check against the given node./* w w w .j a v a 2 s . co m*/ * * @param node * is the node to check. */ @SuppressWarnings("unchecked") public void checkScriptDefStyle(String name, Node node) { List<Node> statements = node.selectNodes("//scriptdef[@name='" + name + "']/attribute"); Pattern p1 = Pattern.compile("attributes.get\\([\"']([^\"']*)[\"']\\)"); Matcher m1 = p1.matcher(node.getText()); ArrayList<String> props = new ArrayList<String>(); while (m1.find()) { props.add(m1.group(1)); } ArrayList<String> attributes = new ArrayList<String>(); for (Node statement : statements) { attributes.add(statement.valueOf("@name")); } if (!statements.isEmpty() && props.isEmpty()) { log("Scriptdef " + name + " doesn't reference attributes directly, poor style"); } }
From source file:com.nokia.helium.diamonds.DiamondsConfig.java
License:Open Source License
/** * Parses the general configuration info. * //from ww w .j a va2 s . c om * @param document * - XML config in DOM4J document */ private static void parseConfig(Document document) { log.debug("diamonds:DiamondsConfig:parsing general configuration."); Node node = document.selectSingleNode("//output-dir"); outputDir = node.valueOf("@path"); node = document.selectSingleNode("//template-dir"); templateDir = node.valueOf("@path"); }
From source file:com.nokia.helium.diamonds.DiamondsConfig.java
License:Open Source License
/** * Load diamonds property into hashmap./*from ww w . j a va 2s. c om*/ * @param doc * @param hash * @param name * @return */ public static void loadProperty(Document document, Map<String, String> hash, String name) { Node node = document.selectSingleNode("//property[@name='" + name + "']"); if (node == null) { throw new BuildException("diamonds: DiamondsConfig:'" + name + "' property definition is missing."); } hash.put(name, node.valueOf("@value")); }
From source file:com.noterik.bart.fs.action.GenericIndexAction.java
License:Open Source License
@SuppressWarnings("unchecked") private static String getObjectDuration(Document object) { Element video;/*w w w. ja va2s .c om*/ double videoDuration, totalDuration = 0.0; List<Node> videos = object.selectNodes("//video"); //check if special ordering is required if (object.selectSingleNode("//video/properties/position") != null) { videos = orderVideos(videos); } // Loop all videos for (Iterator<Node> iter = videos.iterator(); iter.hasNext();) { video = (Element) iter.next(); //videos without refer can occur, don't have properties if (video.element("properties") == null) { return "0"; } videoDuration = video.element("properties").elementText("duration") == null ? 0.0 : Double.parseDouble(video.element("properties").elementText("duration")); // if video does not contain duration it's not editted, take refers duration if (videoDuration == 0.0) { //get refer rawvideo 2 for duration in seconds Document videoNode = FSXMLRequestHandler.instance() .getNodeProperties(video.attributeValue("referid"), false); if (videoNode != null) { List<Node> rawvideos = videoNode.selectNodes("//rawvideo"); for (Node rawvideoNode : rawvideos) { String durationStr = rawvideoNode.valueOf("properties/duration"); try { videoDuration = Double.parseDouble(durationStr); } catch (Exception e) { /* ignored */} // check if video duration was set if (videoDuration != 0.0) { break; } } } } // TODO: take in/out points into account on duration totalDuration += videoDuration; } int duration = (int) Math.round(totalDuration); return Integer.toString(duration); }
From source file:com.noterik.bart.fs.action.PresentationIndexAction.java
License:Open Source License
@SuppressWarnings("unchecked") private static String getPresentationDuration(Document presentation) { Element video;//from www.jav a 2 s . co m double videoDuration, totalDuration = 0.0; List<Node> videos = presentation.selectNodes("//video"); //check if special ordering is required if (presentation.selectSingleNode("//video/properties/position") != null) { videos = orderVideos(videos); } // Loop all videos for (Iterator<Node> iter = videos.iterator(); iter.hasNext();) { video = (Element) iter.next(); //videos without refer can occur, don't have properties if (video.element("properties") == null) { return "0"; } videoDuration = video.element("properties").elementText("duration") == null ? 0.0 : Double.parseDouble(video.element("properties").elementText("duration")); // if video does not contain duration it's not editted, take refers duration if (videoDuration == 0.0) { //get refer rawvideo 2 for duration in seconds Document videoNode = FSXMLRequestHandler.instance() .getNodeProperties(video.attributeValue("referid"), false); if (videoNode != null) { List<Node> rawvideos = videoNode.selectNodes("//rawvideo"); for (Node rawvideoNode : rawvideos) { String durationStr = rawvideoNode.valueOf("properties/duration"); try { videoDuration = Double.parseDouble(durationStr); } catch (Exception e) { /* ignored */} // check if video duration was set if (videoDuration != 0.0) { break; } } } } // TODO: take in/out points into account on duration totalDuration += videoDuration; } int duration = (int) Math.round(totalDuration); return Integer.toString(duration); }
From source file:com.noterik.bart.fs.fscommand.CopyCommand.java
License:Open Source License
/** * Copy resource specified by the input parameters. * //from w ww . j a va2s .c o m * @param input input parameters * @param uri local directory * @return status/error message */ private String copy(Properties input, String uri) { String res = null; // get input parameters String source = input.getProperty("source"); String destination = input.getProperty("destination"); String params = input.getProperty("params"); logger.debug("source: " + source + ", destination: " + destination + ", params: " + params); //System.out.println("source: "+source+", destination: "+destination+", params: "+params); // determine optional parameters boolean recursive = false, override = false; if (params != null) { recursive = params.contains("-r"); override = params.contains("-o"); } // check input parameters if (source == null || destination == null) { return FSXMLBuilder.getErrorMessage("500", "No source or destination", "Please provide the SOURCE and DESTINATION input parameters", "http://teamelements.noterik.com/team"); } // resolve uris String sourceUri = URIParser.resolveLocalUri(source, uri); if (sourceUri.lastIndexOf("/") == sourceUri.length() - 1) { sourceUri = sourceUri.substring(0, sourceUri.lastIndexOf("/")); } String destinationUri = URIParser.resolveLocalUri(destination, uri); if (destinationUri.lastIndexOf("/") == destinationUri.length() - 1) { destinationUri = destinationUri.substring(0, destinationUri.lastIndexOf("/")); } logger.debug("ABSOLUTE URIS -- source: " + sourceUri + ", destination: " + destinationUri); // check if uri is an uri of type id String typeSource = URIParser.getResourceTypeFromUri(sourceUri); String cpDest = URIParser.getCurrentUriPart(destinationUri); if (!URIParser.isResourceId(sourceUri)) { return FSXMLBuilder.getErrorMessage("500", "Invalid source specified, only id nodes permitted.", "Invalid source specified, only id nodes permitted.", "http://teamelements.noterik.com/team"); } String docStr = null; String refer = null; if (recursive) { // get properties of source Document doc = getPropertiesOfUri(sourceUri, -1); logger.debug("document being created: " + doc.asXML()); // exception for first node Element root = doc.getRootElement(); Node first = root.selectSingleNode("//" + typeSource); refer = first.valueOf("@referid"); List<Node> children = first.selectNodes("child::*"); for (Iterator<Node> iter = children.iterator(); iter.hasNext();) { Node node = iter.next(); docStr += node.asXML(); } docStr = "<fsxml>" + docStr + "</fsxml>"; logger.debug("document being created after first node exception: " + docStr); } else { // get properties of source Document doc = getPropertiesOfUri(sourceUri, 0); logger.debug("document being created: " + doc.asXML()); // exception for first node Element root = doc.getRootElement(); Node first = root.selectSingleNode("//" + typeSource); Node properties = first.selectSingleNode("properties"); refer = first.valueOf("@referid"); docStr = "<fsxml>" + properties.asXML() + "</fsxml>"; logger.debug("document being created after first node exception: " + docStr); } // check if dest ends with 'properties' String newResourceUri = null; if (cpDest.equals(FSXMLHelper.XML_PROPERTIES)) { logger.debug("putting to " + destinationUri); res = rHandler.handlePUT(destinationUri, docStr); newResourceUri = URIParser.getParentUri(destinationUri); } else if (URIParser.isResourceId(destinationUri)) { destinationUri += "/" + FSXMLHelper.XML_PROPERTIES; logger.debug("putting to " + destinationUri); res = rHandler.handlePUT(destinationUri, docStr); newResourceUri = URIParser.getParentUri(destinationUri); } else { logger.debug("posting to " + destinationUri); res = rHandler.handlePOST(destinationUri, docStr); try { if (FSXMLParser.getErrorMessageFromXml(res) == null) { Document respDoc = DocumentHelper.parseText(res); newResourceUri = respDoc.valueOf("//uri"); } } catch (Exception e) { logger.error("", e); } } // add refer of first node if (refer != null && !refer.equals("")) { logger.debug("adding refer for first node (" + refer + ")"); boolean ok = rHandler.saveAttributes(newResourceUri, "<fsxml><attributes><referid>" + refer + "</referid></attributes></fsxml>", "PUT"); logger.debug("attributes added: " + ok); } else { logger.debug("not need for adding refer id"); } logger.debug("response: " + res); return res; }
From source file:com.noterik.bart.fs.fscommand.MoveCommand.java
License:Open Source License
/** * Move resource specified by the input parameters. * //w w w .jav a 2s . c o m * @param input input parameters * @param uri local directory * @return status/error message */ private String move(Properties input, String uri) { String res = null; // get input parameters String source = input.getProperty("source"); String destination = input.getProperty("destination"); String params = input.getProperty("params"); logger.debug("source: " + source + ", destination: " + destination + ", params: " + params); // determine optional parameters boolean override = false; if (params != null) { override = params.contains("-o"); } // check input parameters if (source == null || destination == null) { return FSXMLBuilder.getErrorMessage("500", "No source or destination", "Please provide the SOURCE and DESTINATION input parameters", "http://teamelements.noterik.com/team"); } // resolve uris String sourceUri = URIParser.resolveLocalUri(source, uri); if (sourceUri.lastIndexOf("/") == sourceUri.length() - 1) { sourceUri = sourceUri.substring(0, sourceUri.lastIndexOf("/")); } String destinationUri = URIParser.resolveLocalUri(destination, uri); if (destinationUri.lastIndexOf("/") == destinationUri.length() - 1) { destinationUri = destinationUri.substring(0, destinationUri.lastIndexOf("/")); } logger.debug("ABSOLUTE URIS -- source: " + sourceUri + ", destination: " + destinationUri); // check if uri is an uri of type id String typeSource = URIParser.getResourceTypeFromUri(sourceUri); String cpDest = URIParser.getCurrentUriPart(destinationUri); if (!URIParser.isResourceId(sourceUri)) { return FSXMLBuilder.getErrorMessage("500", "Invalid source specified, only id nodes permitted.", "Invalid source specified, only id nodes permitted.", "http://teamelements.noterik.com/team"); } String docStr = null; String refer = null; // get properties of source Document doc = getPropertiesOfUri(sourceUri, -1); logger.debug("document being created: " + doc.asXML()); // exception for first node Element root = doc.getRootElement(); Node first = root.selectSingleNode("//" + typeSource); refer = first.valueOf("@referid"); List<Node> children = first.selectNodes("child::*"); for (Iterator<Node> iter = children.iterator(); iter.hasNext();) { Node node = iter.next(); docStr += node.asXML(); } docStr = "<fsxml>" + docStr + "</fsxml>"; logger.debug("document being created after first node exception: " + docStr); // check if dest ends with 'properties' String newResourceUri = null; if (cpDest.equals(FSXMLHelper.XML_PROPERTIES)) { logger.debug("putting to " + destinationUri); res = rHandler.handlePUT(destinationUri, docStr); newResourceUri = URIParser.getParentUri(destinationUri); } else if (URIParser.isResourceId(destinationUri)) { destinationUri += "/" + FSXMLHelper.XML_PROPERTIES; logger.debug("putting to " + destinationUri); res = rHandler.handlePUT(destinationUri, docStr); newResourceUri = URIParser.getParentUri(destinationUri); } else { logger.debug("posting to " + destinationUri); res = rHandler.handlePOST(destinationUri, docStr); try { if (FSXMLParser.getErrorMessageFromXml(res) == null) { Document respDoc = DocumentHelper.parseText(res); newResourceUri = respDoc.valueOf("//uri"); } } catch (Exception e) { logger.error("", e); } } // add refer of first node if (refer != null && !refer.equals("")) { logger.debug("adding refer for first node (" + refer + ")"); boolean ok = rHandler.saveAttributes(newResourceUri, "<fsxml><attributes><referid>" + refer + "</referid></attributes></fsxml>", "PUT"); logger.debug("attributes added: " + ok); } else { logger.debug("not need for adding refer id"); } // check if copy was successful and remove original String vError = FSXMLParser.getErrorMessageFromXml(res); if (vError != null) { logger.error("copy before moving was unsuccessful."); } else { logger.debug("copy before moving was successful."); FSXMLRequestHandler.instance().deleteNodeProperties(sourceUri, true); } logger.debug("response: " + res); return res; }
From source file:com.noterik.bart.fs.script.ActionSet.java
License:Open Source License
/** * Parses document for conditions//from ww w . j a v a 2 s . co m * @param doc */ private void parseConditions(Document doc) { logger.debug("parsing conditions"); List<Node> nodelist = doc.selectNodes("//condition"); Node node; Condition cond; String type, milis, p_uri, p_method, p_mimetype; for (Iterator<Node> iter = nodelist.iterator(); iter.hasNext();) { node = iter.next(); type = node.valueOf("properties/type"); if (type.equals("filter")) { p_uri = node.valueOf("properties/uri"); p_method = node.valueOf("properties/method"); p_mimetype = node.valueOf("properties/mimetype"); cond = new FilterCondition(p_uri, p_method, p_mimetype); // FIXME: ugly ass hell // set get/put/post/delete variables if (((FilterCondition) cond).methodPatternApplies("GET")) { script.get(true); } if (((FilterCondition) cond).methodPatternApplies("PUT")) { script.put(true); } if (((FilterCondition) cond).methodPatternApplies("POST")) { script.post(true); } if (((FilterCondition) cond).methodPatternApplies("DELETE")) { script.delete(true); } logger.debug("adding filter condition: uri=" + p_uri + ", method=" + p_method + ", mimetype=" + p_mimetype); addCondition(cond); } else if (type.equals("periodically")) { logger.info("Found periodically script " + this.id); //check if this smithers is configured to handle this timer String[] validDomains = LazyHomer.getTimerScriptDomains(); boolean valid = false; String domain = URIParser.getDomainFromUri(this.id); for (String validDomain : validDomains) { if (validDomain.equals(domain)) { valid = true; } } if (valid) { milis = node.valueOf("properties/milis"); TimerCondition timerCondition = new TimerCondition(Long.parseLong(milis), actions); Timer timer = new Timer(); timer.schedule(timerCondition, 1000, Long.parseLong(milis)); addTimerCondition(timer); logger.debug("adding timer condition: milis=" + milis); } else { logger.debug("No matching domain for domain " + domain); } } } }