List of usage examples for org.dom4j DocumentFactory getInstance
public static synchronized DocumentFactory getInstance()
From source file:gjset.tests.MockClient.java
License:Open Source License
/** * Create a client that will connect to the indicated port. * * @param string// ww w. j a va 2s . co m * @param gamePort */ public MockClient(String hostname, int port) { socketAddress = new InetSocketAddress(hostname, port); DocumentFactory.getInstance(); playerId = 0; }
From source file:gjset.tools.MessageUtils.java
License:Open Source License
/** * Wraps a message with enclosing tags and a comm version. * * @param messageElement//from w w w.ja v a 2s. co m * @return */ public static Element wrapMessage(Element messageElement) { DocumentFactory documentFactory = DocumentFactory.getInstance(); Element rootElement = documentFactory.createElement("combocards"); Element versionElement = documentFactory.createElement("version"); versionElement.setText(GameConstants.COMM_VERSION); rootElement.add(versionElement); rootElement.add(messageElement); return rootElement; }
From source file:gov.nih.nci.grididloader.Config.java
License:BSD License
/** * Serialized the entity mapping to an XML format. * @param xmlMappingFile/*from ww w .j a v a 2 s . com*/ * @throws Exception */ public void saveXMLMapping(String xmlMappingFile) throws Exception { Document doc = DocumentFactory.getInstance().createDocument(); Element mapping = doc.addElement("mapping"); String mappingPackage = null; for (BigEntity entity : entities) { String packageName = entity.getPackageName(); String className = entity.getClassName(); if (mappingPackage == null) { mappingPackage = packageName; } else if (!mappingPackage.equals(packageName)) { System.err.println("ERROR: inconsistent package, " + mappingPackage + " != " + packageName); } // create entity Element entityElement = mapping.addElement("entity").addAttribute("class", className) .addAttribute("table", entity.getTableName()); entityElement.addElement("primary-key").addText(entity.getPrimaryKey()); Element logicalElement = entityElement.addElement("logical-key"); // add joined attributes Map<String, String> seenAttrs = new HashMap<String, String>(); Collection<Join> joins = entity.getJoins(); for (Join join : joins) { if (join instanceof TableJoin) { TableJoin tableJoin = (TableJoin) join; for (String attr : tableJoin.getAttributes()) { logicalElement.addElement("property").addAttribute("table", tableJoin.getForeignTable()) .addAttribute("primary-key", tableJoin.getForeignTablePK()) .addAttribute("foreign-key", tableJoin.getForeignKey()).addText(attr); seenAttrs.put(attr, null); } } else { EntityJoin entityJoin = (EntityJoin) join; logicalElement.addElement("property") .addAttribute("entity", entityJoin.getEntity().getClassName()) .addAttribute("foreign-key", entityJoin.getForeignKey()); } } // add all the leftover non-joined attributes for (String attr : entity.getAttributes()) { if (!seenAttrs.containsKey(attr)) { logicalElement.addElement("property").addText(attr); } } } mapping.addAttribute("package", mappingPackage); // write to file OutputFormat outformat = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(xmlMappingFile), outformat); writer.write(doc); writer.flush(); }
From source file:hudson.model.Api.java
License:Open Source License
/** * Exposes the bean as XML./*from w ww . jav a 2 s.co m*/ */ public void doXml(StaplerRequest req, StaplerResponse rsp, @QueryParameter String xpath, @QueryParameter String wrapper, @QueryParameter String tree, @QueryParameter int depth) throws IOException, ServletException { setHeaders(rsp); String[] excludes = req.getParameterValues("exclude"); if (xpath == null && excludes == null) { // serve the whole thing rsp.serveExposedBean(req, bean, Flavor.XML); return; } StringWriter sw = new StringWriter(); // first write to String Model p = MODEL_BUILDER.get(bean.getClass()); TreePruner pruner = (tree != null) ? new NamedPathPruner(tree) : new ByDepth(1 - depth); p.writeTo(bean, pruner, Flavor.XML.createDataWriter(bean, sw)); // apply XPath FilteredFunctionContext functionContext = new FilteredFunctionContext(); Object result; try { Document dom = new SAXReader().read(new StringReader(sw.toString())); // apply exclusions if (excludes != null) { for (String exclude : excludes) { XPath xExclude = dom.createXPath(exclude); xExclude.setFunctionContext(functionContext); List<org.dom4j.Node> list = (List<org.dom4j.Node>) xExclude.selectNodes(dom); for (org.dom4j.Node n : list) { Element parent = n.getParent(); if (parent != null) parent.remove(n); } } } if (xpath == null) { result = dom; } else { XPath comp = dom.createXPath(xpath); comp.setFunctionContext(functionContext); List list = comp.selectNodes(dom); if (wrapper != null) { Element root = DocumentFactory.getInstance().createElement(wrapper); for (Object o : list) { if (o instanceof String) { root.addText(o.toString()); } else { root.add(((org.dom4j.Node) o).detach()); } } result = root; } else if (list.isEmpty()) { rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); rsp.getWriter().print(Messages.Api_NoXPathMatch(xpath)); return; } else if (list.size() > 1) { rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); rsp.getWriter().print(Messages.Api_MultipleMatch(xpath, list.size())); return; } else { result = list.get(0); } } } catch (DocumentException e) { LOGGER.log(Level.FINER, "Failed to do XPath/wrapper handling. XML is as follows:" + sw, e); throw new IOException("Failed to do XPath/wrapper handling. Turn on FINER logging to view XML.", e); } if (isSimpleOutput(result) && !permit(req)) { // simple output prohibited rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester"); return; } // switch to gzipped output OutputStream o = rsp.getCompressedOutputStream(req); try { if (isSimpleOutput(result)) { // simple output allowed rsp.setContentType("text/plain;charset=UTF-8"); String text = result instanceof CharacterData ? ((CharacterData) result).getText() : result.toString(); o.write(text.getBytes("UTF-8")); return; } // otherwise XML rsp.setContentType("application/xml;charset=UTF-8"); new XMLWriter(o).write(result); } finally { o.close(); } }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaEntitesImpl.java
License:Open Source License
private byte[] exportGraphML(EntiteDto entiteDto, FiltreStatut filtreStatut, Map<String, Boolean> mapIdLiOuvert) throws IOException { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); Element graph = initRoot(root); initHeader(root);/* ww w. j a v a2 s. com*/ construitTableauStats(graph, entiteDto); buildGraphMlTree(graph, entiteDto, mapIdLiOuvert, filtreStatut); ajoutLogoMairie(graph); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaFichesPosteImpl.java
License:Open Source License
private byte[] exportGraphML(FichePosteTreeNodeDto node, boolean isAfficheAgent, Map<String, Boolean> mapIdLiOuvert) throws IOException { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); Element graph = initRoot(root); initHeader(root);//ww w.jav a 2s. c o m construitTableauStats(graph, this.entiteDto); mapFichesPosteSuperieureByService = EntityUtils.getFichesPosteChefDeService(node); buildGraphMlTree(graph, node, mapIdLiOuvert, isAfficheAgent, null); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:nc.noumea.mairie.organigramme.services.impl.ExportGraphMLServiceImpl.java
License:Open Source License
private byte[] exportGraphML(EntiteDto entiteDto, Map<String, Boolean> mapIdLiOuvert) { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); initHeader(root);/*from www . j a va 2 s. com*/ Element graph = initRoot(root); buildGraphMlTree(graph, entiteDto, mapIdLiOuvert); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:nl.ru.cmbi.vase.parse.VASEXMLParser.java
License:Apache License
public static void write(VASEDataObject data, OutputStream xmlOut) throws IOException { DocumentFactory df = DocumentFactory.getInstance(); Document doc = df.createDocument(); Element root = doc.addElement("xml"); if (data.getTitle() != null) { Element title = root.addElement("title"); title.setText(data.getTitle());/* www .j ava 2s .c om*/ } Element fasta = root.addElement("fasta"); ByteArrayOutputStream fastaStream = new ByteArrayOutputStream(); FastaParser.toFasta(data.getAlignment().getMap(), fastaStream); fasta.add(df.createCDATA(new String(fastaStream.toByteArray(), StandardCharsets.UTF_8))); Element pdb = root.addElement("pdb"); pdb.addAttribute("pdbid", data.getPdbID()); table2xml(data.getTable(), root); if (data.getPlots().size() > 0) { Element plots = root.addElement("plots"); for (PlotDescription pd : data.getPlots()) { Element plot = plots.addElement("plot"); plot.addElement("x").setText(pd.getXAxisColumnID()); plot.addElement("y").setText(pd.getYAxisColumnID()); plot.addAttribute("title", pd.getPlotTitle()); } } XMLWriter writer = new XMLWriter(xmlOut); writer.write(doc); writer.close(); }
From source file:nl.tue.gale.ae.config.PresentationConfig.java
License:Open Source License
public Object getObject_layout(Resource resource) { Element result = DocumentFactory.getInstance().createElement("struct"); result.addAttribute("cols", "20%;*"); result.addElement("view").addAttribute("name", "static-tree-view"); result.addElement("content"); GaleContext gale = GaleContext.of(resource); CacheSession<EntityValue> session = gale.openUmSession(); EntityValue ev = session.get(URIs.of("#layout")); if (ev == null) { /*/*w w w . j av a2 s .c om*/ * if (gale.conceptUri().toString().startsWith( * "gale://gale.tue.nl/aha3/tutorial") && * "page".equals(gale.concept().getType())) return result; */ return null; } if (ev.getValue().toString().trim().equals("")) return null; return GaleUtil.parseXML(new StringReader(ev.getValue().toString())).getRootElement(); }
From source file:nl.tue.gale.ae.grapple.CourseListService.java
License:Open Source License
private Element createIMSLIP(Concept c) { DocumentFactory df = DocumentFactory.getInstance(); Element sourcedid = df.createElement("sourcedid"); Element result = df.createElement("activity"); Element contentype = result.addElement("contentype"); contentype.addElement("referential").add(sourcedid); sourcedid.addElement("source").addText(galeConfig.getRootGaleUrl() + c.getUriString()); sourcedid.addElement("id").addText(c.getTitle()); String camguid = c.getProperty("cam.model.guid"); if (camguid != null && !"".equals(camguid)) { Element field = contentype.addElement("temporal").addElement("temporalfield"); field.addElement("fieldlabel").addElement("typename").addElement("tyvalue").addText("camguid"); field.addElement("fielddata").addText(camguid); }/*from www . jav a 2 s . c o m*/ return result; }