private static void serializeEntry(TransformerHandler hd, Entry entry) throws SAXException { AttributesImpl entryAttributes = new AttributesImpl(); for (Iterator<String> it = entry.getAttributes().iterator(); it.hasNext(); ) { String key = it.next(); entryAttributes.addAttribute("", "", key, "", entry.getAttributes().getValue(key)); } hd.startElement("", "", ENTRY_ELEMENT, entryAttributes); StringList tokens = entry.getTokens(); for (Iterator<String> it = tokens.iterator(); it.hasNext(); ) { hd.startElement("", "", TOKEN_ELEMENT, new AttributesImpl()); String token = it.next(); hd.characters(token.toCharArray(), 0, token.length()); hd.endElement("", "", TOKEN_ELEMENT); } hd.endElement("", "", ENTRY_ELEMENT); }
protected void toXml(Record record) throws SAXException { if (!MarcFactory.newInstance().validateRecord(record)) { throw new MarcException("Marc record didn't validate"); } char temp[]; AttributesImpl atts = new AttributesImpl(); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 3); handler.startElement(Constants.MARCXML_NS_URI, RECORD, RECORD, atts); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.startElement(Constants.MARCXML_NS_URI, LEADER, LEADER, atts); Leader leader = record.getLeader(); temp = leader.toString().toCharArray(); handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, LEADER, LEADER); for (ControlField field : record.getControlFields()) { atts = new AttributesImpl(); atts.addAttribute("", "tag", "tag", "CDATA", field.getTag()); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.startElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, CONTROL_FIELD, atts); temp = getDataElement(field.getData()); handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, CONTROL_FIELD); } for (DataField field : record.getDataFields()) { atts = new AttributesImpl(); atts.addAttribute("", "tag", "tag", "CDATA", field.getTag()); atts.addAttribute("", "ind1", "ind1", "CDATA", String.valueOf(field.getIndicator1())); atts.addAttribute("", "ind2", "ind2", "CDATA", String.valueOf(field.getIndicator2())); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.startElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD, atts); for (Subfield subfield : field.getSubfields()) { atts = new AttributesImpl(); atts.addAttribute("", "code", "code", "CDATA", String.valueOf(subfield.getCode())); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 7); handler.startElement(Constants.MARCXML_NS_URI, SUBFIELD, SUBFIELD, atts); temp = getDataElement(subfield.getData()); handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, SUBFIELD, SUBFIELD); } if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.endElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD); } if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 3); handler.endElement(Constants.MARCXML_NS_URI, RECORD, RECORD); }
@Override public String serialize(List<Book> books) throws Exception { SAXTransformerFactory factory = (SAXTransformerFactory) TransformerFactory.newInstance(); // 取得SAXTransformerFactory实例 TransformerHandler handler = factory.newTransformerHandler(); // 从factory获取TransformerHandler实例 Transformer transformer = handler.getTransformer(); // 从handler获取Transformer实例 transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // 设置输出采用的编码方式 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // 是否自动添加额外的空白 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); // 是否忽略XML声明 StringWriter writer = new StringWriter(); Result result = new StreamResult(writer); handler.setResult(result); String uri = ""; // 代表命名空间的URI 当URI无值时 须置为空字符串 String localName = ""; // 命名空间的本地名称(不包含前缀) 当没有进行命名空间处理时 须置为空字符串 handler.startDocument(); handler.startElement(uri, localName, "books", null); AttributesImpl attrs = new AttributesImpl(); // 负责存放元素的属性信息 char[] ch = null; for (Book book : books) { attrs.clear(); // 清空属性列表 attrs.addAttribute( uri, localName, "id", "string", String.valueOf(book.getId())); // 添加一个名为id的属性(type影响不大,这里设为string) handler.startElement(uri, localName, "book", attrs); // 开始一个book元素 // 关联上面设定的id属性 handler.startElement(uri, localName, "name", null); // 开始一个name元素 // 没有属性 ch = String.valueOf(book.getName()).toCharArray(); handler.characters(ch, 0, ch.length); // 设置name元素的文本节点 handler.endElement(uri, localName, "name"); handler.startElement(uri, localName, "price", null); // 开始一个price元素 // 没有属性 ch = String.valueOf(book.getPrice()).toCharArray(); handler.characters(ch, 0, ch.length); // 设置price元素的文本节点 handler.endElement(uri, localName, "price"); handler.endElement(uri, localName, "book"); } handler.endElement(uri, localName, "books"); handler.endDocument(); return writer.toString(); }
/** * Generate the sitemap files. * * @throws IOException if the files could not be created. * @throws SAXException if a xml error occurs. */ public void generate() throws IOException, SAXException { int totalCount = 0; AttributesImpl schemaLocation = new AttributesImpl(); transformerHandler.startDocument(); transformerHandler.startPrefixMapping("xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI); transformerHandler.startPrefixMapping("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); schemaLocation.addAttribute( XMLConstants.W3C_XML_SCHEMA_NS_URI, "schemaLocation", "xsi:schemaLocation", "CDATA", "http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"); transformerHandler.startElement(NS, "", "sitemapindex", schemaLocation); for (final PageProvider provider : providers) { LOG.info("Processing " + provider.getName()); final SiteMap group = new SiteMap(provider.getName()); try { for (final Page page : provider) { if (null != page) { group.addPage(page); } } } finally { group.finish(); LOG.info(group.getCount() + " entries processed for " + provider.getName()); totalCount += group.getCount(); } for (final SiteMap.SiteMapFile map : group.getSiteMaps()) { transformerHandler.startElement("", "", "sitemap", new AttributesImpl()); addElement("loc", uri.resolve(map.getFileName()).toString()); addElement("lastmod", formatDateW3c((new Date()))); transformerHandler.endElement("", "", "sitemap"); } } transformerHandler.endElement(NS, "", "sitemapindex"); transformerHandler.endDocument(); writer.close(); LOG.info("All done (" + totalCount + " entries)"); }
public void executedAtExit(Store store, int solutionsNo) { try { hdTree.endElement("", "", "tree"); hdTree.endDocument(); hdVis.endElement("", "", "visualization"); hdVis.endDocument(); } catch (SAXException e) { e.printStackTrace(); } }
public void write(HttpServletResponse response) { StreamResult streamResult; SAXTransformerFactory tf; TransformerHandler hd; Transformer serializer; try { try { streamResult = new StreamResult(response.getWriter()); tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); hd = tf.newTransformerHandler(); serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM, "http://labs.omniti.com/resmon/trunk/resources/resmon.dtd"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); hd.setResult(streamResult); hd.startDocument(); AttributesImpl atts = new AttributesImpl(); hd.startElement("", "", "ResmonResults", atts); for (ResmonResult r : s) { r.write(hd); } hd.endElement("", "", "ResmonResults"); hd.endDocument(); } catch (TransformerConfigurationException tce) { response.getWriter().println(tce.getMessage()); } catch (SAXException se) { response.getWriter().println(se.getMessage()); } } catch (IOException ioe) { } }
public void create(Properties ctx, TransformerHandler document) throws SAXException { int AD_Column_ID = Env.getContextAsInt(ctx, X_AD_Column.COLUMNNAME_AD_Column_ID); AttributesImpl atts = new AttributesImpl(); X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID, getTrxName(ctx)); createColumnBinding(atts, m_Column); document.startElement("", "", "column", atts); document.endElement("", "", "column"); }
public void create(Properties ctx, TransformerHandler document) throws SAXException { int AD_Workflow_ID = Env.getContextAsInt(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); AttributesImpl atts = new AttributesImpl(); createWorkflowAccessBinding(atts, AD_Workflow_ID, AD_Role_ID); document.startElement("", "", "workflowaccess", atts); document.endElement("", "", "workflowaccess"); }
public void create(Properties ctx, TransformerHandler document) throws SAXException { int AD_Ref_List_ID = Env.getContextAsInt(ctx, X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx)); AttributesImpl atts = new AttributesImpl(); createRefListBinding(atts, m_Ref_List); document.startElement("", "", "referencelist", atts); document.endElement("", "", "referencelist"); }
@Override public void create(Properties ctx, TransformerHandler document) throws SAXException { String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType); AttributesImpl atts = new AttributesImpl(); createSQLStatmentBinding(atts, SQLStatement, DBType); document.startElement("", "", "SQLStatement", atts); document.endElement("", "", "SQLStatement"); }
public void create(Properties ctx, TransformerHandler document) throws SAXException { int AD_Form_ID = Env.getContextAsInt(ctx, "AD_Form_ID"); if (forms.contains(AD_Form_ID)) return; forms.add(AD_Form_ID); X_AD_Form m_Form = new X_AD_Form(ctx, AD_Form_ID, null); AttributesImpl atts = new AttributesImpl(); createFormBinding(atts, m_Form); document.startElement("", "", "form", atts); document.endElement("", "", "form"); }
/** * Writes the root end tag to the result. * * @throws SAXException */ protected void writeEndDocument() { try { if (indent) handler.ignorableWhitespace("\n".toCharArray(), 0, 1); handler.endElement(Constants.MARCXML_NS_URI, COLLECTION, COLLECTION); handler.endPrefixMapping(""); handler.endDocument(); } catch (SAXException e) { throw new MarcException("SAX error occured while writing end document", e); } }
private void addElement(final String element, final String string) throws SAXException { final AttributesImpl noAttributes = new AttributesImpl(); transformerHandler.startElement("", "", element, noAttributes); if (string != null) { transformerHandler.characters(string.toCharArray(), 0, string.length()); } transformerHandler.endElement("", "", element); }
public void finish() throws IOException { if (!finished) { try { transformerHandler.endElement(NS, "", "urlset"); transformerHandler.endDocument(); this.writer.close(); finished = true; } catch (SAXException e) { throw new RuntimeException(e); } } }
void generateSuccessNode(int searchNodeId) { try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "" + searchNodeId); hdTree.startElement("", "", "succ", atts); hdTree.endElement("", "", "succ"); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Save the specified object. * * @param object The node to load from. * @param hd The XML object. */ public void save(final EncogPersistedObject object, final TransformerHandler hd) { try { final AttributesImpl atts = EncogPersistedCollection.createAttributes(object); final BasicNetwork network = (BasicNetwork) object; hd.startElement("", "", network.getClass().getSimpleName(), atts); hd.startElement("", "", "layers", atts); for (final Layer layer : network.getLayers()) { if (layer instanceof EncogPersistedObject) { final EncogPersistedObject epo = (EncogPersistedObject) layer; final Persistor persistor = EncogPersistedCollection.createPersistor(layer.getClass().getSimpleName()); persistor.save(epo, hd); } } hd.endElement("", "", "layers"); hd.endElement("", "", network.getClass().getSimpleName()); } catch (final SAXException e) { throw new NeuralNetworkError(e); } }
/** * Save the specified object. * * @param object The object to save. * @param hd The XML object. */ public void save(final EncogPersistedObject object, final TransformerHandler hd) { try { final BasicNeuralDataSet set = (BasicNeuralDataSet) object; final AttributesImpl atts = EncogPersistedCollection.createAttributes(object); hd.startElement("", "", "BasicNeuralDataSet", atts); atts.clear(); for (final NeuralDataPair pair : set) { hd.startElement("", "", this.pairXML, atts); hd.startElement("", "", this.inputXML, atts); for (int i = 0; i < pair.getInput().size(); i++) { hd.startElement("", "", this.valueXML, atts); final String data = "" + pair.getInput().getData(i); hd.characters(data.toCharArray(), 0, data.length()); hd.endElement("", "", this.valueXML); } hd.endElement("", "", this.inputXML); hd.startElement("", "", this.idealXML, atts); for (int i = 0; i < pair.getIdeal().size(); i++) { hd.startElement("", "", this.valueXML, atts); final String data = "" + pair.getIdeal().getData(i); hd.characters(data.toCharArray(), 0, data.length()); hd.endElement("", "", this.valueXML); } hd.endElement("", "", this.idealXML); hd.endElement("", "", this.pairXML); } hd.endElement("", "", "BasicNeuralDataSet"); } catch (final SAXException e) { throw new NeuralNetworkError(e); } }
void prepareTreeHeader() { PrintWriter printWriter; try { printWriter = new PrintWriter(new FileOutputStream(treeFilename)); } catch (FileNotFoundException e) { e.printStackTrace(); printWriter = new PrintWriter(new StringWriter()); } StreamResult streamResult = new StreamResult(printWriter); SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); try { hdTree = tf.newTransformerHandler(); Transformer serializer = hdTree.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // "ISO-8859-1"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.STANDALONE, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); hdTree.setResult(streamResult); hdTree.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "version", "CDATA", "1.0"); atts.addAttribute("", "", "xmln:xsi", "CDATA", "http://www.w3.org/2001/XMLSchema-instance"); atts.addAttribute("", "", "xsi:noNamespaceSchemaLocation", "CDATA", "tree.xsd"); String ourText = " Generated by JaCoP solver; " + getDateTime() + " "; char[] comm = ourText.toCharArray(); hdTree.comment(comm, 0, comm.length); hdTree.startElement("", "", "tree", atts); atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "0"); hdTree.startElement("", "", "root", atts); hdTree.endElement("", "", "root"); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
void generateTrycNode(int searchNodeId, int parentNode, PrimitiveConstraint c) { try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "" + searchNodeId); atts.addAttribute("", "", "parent", "CDATA", "" + parentNode); atts.addAttribute("", "", "choice", "CDATA", c.toString()); hdTree.startElement("", "", "tryc", atts); hdTree.endElement("", "", "tryc"); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
void generateFailNode(int searchNodeId, int parentNode, String name, int size, int value) { try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "" + searchNodeId); atts.addAttribute("", "", "parent", "CDATA", "" + parentNode); atts.addAttribute("", "", "name", "CDATA", name); atts.addAttribute("", "", "size", "CDATA", "" + size); atts.addAttribute("", "", "value", "CDATA", "" + value); hdTree.startElement("", "", "fail", atts); hdTree.endElement("", "", "fail"); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Serializes the given entries to the given {@link java.io.OutputStream}. * * <p>After the serialization is finished the provided {@link java.io.OutputStream} remains open. * * @param out stream to serialize to * @param entries entries to serialize * @param casesensitive indicates if the written dictionary should be case sensitive or case * insensitive. * @throws java.io.IOException If an I/O error occurs */ public static void serialize(OutputStream out, Iterator<Entry> entries, boolean casesensitive) throws IOException { StreamResult streamResult = new StreamResult(out); SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler hd; try { hd = tf.newTransformerHandler(); } catch (TransformerConfigurationException e) { throw new AssertionError("The Transformer configuration must be valid!"); } Transformer serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, CHARSET); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); hd.setResult(streamResult); try { hd.startDocument(); AttributesImpl dictionaryAttributes = new AttributesImpl(); dictionaryAttributes.addAttribute( "", "", ATTRIBUTE_CASE_SENSITIVE, "", String.valueOf(casesensitive)); hd.startElement("", "", DICTIONARY_ELEMENT, dictionaryAttributes); while (entries.hasNext()) { Entry entry = entries.next(); serializeEntry(hd, entry); } hd.endElement("", "", DICTIONARY_ELEMENT); hd.endDocument(); } catch (SAXException e) { // TODO update after Java6 upgrade throw (IOException) new IOException("Error during serialization: " + e.getMessage()).initCause(e); } }
void generateFailcNode(int searchNodeId, int parentNode, String name, int size, Domain dom) { try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "" + searchNodeId); atts.addAttribute("", "", "parent", "CDATA", "" + parentNode); atts.addAttribute("", "", "name", "CDATA", name); atts.addAttribute("", "", "size", "CDATA", "" + size); // TODO, BUG? Why in the function above generateTrycNode, originally function filter*(dom) was // called and here // our toString() for dom is being called. atts.addAttribute("", "", "choice", "CDATA", "" + dom); hdTree.startElement("", "", "failc", atts); hdTree.endElement("", "", "failc"); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
void generateTrycNode(int searchNodeId, int parentNode, String name, int size, Domain dom) { try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "" + searchNodeId); atts.addAttribute("", "", "parent", "CDATA", "" + parentNode); atts.addAttribute("", "", "name", "CDATA", name); atts.addAttribute("", "", "size", "CDATA", "" + size); if (dom instanceof IntDomain) atts.addAttribute("", "", "choice", "CDATA", "" + intDomainToString((IntDomain) dom)); if (dom instanceof SetDomain) { atts.addAttribute("", "", "choice", "CDATA", "" + setDomainToString((SetDomain) dom)); } hdTree.startElement("", "", "tryc", atts); hdTree.endElement("", "", "tryc"); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void addPage(final Page page) throws SAXException { transformerHandler.startElement("", "", "url", new AttributesImpl()); addElement("loc", page.getLocation().toString()); if (null != page.getLastModified()) { addElement("lastmod", formatDateW3c(page.getLastModified())); } if (0.5 != page.getPriority()) { // 0.5 is the default and we don't want to waste tags. addElement("priority", Double.toString(page.getPriority())); } if (null != page.getFrequency()) { addElement("changefreq", page.getFrequency().name().toLowerCase()); } transformerHandler.endElement("", "", "url"); entryCount++; }
void generateVisualizationNode(int searchNodeId, boolean tryNode) { int visualizerState = 1; try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "id", "CDATA", "" + visualisationNodeId); atts.addAttribute("", "", "tree_node", "CDATA", "" + searchNodeId); hdVis.startElement("", "", "state", atts); if (tracedVar.size() != 0) { AttributesImpl visAtts = new AttributesImpl(); visAtts.addAttribute("", "", "id", "CDATA", "" + visualizerState); hdVis.startElement("", "", "visualizer_state", visAtts); // variable visualization for (int i = 0; i < tracedVar.size(); i++) { AttributesImpl vAtts = new AttributesImpl(); vAtts.addAttribute("", "", "index", "CDATA", "" + (int) (i + 1)); if (tracedVar.get(i) instanceof uk.ac.stir.cs.homer.homerPolicyServer.overlap.JaCoP.core.IntVar) { IntVar v = (IntVar) tracedVar.get(i); if (v.singleton()) { // IntVar vAtts.addAttribute("", "", "value", "CDATA", "" + v.value()); hdVis.startElement("", "", "integer", vAtts); hdVis.endElement("", "", "integer"); } else { vAtts.addAttribute("", "", "domain", "CDATA", intDomainToString((IntDomain) v.dom())); hdVis.startElement("", "", "dvar", vAtts); hdVis.endElement("", "", "dvar"); } } else { // setVar SetVar v = (SetVar) tracedVar.get(i); if (v.singleton()) { // IntVar vAtts.addAttribute( "", "", "value", "CDATA", "" + setDomainToString((SetDomain) v.dom())); hdVis.startElement("", "", "sinteger", vAtts); hdVis.endElement("", "", "sinteger"); } else { // TODO, BUG? Why the same thing is written to low and high attribute? vAtts.addAttribute("", "", "low", "CDATA", setDomainToString((SetDomain) v.dom())); vAtts.addAttribute("", "", "high", "CDATA", setDomainToString((SetDomain) v.dom())); hdVis.startElement("", "", "svar", vAtts); hdVis.endElement("", "", "svar"); } } visualizerState++; } if (varIndex.get(selectedVar) != null) { AttributesImpl vFocus = new AttributesImpl(); vFocus.addAttribute("", "", "index", "CDATA", "" + (int) (varIndex.get(selectedVar) + 1)); vFocus.addAttribute("", "", "group", "CDATA", "" + "default"); if (tryNode) { vFocus.addAttribute("", "", "type", "CDATA", ""); hdVis.startElement("", "", "focus", vFocus); hdVis.endElement("", "", "focus"); } else { // fail node vFocus.addAttribute("", "", "value", "CDATA", "" + selectedValue); hdVis.startElement("", "", "failed", vFocus); hdVis.endElement("", "", "failed"); } } hdVis.endElement("", "", "visualizer_state"); } hdVis.endElement("", "", "state"); visualisationNodeId++; } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
void prepareVizHeader() { PrintWriter printWriter; try { printWriter = new PrintWriter(new FileOutputStream(visFilename)); } catch (FileNotFoundException e) { e.printStackTrace(); printWriter = new PrintWriter(new StringWriter()); } StreamResult streamResult = new StreamResult(printWriter); SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); try { hdVis = tf.newTransformerHandler(); Transformer serializer = hdVis.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // "ISO-8859-1"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.STANDALONE, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); hdVis.setResult(streamResult); hdVis.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "version", "CDATA", "1.0"); atts.addAttribute("", "", "xmlns:xsi", "CDATA", "http://www.w3.org/2001/XMLSchema-instance"); atts.addAttribute("", "", "xsi:noNamespaceSchemaLocation", "CDATA", "visualization.xsd"); String ourText = " Generated by JaCoP solver; " + getDateTime() + " "; char[] comm = ourText.toCharArray(); hdVis.comment(comm, 0, comm.length); hdVis.startElement("", "", "visualization", atts); // visualizer if (tracedVar.size() != 0) { AttributesImpl visAtt = new AttributesImpl(); visAtt.addAttribute("", "", "id", "CDATA", "1"); visAtt.addAttribute("", "", "type", "CDATA", "vector"); visAtt.addAttribute("", "", "display", "CDATA", "expanded"); visAtt.addAttribute("", "", "group", "CDATA", "default"); visAtt.addAttribute("", "", "x", "CDATA", "0"); visAtt.addAttribute("", "", "y", "CDATA", "0"); int minV = minValue(tracedVar), maxV = maxValue(tracedVar); visAtt.addAttribute("", "", "width", "CDATA", "" + tracedVar.size()); visAtt.addAttribute("", "", "height", "CDATA", "" + (int) (maxV - minV + 1)); visAtt.addAttribute("", "", "min", "CDATA", "" + minV); visAtt.addAttribute("", "", "max", "CDATA", "" + maxV); hdVis.startElement("", "", "visualizer", visAtt); hdVis.endElement("", "", "visualizer"); } generateVisualizationNode(0, true); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void create(Properties ctx, TransformerHandler document) throws SAXException { int AD_PrintFormat_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID); PackOut packOut = (PackOut) ctx.get("PackOutProcess"); if (formats.contains(AD_PrintFormat_ID)) return; formats.add(AD_PrintFormat_ID); AttributesImpl atts = new AttributesImpl(); String sql = null; sql = "SELECT AD_PrintFormat_ID " + "FROM AD_PrintFormat " + "WHERE (AD_PrintFormat_ID IN " + "(SELECT AD_PrintFormatChild_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID = " + AD_PrintFormat_ID + " AND PrintFormatType = 'P' GROUP BY AD_PrintFormatChild_ID) OR AD_PrintFormat_ID = " + AD_PrintFormat_ID + ")"; PreparedStatement pstmt = null; pstmt = DB.prepareStatement(sql, getTrxName(ctx)); try { ResultSet rs = pstmt.executeQuery(); while (rs.next()) { X_AD_PrintFormat m_Printformat = new X_AD_PrintFormat(ctx, rs.getInt("AD_PrintFormat_ID"), null); if (m_Printformat.getAD_PrintPaper_ID() > 0) packOut.createPrintPaper(m_Printformat.getAD_PrintPaper_ID(), document); createPrintFormatBinding(atts, m_Printformat); document.startElement("", "", "printformat", atts); String sql2 = "SELECT * FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= " + m_Printformat.getAD_PrintFormat_ID() + " ORDER BY " + X_AD_PrintFormatItem.COLUMNNAME_SeqNo + "," + X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID; PreparedStatement pstmt2 = null; pstmt2 = DB.prepareStatement(sql2, getTrxName(ctx)); try { ResultSet rs2 = pstmt2.executeQuery(); while (rs2.next()) { createItem(ctx, document, rs2.getInt("AD_PrintFormatItem_ID")); } rs2.close(); pstmt2.close(); pstmt2 = null; } finally { try { if (pstmt2 != null) pstmt2.close(); } catch (Exception e) { } pstmt2 = null; } document.endElement("", "", "printformat"); } rs.close(); pstmt.close(); pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); if (e instanceof SAXException) throw (SAXException) e; else if (e instanceof SQLException) throw new DatabaseAccessException("Failed to export print format.", e); else if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new RuntimeException("Failed to export print format.", e); } finally { try { if (pstmt != null) pstmt.close(); } catch (Exception e) { } pstmt = null; } }
public void create(Properties ctx, TransformerHandler document) throws SAXException { int AD_Process_ID = Env.getContextAsInt(ctx, "AD_Process_ID"); if (processes.contains(AD_Process_ID)) return; processes.add(AD_Process_ID); PackOut packOut = (PackOut) ctx.get("PackOutProcess"); String sqlW = "SELECT AD_Process_ID FROM AD_PROCESS WHERE AD_PROCESS_ID = " + AD_Process_ID; AttributesImpl atts = new AttributesImpl(); PreparedStatement pstmt1 = null; pstmt1 = DB.prepareStatement(sqlW, getTrxName(ctx)); try { ResultSet rs1 = pstmt1.executeQuery(); while (rs1.next()) { X_AD_Process m_Process = new X_AD_Process(ctx, rs1.getInt("AD_Process_ID"), null); log.log(Level.INFO, "AD_ReportView_ID: " + m_Process.getAD_Process_ID()); if (m_Process.isReport() && m_Process.getAD_ReportView_ID() > 0) { packOut.createReportview(m_Process.getAD_ReportView_ID(), document); } if (m_Process.isReport() && m_Process.getAD_PrintFormat_ID() > 0) { packOut.createPrintFormat(m_Process.getAD_PrintFormat_ID(), document); } if (m_Process.getAD_Workflow_ID() > 0) { packOut.createWorkflow(m_Process.getAD_Workflow_ID(), document); } if (m_Process.getAD_Form_ID() > 0) { packOut.createForm(m_Process.getAD_Form_ID(), document); } if (m_Process.getAD_Browse_ID() > 0) { packOut.createBrowse(m_Process.getAD_Browse_ID(), document); } createProcessBinding(atts, m_Process); document.startElement("", "", "process", atts); // processpara tags String sqlP = "SELECT * FROM AD_PROCESS_PARA WHERE AD_PROCESS_ID = " + AD_Process_ID + " ORDER BY " + X_AD_Process_Para.COLUMNNAME_SeqNo + "," + X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID; PreparedStatement pstmtP = null; pstmtP = DB.prepareStatement(sqlP, getTrxName(ctx)); try { ResultSet rsP = pstmtP.executeQuery(); while (rsP.next()) { if (rsP.getInt("AD_Reference_ID") > 0) packOut.createReference(rsP.getInt("AD_Reference_ID"), document); if (rsP.getInt("AD_Reference_Value_ID") > 0) packOut.createReference(rsP.getInt("AD_Reference_Value_ID"), document); if (rsP.getInt("AD_Val_Rule_ID") > 0) packOut.createDynamicRuleValidation(rsP.getInt("AD_Val_Rule_ID"), document); createProcessPara(ctx, document, rsP.getInt("AD_Process_Para_ID")); } rsP.close(); pstmtP.close(); pstmtP = null; } catch (Exception e) { log.log(Level.SEVERE, "getProcess_Para", e); if (e instanceof SAXException) throw (SAXException) e; else if (e instanceof SQLException) throw new DatabaseAccessException("Failed to export process.", e); else if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new RuntimeException("Failed to export process.", e); } finally { try { if (pstmtP != null) pstmtP.close(); } catch (Exception e) { } pstmtP = null; } document.endElement("", "", "process"); } rs1.close(); pstmt1.close(); pstmt1 = null; } catch (Exception e) { log.log(Level.SEVERE, "getProcess", e); } finally { try { if (pstmt1 != null) pstmt1.close(); } catch (Exception e) { } pstmt1 = null; } }