Source Code Cross Referenced for TemplateResponder.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » servlets » responders » 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 » Ajax » Laszlo 4.0.10 » org.openlaszlo.servlets.responders 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * TemplateResponder.java
003:         * ****************************************************************************/package org.openlaszlo.servlets.responders;
004:
005:        import java.io.*;
006:        import java.util.*;
007:        import java.net.URLEncoder;
008:        import java.util.Enumeration;
009:        import java.util.Properties;
010:        import javax.servlet.ServletConfig;
011:        import javax.servlet.ServletException;
012:        import javax.servlet.ServletOutputStream;
013:        import javax.servlet.http.HttpSession;
014:        import javax.servlet.http.HttpServletRequest;
015:        import javax.servlet.http.HttpServletResponse;
016:        import org.openlaszlo.compiler.Canvas;
017:        import org.openlaszlo.compiler.CompilationError;
018:        import org.openlaszlo.utils.*;
019:        import org.apache.log4j.Logger;
020:
021:        public final class TemplateResponder extends ResponderCompile {
022:            private static Logger mLogger = Logger
023:                    .getLogger(TemplateResponder.class);
024:
025:            /** {lzt -> Responder} */
026:            private static Map mResponderMap = new HashMap();
027:
028:            public static Responder getResponder(String lzt) {
029:                String pathname = org.openlaszlo.server.LPS
030:                        .getTemplateDirectory()
031:                        + File.separator
032:                        + lzt
033:                        + org.openlaszlo.i18n.LaszloMessages.getMessage(
034:                                TemplateResponder.class.getName(),
035:                                "xsltfilename");
036:
037:                /* for i18n get filename from properties file.
038:                 original :   String pathname =  org.openlaszlo.server.LPS.getTemplateDirectory() +
039:                 File.separator + lzt + "-response.xslt";
040:                 */
041:
042:                synchronized (mResponderMap) {
043:                    Responder responder = (Responder) mResponderMap
044:                            .get(pathname);
045:                    if (responder == null) {
046:                        if (new File(pathname).exists())
047:                            responder = new TemplateResponder(pathname);
048:                        mLogger.debug("getResponder(" + lzt + ") -> "
049:                                + responder);
050:                        mResponderMap.put(pathname, responder);
051:                    }
052:                    return responder;
053:                }
054:            }
055:
056:            protected final String mTemplatePathname;
057:
058:            protected TemplateResponder(String templatePathname) {
059:                this .mTemplatePathname = templatePathname;
060:            }
061:
062:            /**
063:             * @param fileName Full pathname to file from request.
064:             */
065:            protected void respondImpl(String fileName, HttpServletRequest req,
066:                    HttpServletResponse res) throws IOException {
067:                mLogger.info(
068:                /* (non-Javadoc)
069:                 * @i18n.test
070:                 * @org-mes="Responding with HTML wrapper for " + p[0]
071:                 */
072:                org.openlaszlo.i18n.LaszloMessages.getMessage(
073:                        TemplateResponder.class.getName(), "051018-69",
074:                        new Object[] { fileName }));
075:                if ("svg".equals(req.getParameter("lzr"))
076:                        && "svg".equals(req.getParameter("lzt"))) {
077:                    res.setContentType("image/svg+xml");
078:                } else {
079:                    res.setContentType("text/html");
080:                }
081:                ServletOutputStream out = res.getOutputStream();
082:                try {
083:                    // Get the canvas first, so that if this fails and we
084:                    // write the compilation error, nothing has been written
085:                    // to out yet.
086:                    if (fileName.endsWith(".lzo")) {
087:                        fileName = fileName.substring(0, fileName.length() - 1)
088:                                + "x";
089:                    }
090:                    Canvas canvas = getCanvas(fileName, req);
091:                    writeCanvas(out, req, canvas, fileName);
092:                } catch (CompilationError e) {
093:                    ResponderAPP_CONSOLE.respondCompilationError(e, req, res);
094:                } finally {
095:                    FileUtils.close(out);
096:                }
097:            }
098:
099:            /**
100:             * Writes the canvas html.  The canvas is the area in which the
101:             * Laszlo application is rendered.
102:             * @param out <tt>ServletOutputStream</tt> to write on
103:             * @param req request to retrieve scheme, server name, server port and
104:             * requested url
105:             * @param canvas the canvas for the given request
106:             * @param fileName file for the app
107:             */
108:            private void writeCanvas(ServletOutputStream out,
109:                    HttpServletRequest req, Canvas canvas, String fileName)
110:                    throws IOException {
111:                String xmlString = canvas.getXML(ResponderAPP_CONSOLE
112:                        .getRequestXML(req, fileName));
113:                Properties properties = new Properties();
114:                TransformUtils.applyTransform(mTemplatePathname, properties,
115:                        xmlString, out);
116:            }
117:
118:            /** 
119:             * Return all query args except for "lzt"
120:             */
121:            private String getQueryArgs(HttpServletRequest req) {
122:                StringBuffer query = new StringBuffer();
123:                Enumeration e = req.getParameterNames();
124:                while (e.hasMoreElements()) {
125:                    String name = (String) e.nextElement();
126:                    String val = req.getParameter(name);
127:                    if (!name.equals("lzt")) {
128:                        query.append("&" + name + "=" + URLEncoder.encode(val));
129:                    }
130:                }
131:                return query.toString();
132:            }
133:
134:            public int getMimeType() {
135:                return MIME_TYPE_HTML;
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.