List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:com.noterik.bart.fs.fscommand.SplitCommand.java
License:Open Source License
private void fixPositions(String uri, int position) { logger.debug("fix positions for: " + uri); int current_position = position; Document doc = FSXMLRequestHandler.instance().getNodeProperties(uri, false); try {//from w w w. j a v a2s. c o m // get videoplaylist Element videoplaylist = (Element) doc.selectSingleNode("//videoplaylist[@id='1']"); // get all child nodes Element elem, propElem; String id, name; for (Iterator<Element> iter = videoplaylist.elementIterator(); iter.hasNext();) { try { // get element elem = iter.next(); // get id, name, uri and properties id = elem.valueOf("@id"); name = elem.getName(); if (!name.equals("video")) continue; String properties = "<properties>"; propElem = (Element) elem.selectSingleNode("properties"); for (Iterator<Element> iter2 = propElem.elementIterator(); iter2.hasNext();) { try { // get element Element videoElem = iter2.next(); String property = videoElem.getName(); String value = videoElem.getTextTrim(); if (property != "starttime" && property != "duration" && property != "position") continue; if (property == "position") { int posvalue = (value != "" ? Integer.parseInt(value) : 0); logger.debug("OLD Position is: " + Integer.toString(posvalue)); if (posvalue >= current_position) { posvalue++; logger.debug("NEW Position is: " + Integer.toString(posvalue)); properties += "<position>" + Integer.toString(posvalue) + "</position>"; } else { properties += videoElem.asXML(); } } else { properties += videoElem.asXML(); } } catch (Exception e) { logger.error("", e); } } properties += "</properties>"; logger.debug("Fix position of: " + uri + "/video/" + id); logger.debug("Properties are: " + properties); String response = FSXMLRequestHandler.instance().handlePUT(uri + "/video/" + id + "/properties", "<fsxml>" + properties + "</fsxml>"); } catch (Exception e) { logger.error("", e); } } } catch (Exception e) { logger.error("", e); } }
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
/** * @see com.openedit.users.UserManager#getGroup(String) *//* w w w. j a v a2 s. co m*/ public Group getGroup(String inGroupId) { Group group = (Group) getGroupIdToGroupMap().get(inGroupId); File find = loadGroupFile(inGroupId); if (group != null) { if (group.getLastModified() == find.lastModified()) { return group; } } if (!find.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/groups/" + inGroupId + ".xml"); find = new File(stub.getAbsolutePath()); } if (!find.exists()) { return null; } if (group == null) { group = new FileSystemGroup(); } FileSystemGroup loadgroup = (FileSystemGroup) group; group = loadgroup; loadgroup.setLastModified(find.lastModified()); getGroupIdToGroupMap().put(inGroupId, group); Element root = getXmlUtil().getXml(find, "UTF-8"); loadgroup.setId(root.attributeValue("id")); if (loadgroup.getId() == null) { loadgroup.setId(inGroupId); } loadgroup.setName(root.elementText("group-name")); if (loadgroup.getName() == null) { loadgroup.setName(inGroupId); } Element perm = root.element("permissions"); if (perm != null) { for (Iterator iterator = perm.elementIterator("permission"); iterator.hasNext();) { Element type = (Element) iterator.next(); loadgroup.addPermission(type.getTextTrim()); } } MapPropertyContainer properties = new MapPropertyContainer(); Element props = root.element("properties"); properties.loadProperties(props); loadgroup.setPropertyContainer(properties); return loadgroup; }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
/** * @see com.openedit.users.UserManager#getGroup(String) */// www.j a v a 2 s. co m public Group getGroup(String inGroupId) { Group group = (Group) getGroupIdToGroupMap().get(inGroupId); File find = loadGroupFile(inGroupId); if (group != null) { if (group.getLastModified() == find.lastModified()) { return group; } } if (!find.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/groups/" + inGroupId + ".xml"); find = new File(stub.getAbsolutePath()); } if (!find.exists()) { return null; } if (group == null) { // System.out.println("calling " + inGroupId + " " + hashCode() ); group = new FileSystemGroup(); } FileSystemGroup loadgroup = (FileSystemGroup) group; group = loadgroup; loadgroup.setLastModified(find.lastModified()); getGroupIdToGroupMap().put(inGroupId, group); Element root = getXmlUtil().getXml(find, "UTF-8"); loadgroup.setId(root.attributeValue("id")); if (loadgroup.getId() == null) { loadgroup.setId(inGroupId); } loadgroup.setName(root.elementText("group-name")); if (loadgroup.getName() == null) { loadgroup.setName(inGroupId); } Element perm = root.element("permissions"); if (perm != null) { for (Iterator iterator = perm.elementIterator("permission"); iterator.hasNext();) { Element type = (Element) iterator.next(); loadgroup.addPermission(type.getTextTrim()); } } MapPropertyContainer properties = new MapPropertyContainer(); Element props = root.element("properties"); properties.loadProperties(props); loadgroup.setPropertyContainer(properties); return loadgroup; }
From source file:com.ostrichemulators.semtool.ui.components.playsheets.BrowserPlaySheet2.java
License:Open Source License
protected BufferedImage getExportImageFromSVGBlock() throws IOException { log.debug("Using SVG block to save image."); DOMReader rdr = new DOMReader(); Document doc = rdr.read(engine.getDocument()); Document svgdoc = null;/*from www .j a v a2 s .c om*/ File svgfile = null; try { Map<String, String> namespaceUris = new HashMap<>(); namespaceUris.put("svg", "http://www.w3.org/2000/svg"); namespaceUris.put("xhtml", "http://www.w3.org/1999/xhtml"); XPath xp = DocumentHelper.createXPath("//svg:svg"); xp.setNamespaceURIs(namespaceUris); // don't forget about the styles XPath stylexp = DocumentHelper.createXPath("//xhtml:style"); stylexp.setNamespaceURIs(namespaceUris); svgdoc = DocumentHelper.createDocument(); Element svg = null; List<?> theSVGElements = xp.selectNodes(doc); if (theSVGElements.size() == 1) { svg = Element.class.cast(theSVGElements.get(0)).createCopy(); } else { int currentTop = 0; int biggestSize = 0; for (int i = 0; i < theSVGElements.size(); i++) { Element thisElement = Element.class.cast(theSVGElements.get(i)).createCopy(); int thisSize = thisElement.asXML().length(); if (thisSize > biggestSize) { currentTop = i; biggestSize = thisSize; } } svg = Element.class.cast(theSVGElements.get(currentTop)).createCopy(); } svgdoc.setRootElement(svg); Element oldstyle = Element.class.cast(stylexp.selectSingleNode(doc)); if (null != oldstyle) { Element defs = svg.addElement("defs"); Element style = defs.addElement("style"); style.addAttribute("type", "text/css"); String styledata = oldstyle.getTextTrim(); style.addCDATA(styledata); // put the stylesheet definitions first List l = svg.elements(); l.remove(defs); l.add(0, defs); } // clean up the SVG a little... // d3 comes up with coords like // M360,27475.063247863247C450,27475.063247863247 450,27269.907692307694 540,27269.907692307694 XPath cleanxp1 = DocumentHelper.createXPath("//svg:path"); Pattern pat = Pattern.compile(",([0-9]+)\\.([0-9]{1,2})[0-9]+"); cleanxp1.setNamespaceURIs(namespaceUris); List<?> cleanups = cleanxp1.selectNodes(svgdoc); for (Object n : cleanups) { Element e = Element.class.cast(n); String dstr = e.attributeValue("d"); Matcher m = pat.matcher(dstr); dstr = m.replaceAll(",$1.$2 "); e.addAttribute("d", dstr.replaceAll("([0-9])C([0-9])", "$1 C$2").trim()); } XPath cleanxp2 = DocumentHelper.createXPath("//svg:g[@class='node']"); cleanxp2.setNamespaceURIs(namespaceUris); cleanups = cleanxp2.selectNodes(svgdoc); for (Object n : cleanups) { Element e = Element.class.cast(n); String dstr = e.attributeValue("transform"); Matcher m = pat.matcher(dstr); dstr = m.replaceAll(",$1.$2"); e.addAttribute("transform", dstr.trim()); } svgfile = File.createTempFile("graphviz-", ".svg"); try (Writer svgw = new BufferedWriter(new FileWriter(svgfile))) { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xmlw = new XMLWriter(svgw, format); xmlw.write(svgdoc); xmlw.close(); if (log.isDebugEnabled()) { FileUtils.copyFile(svgfile, new File(FileUtils.getTempDirectory(), "graphvisualization.svg")); } } try (Reader svgr = new BufferedReader(new FileReader(svgfile))) { TranscoderInput inputSvg = new TranscoderInput(svgr); ByteArrayOutputStream baos = new ByteArrayOutputStream((int) svgfile.length()); TranscoderOutput outputPng = new TranscoderOutput(baos); try { PNGTranscoder transcoder = new PNGTranscoder(); transcoder.addTranscodingHint(PNGTranscoder.KEY_INDEXED, 256); transcoder.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE); transcoder.transcode(inputSvg, outputPng); } catch (Throwable t) { log.error(t, t); } baos.flush(); baos.close(); return ImageIO.read(new ByteArrayInputStream(baos.toByteArray())); } } catch (InvalidXPathException e) { log.error(e); String msg = "Problem creating image"; if (null != svgdoc) { try { File errsvg = new File(FileUtils.getTempDirectory(), "graphvisualization.svg"); FileUtils.write(errsvg, svgdoc.asXML(), Charset.defaultCharset()); msg = "Could not create the image. SVG data store here: " + errsvg.getAbsolutePath(); } catch (IOException ex) { // don't care } } throw new IOException(msg, e); } finally { if (null != svgfile) { FileUtils.deleteQuietly(svgfile); } } }
From source file:com.pactera.edg.am.metamanager.extractor.util.Dom4jReader.java
License:Open Source License
public String getElementText(Element element) { return element.getTextTrim(); }
From source file:com.pactera.edg.am.metamanager.extractor.util.GenSqlUtil.java
License:Open Source License
/** * ?SQL/*from ww w .j av a 2 s . c o m*/ * * @throws IOException * XML? */ private static Map<String, String> readSQL(String location) throws IOException { Map<String, String> sqls = new HashMap<String, String>(); MessageFormat mf = new MessageFormat(Constants.SQL_STORE_PATH); String file = mf.format(new Object[] { location }); InputStream in = null; Dom4jReader reader = null; try { in = GenSqlUtil.class.getClassLoader().getResourceAsStream(file); reader = new Dom4jReader(); reader.initDocument(in); List<?> elements = reader.selectNodes(Constants.SQL_FLAG); for (int i = 0; i < elements.size(); i++) { Element element = (Element) elements.get(i); sqls.put(element.attributeValue("id"), element.getTextTrim()); } } finally { if (reader != null) { reader.close(); } if (in != null) { in.close(); } } return sqls; }
From source file:com.poka.util.XmlSax.java
public String getZCXDFileNameL() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }// w ww . ja v a2 s .c o m Element root1Elm = rootElm.element("zcxdL"); if (root1Elm == null) { root1Elm = rootElm.addElement("zcxdL"); root1Elm.setText("[0-9]{8}_[0-9A-Za-z]*_[0-9]*_1_(CNY)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9]{8}_[0-9A-Za-z]*_[0-9]*_1_(CNY)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }
From source file:com.poka.util.XmlSax.java
public String getZCXDFileNameC() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }/*from ww w .j av a 2s . c o m*/ Element root1Elm = rootElm.element("zcxdC"); if (root1Elm == null) { root1Elm = rootElm.addElement("zcxdC"); root1Elm.setText("[0-9]{8}_[0-9A-Za-z]*_[0-9]*_2_(CNY)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9]{8}_[0-9A-Za-z]*_[0-9]*_2_(CNY)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }
From source file:com.poka.util.XmlSax.java
public String getGDFileNameL() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }/*w ww .j a v a 2s . com*/ Element root1Elm = rootElm.element("dgL"); if (root1Elm == null) { root1Elm = rootElm.addElement("dgL"); root1Elm.setText("[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(1|2|3)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(1|2|3)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }
From source file:com.poka.util.XmlSax.java
public String getGDFileNameC() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }// www . j ava2 s . c o m Element root1Elm = rootElm.element("dgC"); if (root1Elm == null) { root1Elm = rootElm.addElement("dgC"); root1Elm.setText("[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(4|8|12)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(4|8|12)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }