List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:org.dentaku.gentaku.tools.cgen.visitor.JellyTemplateGeneratingVisitor.java
License:Apache License
public void handleElement(Element element) throws VisitorException { if (element.getParent().getName().equals("schema")) { QName rootName = DocumentFactory.getInstance().createQName("jelly", "j", "jelly:core"); Branch parent = DocumentHelper.createDocument().addElement(rootName).addNamespace("x", "jelly:xml"); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(getEncoding()); format.setSuppressDeclaration(false); format.setExpandEmptyElements(false); pushParent(parent.addElement(element.getName())); for (Iterator it = element.elementIterator(); it.hasNext();) { visit((Element) it.next()); }/* ww w. j av a2s .co m*/ popParent(); try { String filename = element.getName() + ".jelly"; Writer out = new FileWriter(new File(getRootDir(), filename)); final XMLWriter xmlWriter = new XMLWriter(out, format); xmlWriter.setEscapeText(false); xmlWriter.write(parent); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { throw new VisitorException("Exception occurred when running Jelly", e); } topLevelElements.put(element.getName(), element); } else { String refName = element.attributeValue("ref"); if (refName != null) { Branch parent = getCurrentParent(); // create an include QName qName = DocumentFactory.getInstance().createQName("import", "j", "jelly:core"); parent.addElement(qName).addAttribute("uri", refName + ".jelly").addAttribute("inherit", "true"); } } }
From source file:org.dentaku.gentaku.tools.cgen.visitor.JellyTemplateGeneratingVisitor.java
License:Apache License
public Branch getCurrentParent() throws VisitorException { Branch parent = null;/*from w w w . ja v a2 s . co m*/ if (parentStack.size() == 0) { QName rootName = DocumentFactory.getInstance().createQName("jelly", "j", "jelly:core"); parent = DocumentHelper.createDocument().addElement(rootName).addNamespace("x", "jelly:xml"); parentStack.push(parent); } else { parent = (Branch) parentStack.peek(); } return parent; }
From source file:org.dentaku.gentaku.tools.cgen.xmi.XMIGenTask.java
License:Apache License
public void execute() throws BuildException { System.out.println("Running " + getClass().getName()); SAXReader reader = new SAXReader(); Document outputDocument = DocumentHelper.createDocument(); Branch content = createXMIDocument(outputDocument); Element model = createIdentifiedEmptyElement(content, "Model").addAttribute("name", "foo"); // add the XSD and mapping documents as tagged values into the package Element gengenPackage = createPackageHierarchy("org.dentaku.gentaku.gengen", model); Element gengenOwnedElement = createOwnedElement(gengenPackage); // create the tag group Element groupStereotype = createIdentifiedEmptyElement(gengenOwnedElement, "Stereotype") .addAttribute("name", "tagGroup"); groupStereotype.addElement("UML:Stereotype.baseClass", "omg.org/UML/1.4").setText("TagDefinition"); Element groupTagdef = createTaggedValueDefinition(gengenOwnedElement, "Group", null, new String[] { "TagDefinition" }, "String", false); groupTagdef.addAttribute("stereotype", groupStereotype.attributeValue("xmi.id")); // create the gengen stereotype marker Element gengenStereotype = createIdentifiedEmptyElement(gengenOwnedElement, "Stereotype") .addAttribute("name", "GenGenPackage"); gengenStereotype.addElement("UML:Stereotype.baseClass", "omg.org/UML/1.4").setText("Package"); Element xsdTaggedValueDefinition = createTaggedValueDefinition(gengenOwnedElement, "gengen.XSD", null, new String[] { "Package" }, "String", false); Element mappingTaggedValueDefinition = createTaggedValueDefinition(gengenOwnedElement, "gengen.mapping", null, new String[] { "Package" }, "String", false); try {// w w w . j a v a 2 s. c om for (Iterator it = antSpecifiedModules.iterator(); it.hasNext();) { visited.clear(); Module module = (Module) it.next(); if (module.getMapping() == null || module.getSchema() == null) { throw new BuildException( "you must provide both a mapping and a schema argument to the XMIGenTask"); } Document mappingDoc = reader.read(new File(module.getMapping())); final Document schemaDoc = reader.read(new File(module.getSchema())); // annotate XSD with mapping document mappingDoc.accept(new VisitorSupport() { public void visit(Element node) { String path = node.attributeValue("path"); if (path != null) { LocalDefaultElement xsdVisit = (LocalDefaultElement) Util.selectSingleNode(schemaDoc, path); xsdVisit.setAnnotation((LocalDefaultElement) node); } } }); String rootPath = ((Element) Util.selectSingleNode(mappingDoc, "/mapping/element[@location='root']")).attributeValue("path"); LocalDefaultElement rootNode = (LocalDefaultElement) Util.selectSingleNode(schemaDoc, rootPath); // create the location sets createLocationSets(rootNode, "root", new Stack()); buildDocument(model, schemaDoc, mappingDoc, rootNode, groupTagdef, gengenStereotype, xsdTaggedValueDefinition, mappingTaggedValueDefinition); } if (destdir == null) destdir = "./"; File file = new File(destdir); file.mkdirs(); writeFile(outputDocument, new File(file, filename)); } catch (DocumentException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.dom4j.samples.CreateXMLDemo.java
License:Open Source License
protected Document createDocument() throws Exception { Document document = DocumentHelper.createDocument(); Element root = document.addElement("system"); Properties properties = System.getProperties(); for (Enumeration elements = properties.propertyNames(); elements.hasMoreElements();) { String name = (String) elements.nextElement(); String value = properties.getProperty(name); Element element = root.addElement("property"); element.addAttribute("name", name); element.addText(value);/* ww w . j a va 2s. c o m*/ } return document; }
From source file:org.eclipse.jubula.client.core.businessprocess.AbstractXMLReportGenerator.java
License:Open Source License
/** * Constructor/* w w w . j a v a2 s . c o m*/ * * @param testResult The Test Result for which to write a report. */ public AbstractXMLReportGenerator(ITestResult testResult) { m_document = DocumentHelper.createDocument(); setTestResult(testResult); }
From source file:org.ecocean.servlet.ScanResultsServlet.java
License:Open Source License
public boolean writeXML(HttpServletRequest request, Vector results, String num, String newEncDate, String newEncShark, String newEncSize) { String context = "context0"; context = ServletUtilities.getContext(request); try {//from w w w. j av a2 s .co m System.out.println("Prepping to write XML file for encounter " + num); //now setup the XML write for the encounter int resultsSize = results.size(); MatchObject[] matches = new MatchObject[resultsSize]; for (int a = 0; a < resultsSize; a++) { matches[a] = (MatchObject) results.get(a); } Arrays.sort(matches, new MatchComparator()); StringBuffer resultsXML = new StringBuffer(); Document document = DocumentHelper.createDocument(); Element root = document.addElement("matchSet"); root.addAttribute("scanDate", (new java.util.Date()).toString()); root.addAttribute("R", request.getParameter("R")); root.addAttribute("epsilon", request.getParameter("epsilon")); root.addAttribute("Sizelim", request.getParameter("Sizelim")); root.addAttribute("maxTriangleRotation", request.getParameter("maxTriangleRotation")); root.addAttribute("C", request.getParameter("C")); for (int i = 0; i < matches.length; i++) { MatchObject mo = matches[i]; Element match = root.addElement("match"); match.addAttribute("points", (new Double(mo.matchValue)).toString()); match.addAttribute("adjustedpoints", (new Double(mo.adjustedMatchValue)).toString()); match.addAttribute("pointBreakdown", mo.pointBreakdown); String finalscore = (new Double(mo.matchValue * mo.adjustedMatchValue)).toString(); if (finalscore.length() > 7) { finalscore = finalscore.substring(0, 6); } match.addAttribute("finalscore", finalscore); //check if logM is very small... try { match.addAttribute("logMStdDev", (new Double(mo.getLogMStdDev())).toString()); } catch (java.lang.NumberFormatException nfe) { match.addAttribute("logMStdDev", "<0.01"); } match.addAttribute("evaluation", mo.getEvaluation()); Element enc = match.addElement("encounter"); enc.addAttribute("number", mo.encounterNumber); enc.addAttribute("date", mo.date); enc.addAttribute("sex", mo.catalogSex); enc.addAttribute("assignedToShark", mo.getIndividualName()); enc.addAttribute("size", ((new Double(mo.size)).toString() + " meters")); for (int k = 0; k < mo.scores.size(); k++) { Element spot = enc.addElement("spot"); spot.addAttribute("x", (new Double(((VertexPointMatch) mo.scores.get(k)).oldX)).toString()); spot.addAttribute("y", (new Double(((VertexPointMatch) mo.scores.get(k)).oldY)).toString()); } Element enc2 = match.addElement("encounter"); enc2.addAttribute("number", num); enc2.addAttribute("date", newEncDate); enc2.addAttribute("sex", mo.newSex); enc2.addAttribute("assignedToShark", newEncShark); enc2.addAttribute("size", (newEncSize + " meters")); for (int j = 0; j < mo.scores.size(); j++) { Element spot = enc2.addElement("spot"); spot.addAttribute("x", (new Double(((VertexPointMatch) mo.scores.get(j)).newX)).toString()); spot.addAttribute("y", (new Double(((VertexPointMatch) mo.scores.get(j)).newY)).toString()); } } //prep for writing out the XML //setup data dir String rootWebappPath = getServletContext().getRealPath("/"); File webappsDir = new File(rootWebappPath).getParentFile(); File shepherdDataDir = new File(webappsDir, CommonConfiguration.getDataDirectoryName(context)); //if(!shepherdDataDir.exists()){shepherdDataDir.mkdirs();} //File encountersDir=new File(shepherdDataDir.getAbsolutePath()+"/encounters"); //if(!encountersDir.exists()){encountersDir.mkdirs();} //in case this is a right-side scan, change file name to save to String fileAddition = ""; if ((request.getParameter("rightSide") != null) && (request.getParameter("rightSide").equals("true"))) { fileAddition = "Right"; } //File file=new File((new File(".")).getCanonicalPath()+File.separator+"webapps"+File.separator+"ROOT"+File.separator+"encounters"+File.separator+num+File.separator+"lastFull"+fileAddition+"Scan.xml"); //File file = new File(encountersDir.getAbsoluteFile()+"/"+ num + "/lastFull" + fileAddition + "Scan.xml"); File file = new File(Encounter.dir(shepherdDataDir, num) + "/lastFull" + fileAddition + "Scan.xml"); FileWriter mywriter = new FileWriter(file); org.dom4j.io.OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); org.dom4j.io.XMLWriter writer = new org.dom4j.io.XMLWriter(mywriter, format); writer.write(document); writer.close(); System.out.println("Successful write."); return true; } catch (Exception e) { System.out.println("Encountered an error trying to write back XML results!"); e.printStackTrace(); return false; } }
From source file:org.ecocean.servlet.WriteOutScanTask.java
License:Open Source License
public boolean writeResult(MatchObject[] swirs, String num, String R, String epsilon, String Sizelim, String maxTriangleRotation, String C, String newEncDate, String newEncShark, String newEncSize, boolean rightSide, double cutoff, Shepherd myShepherd, String context) { try {//from w ww .j av a2s .c o m //System.out.println("Prepping to write XML file for encounter "+num); //now setup the XML write for the encounter int resultsSize = swirs.length; MatchObject[] matches = swirs; Arrays.sort(matches, new MatchComparator()); StringBuffer resultsXML = new StringBuffer(); Document document = DocumentHelper.createDocument(); Element root = document.addElement("matchSet"); root.addAttribute("scanDate", (new java.util.Date()).toString()); root.addAttribute("R", R); root.addAttribute("epsilon", epsilon); root.addAttribute("Sizelim", Sizelim); root.addAttribute("maxTriangleRotation", maxTriangleRotation); root.addAttribute("C", C); int numMatches = matches.length; //hard limit this to 100 matches...no human really goes beyond this... if (numMatches > 100) numMatches = 100; for (int i = 0; i < numMatches; i++) { try { MatchObject mo = matches[i]; if ((mo.getMatchValue() > 0) && ((mo.getMatchValue() * mo.getAdjustedMatchValue()) > 2)) { Element match = root.addElement("match"); match.addAttribute("points", (new Double(mo.getMatchValue())).toString()); match.addAttribute("adjustedpoints", (new Double(mo.getAdjustedMatchValue())).toString()); match.addAttribute("pointBreakdown", mo.getPointBreakdown()); String finalscore = (new Double(mo.getMatchValue() * mo.getAdjustedMatchValue())) .toString(); if (finalscore.length() > 7) { finalscore = finalscore.substring(0, 6); } match.addAttribute("finalscore", finalscore); //check if logM is very small... try { match.addAttribute("logMStdDev", (new Double(mo.getLogMStdDev())).toString()); } catch (java.lang.NumberFormatException nfe) { match.addAttribute("logMStdDev", "<0.01"); } match.addAttribute("evaluation", mo.getEvaluation()); Encounter firstEnc = myShepherd.getEncounter(mo.getEncounterNumber()); Element enc = match.addElement("encounter"); enc.addAttribute("number", firstEnc.getEncounterNumber()); enc.addAttribute("date", firstEnc.getDate()); if (firstEnc.getSex() != null) { enc.addAttribute("sex", firstEnc.getSex()); } else { enc.addAttribute("sex", "unknown"); } enc.addAttribute("assignedToShark", ServletUtilities.handleNullString(firstEnc.getIndividualID())); if (firstEnc.getSizeAsDouble() != null) { enc.addAttribute("size", (firstEnc.getSize() + " meters")); } enc.addAttribute("location", firstEnc.getLocation()); enc.addAttribute("locationID", firstEnc.getLocationID()); VertexPointMatch[] firstScores = mo.getScores(); try { for (int k = 0; k < firstScores.length; k++) { Element spot = enc.addElement("spot"); spot.addAttribute("x", (new Double(firstScores[k].getOldX())).toString()); spot.addAttribute("y", (new Double(firstScores[k].getOldY())).toString()); } } catch (NullPointerException npe) { } Element enc2 = match.addElement("encounter"); Encounter secondEnc = myShepherd.getEncounter(num); enc2.addAttribute("number", num); enc2.addAttribute("date", secondEnc.getDate()); //enc2.addAttribute("sex", secondEnc.getSex()); if (secondEnc.getSex() != null) { enc2.addAttribute("sex", secondEnc.getSex()); } else { enc2.addAttribute("sex", "unknown"); } enc2.addAttribute("assignedToShark", ServletUtilities.handleNullString(secondEnc.getIndividualID())); if (secondEnc.getSizeAsDouble() != null) { enc2.addAttribute("size", (secondEnc.getSize() + " meters")); } else { enc2.addAttribute("size", "unknown"); } enc2.addAttribute("location", secondEnc.getLocation()); enc2.addAttribute("locationID", secondEnc.getLocationID()); try { for (int j = 0; j < firstScores.length; j++) { Element spot = enc2.addElement("spot"); spot.addAttribute("x", (new Double(firstScores[j].getNewX())).toString()); spot.addAttribute("y", (new Double(firstScores[j].getNewY())).toString()); } } catch (NullPointerException npe) { } //let's find the keywords in common List<String> keywords = myShepherd.getKeywordsInCommon(mo.getEncounterNumber(), num); int keywordsSize = keywords.size(); if (keywordsSize > 0) { Element kws = match.addElement("keywords"); for (int y = 0; y < keywordsSize; y++) { Element keyword = kws.addElement("keyword"); keyword.addAttribute("name", ((String) keywords.get(y))); } } } //end if } catch (Exception finale) { finale.printStackTrace(); } } //end for //prep for writing out the XML //in case this is a right-side scan, change file name to save to String fileAddition = ""; if (rightSide) { fileAddition = "Right"; } //setup data dir String rootWebappPath = getServletContext().getRealPath("/"); File webappsDir = new File(rootWebappPath).getParentFile(); File shepherdDataDir = new File(webappsDir, CommonConfiguration.getDataDirectoryName(context)); //if(!shepherdDataDir.exists()){shepherdDataDir.mkdirs();} File encountersDir = new File(shepherdDataDir.getAbsolutePath() + "/encounters"); //if(!encountersDir.exists()){encountersDir.mkdirs();} String thisEncDirString = Encounter.dir(shepherdDataDir, num); File thisEncounterDir = new File(thisEncDirString); if (!thisEncounterDir.exists()) { thisEncounterDir.mkdirs(); System.out.println("I am making the encDir: " + thisEncDirString); } //File file=new File((new File(".")).getCanonicalPath()+File.separator+"webapps"+File.separator+"ROOT"+File.separator+"encounters"+File.separator+num+File.separator+"lastFull"+fileAddition+"Scan.xml"); File file = new File(Encounter.dir(shepherdDataDir, num) + "/lastFull" + fileAddition + "Scan.xml"); System.out.println("Writing scanTask XML file to: " + file.getAbsolutePath()); FileWriter mywriter = new FileWriter(file); org.dom4j.io.OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); org.dom4j.io.XMLWriter writer = new org.dom4j.io.XMLWriter(mywriter, format); writer.write(document); writer.close(); System.out.println("Successful write."); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:org.ecocean.servlet.WriteOutScanTask.java
License:Open Source License
public boolean i3sWriteThis(Shepherd myShepherd, MatchObject[] matches, String num, String newEncDate, String newEncShark, String newEncSize, boolean rightSide, double cutoff, String context) { try {//from ww w . ja v a2 s .com System.out.println("scanWorkItemResultsHandler: Prepping to write I3S XML file for encounter " + num); //now setup the XML write for the encounter //int resultsSize=results.size(); Arrays.sort(matches, new NewI3SMatchComparator()); StringBuffer resultsXML = new StringBuffer(); Document document = DocumentHelper.createDocument(); Element root = document.addElement("matchSet"); root.addAttribute("scanDate", (new java.util.Date()).toString()); //System.out.println("Total num matches for I3S printing: "+matches.length); int numMatches = matches.length; //hard limit this to 100 matches...no human really goes beyond this... if (numMatches > 100) numMatches = 100; for (int i = 0; i < numMatches; i++) { try { //System.out.println(); MatchObject mo = matches[i]; //System.out.println("I3S match value: "+mo.getI3SMatchValue()); if ((mo.getI3SMatchValue() > 0.001) && (mo.getI3SMatchValue() <= 2.0)) { Element match = root.addElement("match"); String finalscore = (new Double(mo.getI3SMatchValue())).toString(); if (finalscore.length() > 7) { finalscore = finalscore.substring(0, 6); } match.addAttribute("finalscore", finalscore); match.addAttribute("evaluation", mo.getEvaluation()); Element enc = match.addElement("encounter"); enc.addAttribute("number", mo.getEncounterNumber()); enc.addAttribute("date", mo.getDate()); if (mo.getSex() != null) { enc.addAttribute("sex", mo.getSex()); } else { enc.addAttribute("sex", "unknown"); } enc.addAttribute("assignedToShark", mo.getIndividualName()); enc.addAttribute("size", (new Double(mo.getSize())).toString()); //get the Map Vector map = mo.getMap2(); int mapSize = map.size(); Encounter e1 = myShepherd.getEncounter(mo.getEncounterNumber()); for (int f = 0; f < mapSize; f++) { Pair tempPair = (com.reijns.I3S.Pair) map.get(f); int M1 = tempPair.getM1(); ArrayList<SuperSpot> spts = new ArrayList<SuperSpot>(); if (rightSide) { spts = e1.getRightSpots(); } else { spts = e1.getSpots(); } //System.out.println("scanWorkItemResultsHandler: I3S spots: "+spts.size()+" vs mapSize: "+mapSize); Element spot = enc.addElement("spot"); spot.addAttribute("x", (new Double(spts.get(M1).getTheSpot().getCentroidX())).toString()); spot.addAttribute("y", (new Double(spts.get(M1).getTheSpot().getCentroidY())).toString()); } Element enc2 = match.addElement("encounter"); enc2.addAttribute("number", num); enc2.addAttribute("date", newEncDate); enc2.addAttribute("sex", mo.getNewSex()); enc2.addAttribute("assignedToShark", newEncShark); enc2.addAttribute("size", newEncSize); //reset the Iterator Encounter e2 = myShepherd.getEncounter(num); for (int g = 0; g < mapSize; g++) { Pair tempPair = (com.reijns.I3S.Pair) map.get(g); int M2 = tempPair.getM2(); ArrayList<SuperSpot> spts = new ArrayList<SuperSpot>(); if (rightSide) { spts = e2.getRightSpots(); } else { spts = e2.getSpots(); } Element spot = enc2.addElement("spot"); //System.out.println("scanWorkItemResultsHandler: I3S next spots: "+spts.size()+" vs mapSize: "+mapSize); spot.addAttribute("x", (new Double(spts.get(M2).getTheSpot().getCentroidX())).toString()); spot.addAttribute("y", (new Double(spts.get(M2).getTheSpot().getCentroidY())).toString()); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } //prep for writing out the XML //in case this is a right-side scan, change file name to save to String fileAddition = ""; if (rightSide) { fileAddition = "Right"; } //setup data dir String rootWebappPath = getServletContext().getRealPath("/"); File webappsDir = new File(rootWebappPath).getParentFile(); File shepherdDataDir = new File(webappsDir, CommonConfiguration.getDataDirectoryName(context)); //if(!shepherdDataDir.exists()){shepherdDataDir.mkdirs();} File encountersDir = new File(shepherdDataDir.getAbsolutePath() + "/encounters"); //if(!encountersDir.exists()){encountersDir.mkdirs();} //File file=new File((new File(".")).getCanonicalPath()+File.separator+"webapps"+File.separator+"ROOT"+File.separator+"encounters"+File.separator+num+File.separator+"lastFull"+fileAddition+"I3SScan.xml"); File file = new File(Encounter.dir(shepherdDataDir, num) + "/lastFull" + fileAddition + "I3SScan.xml"); FileWriter mywriter = new FileWriter(file); org.dom4j.io.OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); org.dom4j.io.XMLWriter writer = new org.dom4j.io.XMLWriter(mywriter, format); writer.write(document); writer.close(); System.out.println("writeOutScanTask: Successful I3S write."); return true; } catch (Exception e) { System.out.println("writeOutScanTask: Failed to write out I3S results!"); e.printStackTrace(); return false; } }
From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.taxonomy.TaxonomyRepositoryHibernate.java
License:Open Source License
@SuppressWarnings("rawtypes") public String makeTree(Code rootCode) { int depth = findMaxDepthInTaxonomy(rootCode, rootCode.getOrganization().getPartyUid()); char[] alphas = new char[depth + 1]; for (int c = 0; c <= depth; c++) alphas[c] = (char) (97 + c); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("node"); // need to update root.addAttribute("code", rootCode.getCode()); root.addAttribute("type", rootCode.getCodeType().getLabel()); root.addAttribute("depth", "0"); root.addAttribute("codeId", rootCode.getCodeId().toString()); root.addAttribute("codeUId", rootCode.getCodeUid().toString()); root.addAttribute("taxonomyImageUrl", rootCode.getTaxonomyImageUrl()); root.addAttribute("displayCode", rootCode.getdisplayCode()); root.addAttribute("activeFlag", rootCode.getActiveFlag() + ""); String q1 = "select label from taxonomy_level_type where code_id=" + rootCode.getRootNodeId() + " order by depth"; @SuppressWarnings("unchecked") List<String> labels = this.getJdbcTemplate().query(q1, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString("label"); }/* ww w. j ava 2 s. c o m*/ }); for (int i = 1; i <= depth; i++) { StringBuilder query = new StringBuilder("SELECT "); for (int j = 0; j <= i; j++) { query.append(alphas[j] + ".display_code, " + alphas[j] + ".code_image, " + alphas[j] + ".code_uid, " + alphas[j] + ".code_id, " + alphas[j] + ".display_order, " + alphas[j] + ".depth, " + alphas[j] + ".label as '" + labels.get(j) + "', " + alphas[j] + ".code as '" + labels.get(j) + "' "); if (j != i) { query.append(","); } } query.append(" from "); for (int j = 0; j <= i; j++) { query.append(" code " + alphas[j]); if (j != i) { query.append(","); } } query.append(" where "); for (int j = 0; j <= i; j++) { query.append(alphas[j] + ".depth=" + j); // if(j!=i) query.append(" and "); } for (int j = 0; j < i; j++) { query.append(alphas[j + 1] + ".parent_id=" + alphas[j] + ".code_id"); // if(j!=i-1) query.append(" and " + alphas[j + 1] + ".active_flag=1 and "); } query.append(alphas[0] + ".code_id=" + rootCode.getCodeId()); query.append(" and " + alphas[0] + ".active_flag=1"); @SuppressWarnings("unchecked") List<String[]> labelss = this.getJdbcTemplateReadOnly().query(query.toString(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { final ResultSetMetaData metaData = rs.getMetaData(); final int noofcolumns = metaData.getColumnCount(); final String label[] = new String[noofcolumns]; for (int m = 1; m <= noofcolumns; m++) { label[m - 1] = rs.getString(m); } return label; } }); @SuppressWarnings("unchecked") List<Node> nodes = doc.selectNodes("//node"); for (String[] array : labelss) { int length = array.length; for (Node node : nodes) { Element parent = (Element) node; String att = parent.attribute("code").getText(); if (att.equals(array[length - 9])) { // Element child = parent.addElement(labels.get(i)); Element child = parent.addElement("node"); child.addAttribute("type", labels.get(i)); child.addAttribute("code", array[length - 1]); child.addAttribute("label", array[length - 2]); child.addAttribute("depth", array[length - 3]); child.addAttribute("order", array[length - 4]); child.addAttribute("codeId", array[length - 5]); child.addAttribute("codeUId", array[length - 6]); String taxonomyImageUrl = array[length - 7] != null ? rootCode.getAssetURI() + array[length - 7] : ""; child.addAttribute("taxonomyImageUrl", taxonomyImageUrl); String displayCode = array[length - 8]; if (displayCode != null) child.addAttribute("displayCode", array[length - 8]); else child.addAttribute("displayCode", ""); child.addAttribute("activeFlag", rootCode.getActiveFlag() + ""); } } } } return doc.asXML(); }
From source file:org.etudes.api.app.melete.util.XMLHelper.java
License:Apache License
/** * Creates xml docuemnt and adds element * @param element// w ww .j ava 2s. c o m */ static public Document createXMLDocument(Element element) { Document document = DocumentHelper.createDocument(); document.add(element); return document; }