001: /*
002: * Created on Apr 29, 2004
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.xdev.base.xssl.manage;
008:
009: import java.util.HashMap;
010:
011: import org.jdom.Document;
012: import org.jdom.Element;
013: import org.jdom.input.SAXBuilder;
014: import org.jdom.output.XMLOutputter;
015: import org.jdom.transform.JDOMSource;
016: import org.xdev.base.core.BASE;
017: import org.xdev.base.core.IPage;
018: import org.xdev.base.core.compiler.AXCompiler;
019: import org.xdev.base.xssl.XSSLAction;
020: import org.xdev.base.xssl.XSSLReturn;
021:
022: import java.io.StringReader;
023: import java.io.StringWriter;
024:
025: import javax.xml.transform.Transformer;
026: import javax.xml.transform.TransformerFactory;
027: import javax.xml.transform.stream.StreamResult;
028: import javax.xml.transform.stream.StreamSource;
029:
030: /**
031: * @author AYegorov
032: *
033: * To change the template for this generated type comment go to
034: * Window>Preferences>Java>Code Generation>Code and Comments
035: */
036: public class TransactionDocument extends XSSLReturn {
037:
038: private Object returnValue = null;
039:
040: /**
041: * @param id
042: */
043: public TransactionDocument(String id) {
044: super (id);
045: // XXX Auto-generated constructor stub
046: }
047:
048: /**
049: * @param id
050: * @param properties
051: */
052: public TransactionDocument(String id, HashMap properties) {
053: super (id, properties);
054: // XXX Auto-generated constructor stub
055: }
056:
057: /* (non-Javadoc)
058: * @see org.xdev.base.core.object.Configuration#getValue()
059: */
060: public Object getObjectValue() {
061:
062: return this .returnValue;
063: }
064:
065: /* (non-Javadoc)
066: * @see org.xdev.base.xssl.XSSLAction#set()
067: */
068: protected void set() throws Exception {
069: String rulePath = this .getProperty("rule-path");
070:
071: XSSLAction action = AXCompiler.getInstance().compileRule(
072: (IPage) this .getTransactionAction(),
073: BASE.getFile(rulePath, this .getClass()), rulePath);
074:
075: Document doc = new Document();
076:
077: Element root = new Element("book");
078:
079: doc.setRootElement(root);
080:
081: recursiveDocument(action, root);
082:
083: this .returnValue = new XMLOutputter().outputString(doc);
084:
085: try {
086: TransformerFactory transformerFactory = org.apache.xalan.processor.TransformerFactoryImpl
087: .newInstance();
088: Transformer transformer = transformerFactory
089: .newTransformer(new StreamSource(this
090: .getFileProperty("document-xsl")));
091:
092: StringWriter writer = new StringWriter();
093:
094: transformer.transform(new JDOMSource(doc),
095: new StreamResult(writer));
096:
097: this .returnValue = writer.toString();
098: } catch (Exception ex) {
099: if (this .getBooleanProperty("strict")) {
100: throw ex;
101: } else {
102: this .logError(ex);
103: }
104: }
105:
106: }
107:
108: private void recursiveDocument(XSSLAction action, Element root)
109: throws Exception {
110: int count = action.getCount();
111:
112: XSSLAction child = null;
113:
114: Element page = new Element("page");
115:
116: Element text = new Element("text");
117:
118: page.addContent(text);
119:
120: root.addContent(page);
121:
122: Element childPage = null;
123:
124: for (int i = 0; i < count; i++) {
125:
126: recursiveDocument((XSSLAction) action.getElement(i), page);
127: }
128:
129: StringBuffer buffer = new StringBuffer();
130:
131: /* if (action.document(buffer)) {
132:
133: text.setText(buffer.toString());
134: }
135: else {
136: SAXBuilder builder = new SAXBuilder();
137:
138: text.addContent(builder.build(new StringReader(buffer.toString())).getRootElement().detach());
139: }*/
140: }
141: }
|