List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:org.springfield.lenny.restlet.LennyResource.java
License:Open Source License
/** * /*from w w w . j av a 2 s .com*/ * @param property * @param value * @return */ private Pair<Status, String> getTicketHasAccess(String uri, String fsxml) { Pair<Status, String> r; int position = uri.indexOf(TICKET_ACCESS_URI) + TICKET_ACCESS_URI.length() + 1; // ticket uri, so not allowed if (position >= uri.length()) { StringBuilder response = new StringBuilder("<?xml version='1.0' encoding='UTF-8'?><fsxml><properties>"); response.append("<allowed>false</allowed>"); response.append("</properties></fsxml>"); r = new Pair<Status, String>(Status.SUCCESS_OK, response.toString()); return r; } String ticket = uri.substring(uri.indexOf(TICKET_ACCESS_URI) + TICKET_ACCESS_URI.length() + 1); String mediaUri = ""; logger.info(fsxml); try { Document doc = DocumentHelper.parseText(fsxml); mediaUri = doc.selectSingleNode("/fsxml/properties/uri") == null ? "" : doc.selectSingleNode("/fsxml/properties/uri").getText(); } catch (Exception e) { e.printStackTrace(); logger.error("error " + e.getMessage()); r = new Pair<Status, String>(Status.CLIENT_ERROR_BAD_REQUEST, property2fsxml("status", "Bad request")); return r; } if (accesslist.containsKey(ticket)) { if (accesslist.hasAccess(mediaUri, "", ticket)) { StringBuilder response = new StringBuilder( "<?xml version='1.0' encoding='UTF-8'?><fsxml><properties>"); response.append("<allowed>true</allowed>"); response.append("</properties></fsxml>"); r = new Pair<Status, String>(Status.SUCCESS_OK, response.toString()); } else { StringBuilder response = new StringBuilder( "<?xml version='1.0' encoding='UTF-8'?><fsxml><properties>"); response.append("<allowed>false</allowed>"); response.append("</properties></fsxml>"); r = new Pair<Status, String>(Status.SUCCESS_OK, response.toString()); } } else { r = new Pair<Status, String>(Status.CLIENT_ERROR_NOT_FOUND, property2fsxml("status", "Ticket not found")); } return r; }
From source file:org.springfield.lou.application.ApplicationManager.java
License:Open Source License
public void loadAvailableApps() { //System.out.println("ApplicationManager.loadAvailableApps()"); availableapps = new HashMap<String, Html5AvailableApplication>(); String xml = "<fsxml><properties><depth>2</depth></properties></fsxml>"; long starttime = new Date().getTime(); // we track the request time for debugging only ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return;/*from w ww . j a v a 2 s.c o m*/ String nodes = smithers.get("/domain/internal/service/lou/apps", xml, "text/xml"); //System.out.println("APP NODECOUNT="+nodes.length()); long endtime = new Date().getTime(); // we track the request time for debugging only //System.out.println("SMITHERSTIME="+(endtime-starttime)); try { Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String id = child.attributeValue("id"); Html5AvailableApplication vapp = new Html5AvailableApplication(); vapp.setId(id); // get all the versions and nodes String production = null; String development = null; for (Iterator<Node> iter2 = child.nodeIterator(); iter2.hasNext();) { //System.out.println("N2"); Node node = iter2.next(); if (node instanceof Element) { Element child2 = (Element) node; String nname = child2.getName(); if (nname.equals("properties")) { //System.out.println("N3"); for (Iterator<Node> iter3 = child2.nodeIterator(); iter3.hasNext();) { Node node2 = iter3.next(); if (node2 instanceof Element) { //System.out.println("N4"); Element child3 = (Element) node2; String pname = child3.getName(); if (pname.equals("autodeploy")) { vapp.loadAutoDeploy(child3.getText()); } } } } else if (nname.equals("versions")) { //System.out.println("N5"); String version = child2.attributeValue("id"); Html5AvailableApplicationVersion v = new Html5AvailableApplicationVersion(vapp); v.setId(version); vapp.addVersion(v); //System.out.println("N5.1"); } else if (nname.equals("nodes")) { //System.out.println("N6"); String ipnumber = child2.attributeValue("id"); String ipversion = child2.attributeValue("referid"); } else if (nname.equals("production")) { //System.out.println("N7"); production = child2.attributeValue("referid"); } else if (nname.equals("development")) { //System.out.println("N7"); development = child2.attributeValue("referid"); } //System.out.println("N5.2"); // ok lets set prod/dev version if (production != null) { Html5AvailableApplicationVersion pv = vapp.getVersionByUrl(production); if (pv != null) { pv.loadProductionState(true); // lets scan for triggers ! String scanpath = "/springfield/lou/apps/" + vapp.getId() + "/" + pv.getId() + "/components/app.xml"; //System.out.println("ACTIONLIST PRESCANNER="+scanpath); readJumpersForApp(scanpath); // if (!LazyHomer.inDeveloperMode()) ActionListManager.readActionListsDirForUrlTriggers(scanpath); } } //System.out.println("N5.2"); if (development != null) { Html5AvailableApplicationVersion dv = vapp.getVersionByUrl(development); if (dv != null) { dv.loadDevelopmentState(true); String scanpath = "/springfield/lou/apps/" + vapp.getId() + "/" + dv.getId() + "/actionlists/"; // if (LazyHomer.inDeveloperMode()) ActionListManager.readActionListsDirForUrlTriggers(scanpath); } } //System.out.println("N5.3"); } else { System.out.println("NOT AN ELEMENT!"); System.out.println(node); } //System.out.println("N99"); } availableapps.put(id, vapp); // parse it again to get the nodes, don't like it but simplest way for (Iterator<Node> iter2 = child.nodeIterator(); iter2.hasNext();) { Element child2 = (Element) iter2.next(); String nname = child2.getName(); if (nname.equals("nodes")) { String ipnumber = child2.attributeValue("id"); String ipversion = child2.attributeValue("referid"); //System.out.println("IP="+ipnumber+" VER="+ipversion); Html5AvailableApplicationVersion vv = vapp.getVersionByUrl(ipversion); if (vv != null) { vv.addNode(ipnumber); } } } } } } catch (Exception e) { System.out.println("Application manager : "); e.printStackTrace(); } if (availableapps.size() == 0) { System.out.println("NO APPS FOUND RETURNING NULL"); availableapps = null; } //System.out.println("END OF LOADAVAIL"); }
From source file:org.springfield.lou.application.ApplicationManager.java
License:Open Source License
private void readJumpersForApp(String filename) { // System.out.println("SCANPATH="+filename); // String filename = basepath+File.separator+"apps"+File.separator+part+File.separator+"components"+File.separator+"app.xml"; File file = new File(filename); if (file.exists()) { try {//from ww w. j a va 2 s .c o m BufferedReader br = new BufferedReader(new FileReader(filename)); StringBuffer str = new StringBuffer(); String line = br.readLine(); while (line != null) { str.append(line); str.append("\n"); line = br.readLine(); } br.close(); String body = str.toString(); Document result = DocumentHelper.parseText(body); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Node child = (Node) iter.next(); //System.out.println("C="+child.getName()); if (child.getName() != null && child.getName().equals("jumper")) { Element model = (Element) child; String sid = model.attributeValue("id"); //FsNode modelnode = new FsNode("model",modelid); for (Iterator<Node> iter2 = model.nodeIterator(); iter2.hasNext();) { Node child2 = (Node) iter2.next(); String id = child2.getName(); if (id != null) { //System.out.println("JUMPER="+sid+" "+id+" "+child2.getText()); LouServlet.addUrlTrigger(sid + "," + child2.getText(), "newscreen"); } } // putNode("/app/component",modelnode); // System.out.println("MIDELNODE="+modelnode.asXML()); } else if (child.getName() != null && child.getName().equals("jumpers")) { Element model = (Element) child; String sid = model.attributeValue("id"); //FsNode modelnode = new FsNode("model",modelid); for (Iterator<Node> iter2 = model.nodeIterator(); iter2.hasNext();) { Node child2 = (Node) iter2.next(); String id = child2.getName(); if (id != null) { System.out.println("JUMPERS=" + sid + " " + id + " " + child2.getText()); FSList fslist = FSListManager.get(child2.getText(), false); if (fslist != null) { List<FsNode> nodes = fslist.getNodes(); if (nodes != null) { for (Iterator<FsNode> iter3 = nodes.iterator(); iter3.hasNext();) { FsNode node = (FsNode) iter3.next(); String jumper = node.getId(); String target = node.getProperty("target"); String domain = node.getProperty("domain"); System.out .println("JUMPER=/lou/" + domain + "/" + jumper + "," + target); LouServlet.addUrlTrigger("/lou/" + domain + "/" + jumper + "," + target, "newscreen"); } } } } } } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.springfield.lou.application.components.types.debugger.Cat.java
License:Open Source License
public static void execute(List<String> buffer, String currentpath, String[] params) { boolean recursive = false; String name = params[1];//from ww w . j a v a 2s .c o m if (name.equals("-r")) { recursive = true; name = params[2]; } if (recursive) { buffer.add("> cat -r " + params[2]); String xml = "<fsxml><properties><depth>0</depth></properties></fsxml>"; //String result = LazyHomer.sendRequestBart("GET",currentpath+name,xml,"text/xml"); ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { buffer.add("> Error smithers down"); return; } String result = smithers.get(currentpath + name, xml, "text/xml"); String[] lines = result.split(">"); for (int i = 0; i < lines.length; i++) { buffer.add(lines[i] + ">"); } } else { buffer.add("> cat " + name); String xml = "<fsxml><properties><depth>0</depth></properties></fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers != null) { String nodes = smithers.get(currentpath + name, xml, "text/xml"); List<String> dirs = new ArrayList<String>(); try { Document result = DocumentHelper.parseText(nodes); System.out.println("R=" + result.asXML()); String value = result.getRootElement().getText(); //System.out.println("V="+value+" r="+result.getRootElement().getName()); buffer.add(value); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.springfield.lou.application.components.types.debugger.Cd.java
License:Open Source License
public static String execute(List<String> buffer, String currentpath, String[] params) { String oldpath = currentpath; if (params.length > 1) { String wantedpath = params[1]; if (wantedpath.equals("../") || wantedpath.equals("..")) { currentpath = currentpath.substring(0, currentpath.length() - 1); int pos = currentpath.lastIndexOf("/"); if (pos != -1) currentpath = currentpath.substring(0, pos); } else if (wantedpath.indexOf("/") == 0) { currentpath = wantedpath;/*from www . j a v a2 s . c om*/ } else { currentpath += wantedpath; } if (!currentpath.endsWith("/")) currentpath += "/"; buffer.add("> cd " + currentpath); // check if its ok String xml = "<fsxml><properties><depth>0</depth></properties></fsxml>"; //String nodes = LazyHomer.sendRequestBart("GET",currentpath,xml,"text/xml"); ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { buffer.add("> Error smithers down"); return currentpath; } String nodes = smithers.get(currentpath, xml, "text/xml"); try { Document result = DocumentHelper.parseText(nodes); if (result.asXML().indexOf("<message>No data available</message>") != -1 || result.asXML() .indexOf("<totalResultsReturned>0</totalResultsReturned></properties>") != -1) { buffer.add("No such entry"); return oldpath; } } catch (Exception e) { buffer.add("No such entry"); return oldpath; } } else { buffer.add("> cd"); } return currentpath; }
From source file:org.springfield.lou.application.components.types.debugger.Dpost.java
License:Open Source License
public static void execute(List<String> buffer, String currentpath, String[] params) { String oldpath = currentpath; buffer.add("> dpost " + currentpath); // check if its ok String body = "<fsxml mimetype=\"application/fscommand\" id=\"dynamic\">"; body += "<properties>"; body += "<handler>" + "/dynamic/presentation/playout/flash" + "</handler>"; body += "<virtualpath>videoplaylist/tagging</virtualpath>"; body += "</properties>"; body += "</fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); String nodes = smithers.post(currentpath, body, "text/xml"); try {/*from w w w . j ava 2 s . c om*/ Document result = DocumentHelper.parseText(nodes); System.out.println("DPOST=" + result.asXML()); } catch (Exception e) { buffer.add("Error"); } }
From source file:org.springfield.lou.application.components.types.debugger.Ls.java
License:Open Source License
public static boolean execute(List<String> buffer, String currentpath, String[] params, String[] ignorelist) { buffer.add("> dir"); String xml = "<fsxml><properties><depth>0</depth></properties></fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { buffer.add("> Error smithers down"); return false; }/*from w ww . ja v a 2 s . co m*/ String nodes = smithers.get(currentpath, xml, "text/xml"); List<String> dirs = new ArrayList<String>(); try { Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element main = (Element) iter.next(); if (currentpath.endsWith(main.getName() + "/")) { String dir = main.attributeValue("id"); if (!dirs.contains(dir)) { if (!Arrays.asList(ignorelist).contains(dir)) { dirs.add(dir); } } } else if (currentpath.endsWith("/properties/")) { for (Iterator<Node> iter2 = main.nodeIterator(); iter2.hasNext();) { Element child = (Element) iter2.next(); if (child.getName().equals("properties")) { for (Iterator<Node> iter3 = child.nodeIterator(); iter3.hasNext();) { Element prop = (Element) iter3.next(); String dir = prop.getName(); if (!dirs.contains(dir)) { if (!Arrays.asList(ignorelist).contains(dir)) { dirs.add(dir); } } } } } } else { for (Iterator<Node> iter2 = main.nodeIterator(); iter2.hasNext();) { Element child = (Element) iter2.next(); String dir = child.getName(); if (!dirs.contains(dir)) { if (!Arrays.asList(ignorelist).contains(dir)) { dirs.add(dir); } } } } } // ok loop all the results String body = ""; for (int i = 0; i < dirs.size(); i++) { if (dirs.size() < 10) { body += dirs.get(i) + " \n"; } else { body += dirs.get(i) + " \t"; } } buffer.add(body); } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:org.springfield.lou.application.components.types.debugger.Mkdir.java
License:Open Source License
public static void execute(List<String> buffer, String currentpath, String[] params) { // find out what type of node we are ? String xml = "<fsxml><properties><depth>0</depth></properties></fsxml>"; //String nodes = LazyHomer.sendRequestBart("GET",currentpath,xml,"text/xml"); ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { buffer.add("> Error smithers down"); return;// www .j a v a2s. c o m } String nodes = smithers.get(currentpath, xml, "text/xml"); try { Document result = DocumentHelper.parseText(nodes); String lastid = currentpath.substring(0, currentpath.length() - 1); lastid = lastid.substring(lastid.lastIndexOf("/") + 1); Element node = result.getRootElement().element(lastid); if (node != null) { String newbody = "<fsxml><properties></properties></fsxml>"; String postpath = currentpath + params[1] + "/properties"; //LazyHomer.sendRequest("PUT",postpath,newbody,"text/xml"); smithers.put(postpath, newbody, "text/xml"); } else { String newbody = "<fsxml>"; newbody += "<" + params[1] + "><properties>"; newbody += "</properties></" + params[1] + "></fsxml>"; //LazyHomer.sendRequest("PUT",currentpath+"properties",newbody,"text/xml"); smithers.put(currentpath + "properties", newbody, "text/xml"); } buffer.add("> mkdir " + params[1]); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.springfield.lou.application.types.DemolinkedtvApplication.java
License:Open Source License
/** * Load the collection presentation from the file system * /* www.j a v a 2 s .c o m*/ * @return true if everything went ok, otherwise false */ private boolean loadCollectionPresentation() { ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return false; //String data = LazyHomer.sendRequestBart("GET", uri, null, null); String data = smithers.get(uri, null, null); try { Document response = DocumentHelper.parseText(data); String presentationUri = response.selectSingleNode("//presentation/@referid") == null ? "" : response.selectSingleNode("//presentation/@referid").getText(); this.presentationUri = presentationUri; return true; } catch (Exception e) { System.out.println("ERROR: loading collection failed"); e.printStackTrace(); return false; } }
From source file:org.springfield.lou.application.types.DemolinkedtvApplication.java
License:Open Source License
/** * Load the presentation from the file system * //from w ww.j a v a2 s.c o m * @return true if everything went ok, otherwise false */ private boolean loadPresentation() { ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return false; String data = smithers.get(presentationUri, "<fsxml><properties><depth>2</depth></properties></fsxml>", "text/xml"); try { Document response = DocumentHelper.parseText(data); String videoUri = response.selectSingleNode("//videoplaylist[@id='1']/video[@id='1']/@referid") == null ? "" : response.selectSingleNode("//videoplaylist[@id='1']/video[@id='1']/@referid").getText(); String mediaResourceId = response.selectSingleNode("//properties/media_resource_id") == null ? "" : response.selectSingleNode("//properties/media_resource_id").getText(); this.videoUri = videoUri; this.mediaResourceId = mediaResourceId; return true; } catch (Exception e) { System.out.println("ERROR: loading presentation failed"); e.printStackTrace(); return false; } }