Source Code Cross Referenced for MacroTagHandler.java in  » Swing-Library » wings3 » org » wings » 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 » Swing Library » wings3 » org.wings 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package org.wings;
014:
015:        import org.wings.io.Device;
016:        import org.wings.macro.MacroContainer;
017:        import org.wings.macro.MacroContext;
018:        import org.wings.macro.MacroProcessor;
019:        import org.wings.plaf.CGManager;
020:        import org.wings.plaf.CmsTableCG;
021:        import org.wings.plaf.ComponentCG;
022:        import org.wings.session.SessionManager;
023:        import org.wings.template.CmsTemplateParseContext;
024:        import org.wings.template.PropertyManager;
025:        import org.wings.template.parser.ParseContext;
026:        import org.wings.template.parser.PositionReader;
027:        import org.wings.template.parser.SGMLTag;
028:        import org.wings.template.parser.SpecialTagHandler;
029:
030:        import java.io.IOException;
031:        import java.io.InputStream;
032:        import java.util.Iterator;
033:        import java.util.Map;
034:
035:        /**
036:         * <code>CmsObjectTagHandler<code>.
037:         * <p/>
038:         * User: raedler
039:         * Date: 08.08.2007
040:         * Time: 14:35:57
041:         *
042:         * @author raedler
043:         * @version $Id
044:         */
045:        public class MacroTagHandler implements  SpecialTagHandler {
046:            boolean close_is_missing = false;
047:
048:            long startPos;
049:            long endPos;
050:            Map properties;
051:            String name;
052:
053:            public long getTagStart() {
054:                return startPos;
055:            }
056:
057:            public long getTagLength() {
058:                return endPos - startPos;
059:            }
060:
061:            public void executeTag(ParseContext context, InputStream input)
062:                    throws Exception {
063:                CmsTemplateParseContext tcontext = (CmsTemplateParseContext) context;
064:                Device sink = tcontext.getDevice();
065:
066:                /*
067:                 * get the component that is associtated with this name. This has
068:                 * been set as Layout Manager Constraint.
069:                 */
070:                SComponent c = tcontext.getComponent(name);
071:                if (c == null) {
072:                    sink.print("<!-- Template: '" + name
073:                            + "' Component not given -->");
074:                } else {
075:
076:                    StringBuilder sb = new StringBuilder();
077:                    for (long i = getTagLength(); i > 0; i--) {
078:                        sb.append((char) input.read());
079:                    }
080:                    //            String content = sb.toString().replaceAll(System.getProperty("line.separator"), "");
081:                    //            content = content.replaceAll("\n", "");
082:                    //            Pattern pattern = Pattern.compile("<object[\\s]*name[\\s]*=[\\s]*\\\".*\\\"[\\s]*>\\n*(.*\\n)*\\n*<[\\s]*/object[\\s]*>");
083:                    //            Matcher matcher = pattern.matcher(sb.toString());
084:                    //
085:                    //            String macroTemplate = null;
086:                    //            if (matcher.matches()) {
087:                    //                macroTemplate = matcher.group(0);
088:                    //                macroTemplate = macroTemplate.substring(macroTemplate.indexOf('>') + 1, macroTemplate.lastIndexOf('<'));
089:                    //            }
090:
091:                    String macroTemplate = sb.toString();
092:                    macroTemplate = macroTemplate.substring(macroTemplate
093:                            .indexOf('>') + 1, macroTemplate.lastIndexOf('<'));
094:
095:                    if (macroTemplate != null
096:                            && !"".equals(macroTemplate.trim())) {
097:                        MacroProcessor macroProcessor = MacroProcessor
098:                                .getInstance();
099:
100:                        MacroContainer macroContainer = macroProcessor
101:                                .buildMacro(macroTemplate);
102:
103:                        MacroContext ctx = new MacroContext();
104:                        ctx.setDevice(sink);
105:                        ctx.setComponent(c);
106:                        ctx.put(name, c);
107:
108:                        macroContainer.setContext(ctx);
109:
110:                        //                if (c instanceof CmsForm) {
111:                        //                    SComponent child = ((CmsForm) c).getComponent();
112:                        //
113:                        //                    if (child instanceof STable) {
114:                        //                        CmsTableCG cg = new CmsTableCG();
115:                        //                        cg.setMacros(macroContainer);
116:                        //                        child.setCG(cg);
117:                        //                        c.write(sink);
118:                        //                    }
119:                        //                }
120:
121:                        if (c instanceof  STable) {
122:                            CmsTableCG cg = new CmsTableCG();
123:                            cg.setMacros(macroContainer);
124:                            c.setCG(cg);
125:                            c.write(sink);
126:                        }
127:
128:                        //String result = macroProcessor.handle(macroTemplate, name, tcontext);
129:                        //sink.print(result);
130:                    } else {
131:
132:                        CGManager cgManager = SessionManager.getSession()
133:                                .getCGManager();
134:                        ComponentCG cg = cgManager.getCG(c);
135:                        c.setCG(cg);
136:
137:                        // set properties; the STemplateLayout knows how
138:                        if (properties.size() > 0) {
139:                            PropertyManager propManager = CmsLayout
140:                                    .getPropertyManager(c.getClass());
141:
142:                            if (propManager != null) {
143:                                Iterator iter = properties.keySet().iterator();
144:                                while (iter.hasNext()) {
145:                                    String key = (String) iter.next();
146:                                    String value = (String) properties.get(key);
147:                                    // System.out.println("set Property " + key + "=" +value + "  for " + name);
148:                                    propManager.setProperty(c, key, value);
149:                                }
150:                            }
151:                        }
152:                        c.write(sink);
153:                    }
154:                    //            input.skip(getTagLength());
155:                }
156:            }
157:
158:            public SGMLTag parseTag(ParseContext context, PositionReader input,
159:                    long startPosition, SGMLTag startTag) throws IOException {
160:
161:                final String startTagName = startTag.getName();
162:                final String endTagName = "/" + startTagName;
163:
164:                /*
165:                 * parse the full tag to get all parameters
166:                 * (i.e. an optional 'format'-parameter)
167:                 * and to place the Reader at the position
168:                 * after the closing '>'
169:                 */
170:                startTag.parse(input);
171:
172:                /*
173:                 * The Offset is the space the reader skipped
174:                 * before it reached the opening '<'
175:                 *   <!-- a comment --> some garbage <DATE>
176:                 * ^----- offset --------------------^
177:                 */
178:                startPos = startPosition + startTag.getOffset();
179:
180:                /*
181:                 * get properties
182:                 */
183:                properties = startTag.getAttributes();
184:
185:                name = startTag.value("NAME", null);
186:                if (name == null)
187:                    return null;
188:
189:                endPos = input.getPosition(); // in case </component> is missing
190:
191:                while (!startTag.finished()) {
192:                    startTag = new SGMLTag(input, true);
193:                    if (startTag.isNamed(endTagName)
194:                            || startTag.isNamed(startTagName))
195:                        break;
196:                }
197:
198:                // Either EOF or newly opened COMPONENT (unexpectedly)
199:                if (startTag.finished() || startTag.isNamed(startTagName)) {
200:                    close_is_missing = true;
201:                } else {
202:                    // The current Position is after the closing '>'
203:                    endPos = input.getPosition();
204:                }
205:
206:                // remove properties, which are not necessary for the PropertyManager
207:                properties.remove("NAME");
208:                properties.remove("TYPE");
209:
210:                return startTag;
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.