List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:org.plasma.provisioning.cli.UMLTool.java
License:Open Source License
/** * Command line entry point. // w w w . ja v a 2 s .c om * <p></p> * <b>Usage:</b> java org.plasma.provisioning.cli.UMLTool * [source <rdb | xsd, ...>] * [dialect <oracle | mysql, ...>] * [platform <papyrus | magicdraw, ...>] * [dest-file] [namespace1, namespace2, ...] * [schema1, schema2, ...] <b>*</b> * <p></p> * <b>Where:</b> * <li><b>-source</b> is one of [rdb | xsd, ...]. * The <i>rdb</i> source interrogates one or more database schemas, using * vendor specific system tables, and generates a UML model for the given UML editing <i>platform</i> * which captures the physical attributes of the database including all tables, * columns, constraints, sequences and comments. Check constraints where the * search condition involves limiting the associated property to a list of values * are captured and used to produce annotated UML enumerations which * are automatically linked as UML enumeration constraints to the * source property.</li> * <li><b>dialect</b> is one of [oracle | mysql, ...] and the specific database product version is determined at runtime</li> * <li><b>platform</b> is one of [papyrus | magicdraw, ...]</li> * <li><b>dest-file</b> is the file name for the target artifact</li> * <li><b>namespace1, namespace2, ...</b> is the comma separated set of namespace URIs used to annotate the UML package(s). If more than one * schema is used, each schema name is used as a suffix. If no namespace-URI is present * a namespace URI based on the destination file name is constructed.</li> * <li><b>schema1, schema2, ...</b> is a set of source RDB schemas separated by commas</li> */ public static void main(String[] args) throws JAXBException, SAXException, IOException { if (args.length < 1) { printUsage(); return; } UMLToolSource source = null; try { String sourceArg = args[0]; if (sourceArg.startsWith("-")) sourceArg = sourceArg.substring(1); source = UMLToolSource.valueOf(sourceArg); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "'" + args[0] + "' - expected one of [" + UMLToolSource.asString() + "]"); } RDBDialect dialect = null; switch (source) { case rdb: try { String dialectArg = args[1]; if (dialectArg.startsWith("-")) dialectArg = dialectArg.substring(1); dialect = RDBDialect.valueOf(dialectArg); } catch (IllegalArgumentException e) { printUsage(); throw new IllegalArgumentException( "'" + args[1] + "' - expected one of [" + RDBDialect.asString() + "]"); } File dest = new File(args[2]); if (!dest.getParentFile().exists()) dest.getParentFile().mkdirs(); break; case xsd: default: printUsage(); break; } UMLDialect platform = UMLDialect.papyrus; String[] schemaNames = null; String[] namespaces = null; if (args.length == 6) { namespaces = args[4].split(","); schemaNames = args[5].split(","); if (namespaces.length != schemaNames.length) throw new RDBException( "expected 'schemaNames' and 'namespaces' arguments with equal number of comma seperated values"); try { String platformArg = args[3]; if (platformArg.startsWith("-")) platformArg = platformArg.substring(1); platform = UMLDialect.valueOf(platformArg); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "'" + args[3] + "' - expected one of [" + UMLDialect.asString() + "]"); } } else if (args.length == 5) { namespaces = args[3].split(","); schemaNames = args[4].split(","); if (namespaces.length != schemaNames.length) throw new RDBException( "expected 'schemaNames' and 'namespaces' arguments with equal number of comma seperated values"); } else { schemaNames = args[3].split(","); namespaces = new String[schemaNames.length]; for (int i = 0; i < schemaNames.length; i++) namespaces[i] = "http://" + schemaNames[i]; } Model model = (new RDBReader()).read(dialect, schemaNames, namespaces); File dest = new File(args[2]); if (!dest.getParentFile().exists()) dest.getParentFile().mkdirs(); if (log.isDebugEnabled()) { ProvisioningModelDataBinding provBinding = new ProvisioningModelDataBinding( new DefaultValidationEventHandler()); String xml = provBinding.marshal(model); File outFile = new File(dest.getParentFile(), "technical-model.xml"); OutputStream stream = new FileOutputStream(outFile); stream.write(xml.getBytes()); stream.flush(); stream.close(); log.debug("wrote merged model file to: " + outFile.getAbsoluteFile()); log.debug("reading merged model file: " + outFile.getAbsoluteFile()); model = (Model) provBinding.unmarshal(new FileInputStream(outFile)); } ModelAdapter helper = new ModelAdapter(model); UMLModelAssembler umlAssembler = null; switch (platform) { case papyrus: umlAssembler = new PapyrusModelAssembler(model, namespaces[0], "tns"); break; case magicdraw: umlAssembler = new MDModelAssembler(model, namespaces[0], "tns"); break; } umlAssembler.setDerivePackageNamesFromURIs(false); Document document = umlAssembler.getDocument(); log.info("marshaling XMI model to " + dest.getAbsolutePath()); try { FileOutputStream os = new FileOutputStream(dest); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(document, os); } catch (FileNotFoundException e) { throw new ProvisioningException(e); } catch (IOException e) { throw new ProvisioningException(e); } }
From source file:org.polago.deployconf.DeploymentWriter.java
License:Open Source License
/** * Write the given DeploymentConfig to persistent storage. * * @param deploymentConfig the DeploymentConfig to persist * @throws IOException indicating IO problems *//*from w ww. j ava2 s . c o m*/ public void persist(DeploymentConfig deploymentConfig) throws IOException { Format format = Format.getPrettyFormat(); format.setLineSeparator(LineSeparator.UNIX); format.setExpandEmptyElements(true); XMLOutputter outputter = new XMLOutputter(format); Element root = new Element(DOM_ROOT); String name = deploymentConfig.getName(); if (name != null) { root.setAttribute(ATTR_NAME, name); } Document document = new Document(); document.setRootElement(root); for (Task task : deploymentConfig.getTasks()) { Element node = new Element(task.getSerializedName()); root.addContent(node); task.serialize(node, groupManager); } outputter.output(document, outputStream); }
From source file:org.rascalmpl.library.lang.xml.DOM.java
License:Open Source License
public IString xmlPretty(IConstructor node) throws IOException { return xmlToString(node, Format.getPrettyFormat()); }
From source file:org.rhwlab.ace3d.Ace3D_Frame.java
private void saveSession(File xml) throws Exception { Element root = new Element("Ace3DSession"); if (bhc != null) { root.addContent(bhc.toXML());/*from w ww . j a va 2 s. c om*/ } root.addContent(imagedEmbryo.toXML()); Element dsProps = new Element("DataSets"); for (String ds : dataSetProperties.keySet()) { DataSetProperties props = dataSetProperties.get(ds); Element dsEle = props.toXML(); dsEle.setAttribute("Name", ds); dsProps.addContent(dsEle); } root.addContent(dsProps); OutputStream stream = new FileOutputStream(xml); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream); stream.close(); props.setProperty("Session", xml.getPath()); sessionXML = xml; }
From source file:org.rhwlab.BHC.BHCTree.java
public void saveAsXML(String file) throws Exception { OutputStream stream = new FileOutputStream(file); Element root = new Element("BHCTrees"); root.setAttribute("alpha", Double.toString(alpha)); StringBuilder builder = new StringBuilder(); builder.append("("); for (int i = 0; i < s.length; ++i) { builder.append(s[i]);// w w w. ja v a2 s. com builder.append(" "); } builder.append(")"); root.setAttribute("s", builder.toString()); root.setAttribute("nu", Integer.toString(nu)); builder = new StringBuilder(); builder.append("("); for (int d = 0; d < mu.length; ++d) { builder.append(mu[d]); builder.append(" "); } builder.append(")"); root.setAttribute("mu", builder.toString()); for (Node node : roots) { ((NodeBase) node).saveAsTreeXML(time, root); TreeSet<Double> posts = new TreeSet<>(); ((NodeBase) node).allPosteriors(posts); int aoshdfuihs = 0; } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream); stream.close(); }
From source file:org.rhwlab.BHC.BHCTree.java
public static void saveXML(String file, Element root) throws Exception { File f = new File(file); File outFile = new File(f.getParent(), f.getName()); OutputStream stream = new FileOutputStream(outFile); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream);/*from www . ja va 2s . c om*/ stream.close(); }
From source file:org.rhwlab.BHC.NodeBase.java
static public void saveAsTreeListXML(int time, String file, List<Node> nodes) throws Exception { OutputStream stream = new FileOutputStream(file); Element root = new Element("BHCTrees"); for (Node node : nodes) { ((NodeBase) node).saveAsTreeXML(time, root); }/*from ww w .ja v a 2 s.co m*/ XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream); stream.close(); }
From source file:org.rhwlab.BHCnotused.Cluster.java
static void saveClusterListAsXML(String file, List<Cluster> clusters, double threshold) throws Exception { OutputStream stream = new FileOutputStream(file); Element root = new Element("BHCClusterList"); int id = 1;/*from w w w . j a va 2 s . com*/ for (Cluster cl : clusters) { id = cl.saveAsXML(root, threshold, id) + 1; } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream); stream.close(); }
From source file:org.rhwlab.dispim.datasource.ClusteredDataSource.java
public void saveAsXML(String file) throws Exception { OutputStream stream = new FileOutputStream(file); Element root = new Element("KMeansClustering"); root.setAttribute("NumberOfClusters", Integer.toString(centers.length)); root.setAttribute("Partitions", Integer.toString(partitions)); root.setAttribute("Dimensions", Integer.toString(D)); root.setAttribute("NumberOfPoints", Long.toString(this.getN())); root.setAttribute("SegmentationThreshold", Double.toString(segThresh)); root.setAttribute("MinimumIntensity", Integer.toString(minIntensity)); root.setAttribute("MaximumIntensity", Integer.toString(maxIntensity)); for (int c = 0; c < gaussians.size(); ++c) { GaussianComponent comp = gaussians.get(c); Element ele = new Element("Cluster"); double[] center = comp.getMean().toArray(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < center.length; ++i) { if (i > 0) { builder.append(" "); }//from w w w.j a va 2 s .com builder.append(center[i]); } ele.setAttribute("Center", builder.toString()); ele.setAttribute("PointCount", Integer.toString(comp.getN())); ele.setAttribute("MinimumIntensity", Integer.toString(this.clusterMinIntensity[c])); ele.setAttribute("MaximumIntensity", Integer.toString(this.clusterMaxIntensity[c])); double avgAdjusted = 0.0; for (int n : comp.getIndexes()) { Element pointEle = new Element("Point"); double[] point = this.X[n].coords.toArray(); int intensity = this.X[n].intensity; pointEle.setAttribute("Intensity", Integer.toString(intensity)); double adj = this.X[n].getAdjusted(); avgAdjusted = avgAdjusted + adj; pointEle.setAttribute("Adjusted", Double.toString(adj)); builder = new StringBuilder(); for (int d = 0; d < point.length; ++d) { if (d > 0) { builder.append(" "); } builder.append(point[d]); } pointEle.addContent(builder.toString()); ele.addContent(pointEle); } ele.setAttribute("AvgAdjusted", Double.toString(avgAdjusted / comp.indexes.size())); root.addContent(ele); } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream); stream.close(); }
From source file:org.rhwlab.variationalbayesian.GaussianMixture.java
public void saveAsXML(String file) throws Exception { FileOutputStream stream = new FileOutputStream(file, false); Element root = new Element("document"); for (int k = 0; k < K; ++k) { if (N[k] > 1) { Element gmm = new Element("GaussianMixtureModel"); gmm.setAttribute("id", String.format("%d", k)); gmm.setAttribute("parent", "-1"); gmm.setAttribute("N", String.format("%f", N[k])); gmm.setAttribute("detW", String.format("%e", detW[k])); gmm.setAttribute("lnLamdbaTilde", String.format("%f", this.lnLambdaTilde[k])); gmm.setAttribute("nu", String.format("%f", nu[k])); gmm.setAttribute("lnPi", String.format("%f", lnPi[k])); StringBuilder builder = new StringBuilder(); for (int d = 0; d < X.getD(); ++d) { if (d > 0) { builder.append(" "); }//from ww w . ja v a2 s . co m builder.append(m[k].getEntry(d)); } gmm.setAttribute("m", builder.toString()); // double c = Math.pow(Math.exp(this.lnLambdaTilde[k])/this.detW[k],1.0/X.getD()); builder = new StringBuilder(); for (int row = 0; row < X.getD(); ++row) { for (int col = 0; col < X.getD(); ++col) { if (row > 0 || col > 0) { builder.append(" "); } builder.append(W[k].getEntry(row, col)); } } gmm.setAttribute("W", builder.toString()); builder = new StringBuilder(); for (int row = 0; row < X.getD(); ++row) { for (int col = 0; col < X.getD(); ++col) { if (row > 0 || col > 0) { builder.append(" "); } builder.append(W[k].getEntry(row, col)); } } gmm.setAttribute("W", builder.toString()); LUDecomposition cd = new LUDecomposition(S[k]); RealMatrix Sinv = cd.getSolver().getInverse(); builder = new StringBuilder(); for (int row = 0; row < X.getD(); ++row) { for (int col = 0; col < X.getD(); ++col) { if (row > 0 || col > 0) { builder.append(" "); } builder.append(Sinv.getEntry(row, col)); } } gmm.setAttribute("Sinv", builder.toString()); root.addContent(gmm); } } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(root, stream); }