Source Code Cross Referenced for XText.java in  » XML » activexml » org » xdev » base » xssl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » activexml » org.xdev.base.xssl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Nov 4, 2003
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;
008:
009:        import java.util.HashMap;
010:
011:        import org.jdom.Attribute;
012:        import org.jdom.Document;
013:        import org.jdom.Text;
014:
015:        import org.jaxen.jdom.JDOMXPath;
016:        import org.jdom.Element;
017:        import org.xdev.base.core.BaseSaxBuilder;
018:        import org.xdev.base.core.compiler.AXCompiler;
019:        import org.xdev.base.log.LoggerWriter;
020:        import org.xdev.base.resource.IDataSource;
021:
022:        /**
023:         * @author AYegorov
024:         *
025:         * To change the template for this generated type comment go to
026:         * Window>Preferences>Java>Code Generation>Code and Comments
027:         */
028:        public final class XText extends XSSLReturn {
029:            public static final String TRANSACTION_TEXT_TAG_NAME = "text";
030:
031:            private Object returnValue = null;
032:
033:            /**
034:             * @param id
035:             */
036:            public XText(String id) {
037:                super (id);
038:                // TODO Auto-generated constructor stub
039:            }
040:
041:            /**
042:             * @param id
043:             * @param properties
044:             */
045:            public XText(String id, HashMap properties) {
046:                super (id, properties);
047:            }
048:
049:            /* (non-Javadoc)
050:             * @see org.xdev.base.transaction.AbstractTransactionResult#set()
051:             */
052:            protected void set() throws Exception {
053:                if (this .getCount() > 0) {
054:                    XSSLReturn r = (XSSLReturn) this .getElement(0);
055:
056:                    if (r.execute(this )) {
057:
058:                        Object obj = r.getObjectValue();
059:
060:                        this .setReturnedText(obj != null ? obj.toString() : "");
061:                    }
062:                }
063:            }
064:
065:            public void setReturnedText(String text) {
066:                this .returnValue = text;
067:            }
068:
069:            /* (non-Javadoc)
070:             * @see org.xdev.base.transaction.AbstractTransactionResult#getValue()
071:             */
072:            public Object getObjectValue() {
073:                StringBuffer buffer = new StringBuffer();
074:
075:                try {
076:                    String key = (String) this .returnValue;
077:
078:                    XText.compileText(key, buffer, AXCompiler.getInstance(),
079:                            this );
080:
081:                } catch (Exception ex) {
082:                    this .logError(ex);
083:
084:                    buffer.setLength(0);
085:
086:                    buffer.append(this .returnValue);
087:                }
088:
089:                return buffer.toString();
090:            }
091:
092:            public static void parseText(String response, StringBuffer result,
093:                    AXCompiler ap) throws Exception {
094:                String keyword = null;
095:
096:                String before = null;
097:
098:                while (response != null && response.indexOf("{!/") != -1
099:                        && response.indexOf("}") != -1) {
100:
101:                    before = response.substring(0, response.indexOf("{!/"));
102:
103:                    result.append(before);
104:
105:                    keyword = response.substring(response.indexOf("{!/") + 3,
106:                            response.indexOf("}"));
107:
108:                    response = response.substring(response.indexOf("}") + 1,
109:                            response.length());
110:
111:                    result.append(XText.getResolvedResults(keyword, ap));
112:                }
113:
114:                result.append(response);
115:            }
116:
117:            public static void compileText(String response,
118:                    StringBuffer result, AXCompiler ap, XSSLAction parent)
119:                    throws Exception {
120:                String keyword = null;
121:
122:                String before = null;
123:
124:                StringBuffer temp = new StringBuffer();
125:
126:                BaseSaxBuilder builder = new BaseSaxBuilder();
127:
128:                Element root = null;
129:
130:                Document doc = null;
131:
132:                XSSLAction action = null;
133:
134:                Object obj = null;
135:
136:                while (response != null && response.indexOf("[@") != -1
137:                        && response.indexOf("@]") != -1) {
138:
139:                    before = response.substring(0, response.indexOf("[@"));
140:
141:                    result.append(before);
142:
143:                    keyword = response.substring(response.indexOf("[@") + 2,
144:                            response.indexOf("@]"));
145:
146:                    parseText(keyword, temp, ap);
147:
148:                    LoggerWriter.log("Building source xml: " + temp);
149:
150:                    AXCompiler compiler = AXCompiler.getInstance();
151:
152:                    doc = builder.build(temp.toString(), AXCompiler.getTypes());
153:
154:                    root = doc.getRootElement();
155:
156:                    action = (XSSLAction) compiler.getCompiledComponent(parent
157:                            .getConfig(), root, parent, (XSSLAction) parent
158:                            .getRoot(), parent.getRulePath());
159:
160:                    action.setConfig(parent.getConfig());
161:
162:                    if (action.execute(parent) && action instanceof  XSSLReturn) {
163:
164:                        obj = ((XSSLReturn) action).getObjectValue();
165:
166:                        XText.compileText(obj.toString(), result, ap, action);
167:                    }
168:
169:                    response = response.substring(response.indexOf("@]") + 2,
170:                            response.length());
171:                }
172:
173:                parseText(response, result, ap);
174:            }
175:
176:            public static Object getResolvedResults(String keyword,
177:                    AXCompiler ap) throws Exception {
178:                Element root = null;
179:
180:                Object obj = null;
181:
182:                String ds = keyword.substring(0, keyword.indexOf("/"));
183:
184:                IDataSource source = ap.getDataSource(ds);
185:
186:                Document doc = (Document) source.getConnection();
187:
188:                root = doc.getRootElement();
189:
190:                if (root == null) {
191:                    root = AXCompiler.BASE_ROOT;
192:                }
193:
194:                JDOMXPath xpath = new JDOMXPath(keyword.substring(keyword
195:                        .indexOf("/"), keyword.length()));
196:
197:                obj = xpath.selectSingleNode(root);
198:
199:                return XText.resolveXmlElement(obj);
200:            }
201:
202:            public static Object resolveXmlElement(Object obj) {
203:                if (obj instanceof  Element) {
204:                    obj = ((Element) obj).getTextTrim();
205:                } else if (obj instanceof  Attribute) {
206:                    obj = ((Attribute) obj).getValue();
207:                } else if (obj instanceof  Text) {
208:                    obj = ((Text) obj).getTextTrim();
209:                }
210:
211:                return obj;
212:            }
213:
214:            /* (non-Javadoc)
215:             * @see org.xdev.base.transaction.AbstractTransaction#rollback()
216:             */
217:            public void rollback() throws Exception {
218:            }
219:
220:            /* (non-Javadoc)
221:             * @see org.xdev.base.transaction.AbstractTransaction#commit()
222:             */
223:            public void commit() {
224:            }
225:
226:            /* (non-Javadoc)
227:             * @see org.xdev.base.transaction.AbstractTransaction#setTagName()
228:             */
229:            protected String setTagName() {
230:                // TODO Auto-generated method stub
231:                return XText.TRANSACTION_TEXT_TAG_NAME;
232:            }
233:
234:            public Object clone() {
235:                XText xtxt = (XText) super .clone();
236:
237:                xtxt.setReturnedText((String) this.returnValue);
238:
239:                return xtxt;
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.