Source Code Cross Referenced for ConnectionRenderer.java in  » Database-ORM » MMBase » org » mmbase » framework » 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 » Database ORM » MMBase » org.mmbase.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.framework;
011:
012:        import java.util.*;
013:        import java.net.*;
014:        import java.io.*;
015:        import javax.servlet.http.*;
016:        import javax.xml.transform.stream.StreamResult;
017:        import javax.xml.transform.stream.StreamSource;
018:        import javax.xml.transform.Source;
019:        import javax.xml.transform.Result;
020:        import org.mmbase.util.functions.*;
021:        import org.mmbase.util.*;
022:
023:        import org.mmbase.util.logging.Logger;
024:        import org.mmbase.util.logging.Logging;
025:
026:        /**
027:         * A Renderer implementation based on an external connection.
028:         *
029:         * @author Michiel Meeuwissen
030:         * @version $Id: ConnectionRenderer.java,v 1.4 2008/02/23 12:44:03 michiel Exp $
031:         * @since MMBase-1.9
032:         */
033:        public class ConnectionRenderer extends AbstractRenderer {
034:            private static final Logger log = Logging
035:                    .getLoggerInstance(ConnectionRenderer.class);
036:
037:            protected URL url;
038:            protected int timeOut = 2000;
039:            protected String xsl = null;
040:            protected boolean decorate = true;
041:
042:            public ConnectionRenderer(String t, Block parent) {
043:                super (t, parent);
044:            }
045:
046:            public void setUrl(String u) throws MalformedURLException {
047:                url = new URL(u);
048:            }
049:
050:            public void setXslt(String x) throws MalformedURLException {
051:                xsl = x;
052:            }
053:
054:            public void setTimeOut(int t) {
055:                timeOut = t;
056:            }
057:
058:            public void setDecorate(boolean d) {
059:                decorate = d;
060:            }
061:
062:            public Parameter[] getParameters() {
063:                return new Parameter[] {};
064:            }
065:
066:            public void render(Parameters blockParameters,
067:                    Parameters frameworkParameters, Writer w, WindowState state)
068:                    throws FrameworkException {
069:
070:                try {
071:                    if (decorate) {
072:                        HttpServletRequest request = blockParameters
073:                                .get(Parameter.REQUEST);
074:                        decorateIntro(request, w, null);
075:                    }
076:                    HttpURLConnection connection = (HttpURLConnection) url
077:                            .openConnection();
078:                    connection.setConnectTimeout(timeOut);
079:                    connection.setReadTimeout(timeOut);
080:                    int responseCode = connection.getResponseCode();
081:                    String contentType = connection.getContentType();
082:                    InputStream inputStream = connection.getInputStream();
083:                    if (responseCode == 200) {
084:                        if (xsl == null) {
085:                            String encoding = GenericResponseWrapper
086:                                    .getEncoding(contentType);
087:                            BufferedReader r = new BufferedReader(
088:                                    new InputStreamReader(inputStream, encoding));
089:                            char[] buf = new char[1000];
090:                            int c;
091:                            while ((c = r.read(buf, 0, 1000)) > 0) {
092:                                w.write(buf, 0, c);
093:                            }
094:                        } else {
095:                            /// convert using the xsl and spit out that.
096:                            Source xml = new StreamSource(inputStream);
097:                            URL x = ResourceLoader.getConfigurationRoot()
098:                                    .getResource(xsl);
099:
100:                            Result res = new StreamResult(w);
101:                            XSLTransformer.transform(xml, x, res,
102:                                    new HashMap<String, Object>());
103:                        }
104:
105:                    } else {
106:                        throw new FrameworkException("" + responseCode);
107:                    }
108:                } catch (java.net.ConnectException ce) {
109:                    throw new FrameworkException(ce.getMessage(), ce);
110:                } catch (java.net.SocketTimeoutException ste) {
111:                    throw new FrameworkException(ste.getMessage(), ste);
112:                } catch (IOException ioe) {
113:                    throw new FrameworkException(ioe.getMessage(), ioe);
114:                } catch (javax.xml.transform.TransformerException te) {
115:                    throw new FrameworkException(te.getMessage(), te);
116:                } finally {
117:                    if (decorate) {
118:                        try {
119:                            HttpServletRequest request = blockParameters
120:                                    .get(Parameter.REQUEST);
121:                            decorateOutro(request, w);
122:                        } catch (Exception e) {
123:                        }
124:                    }
125:                }
126:
127:            }
128:
129:            public String toString() {
130:                return url.toString();
131:            }
132:
133:            public java.net.URI getUri() {
134:                try {
135:                    return url.toURI();
136:                } catch (URISyntaxException use) {
137:                    log.warn(use);
138:                    return null;
139:                }
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.