Source Code Cross Referenced for CapabilityValveImpl.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » capabilities » impl » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.capabilities.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.jetspeed.capabilities.impl;
019:
020:        import org.apache.commons.logging.Log;
021:        import org.apache.commons.logging.LogFactory;
022:        import org.apache.jetspeed.capabilities.Capabilities;
023:        import org.apache.jetspeed.capabilities.CapabilityMap;
024:        import org.apache.jetspeed.capabilities.MediaType;
025:        import org.apache.jetspeed.capabilities.MimeType;
026:        import org.apache.jetspeed.capabilities.UnableToBuildCapabilityMapException;
027:        import org.apache.jetspeed.pipeline.PipelineException;
028:        import org.apache.jetspeed.pipeline.valve.CapabilityValve;
029:        import org.apache.jetspeed.pipeline.valve.ValveContext;
030:        import org.apache.jetspeed.request.RequestContext;
031:
032:        /**
033:         * Invokes the capability mapper in the request pipeline
034:         * 
035:         * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann </a>
036:         * @version $Id: CapabilityValveImpl.java 517719 2007-03-13 15:05:48Z ate $
037:         */
038:        public class CapabilityValveImpl implements  CapabilityValve {
039:            private static final Log log = LogFactory
040:                    .getLog(CapabilityValveImpl.class);
041:            String resourceDefault; // the default name for a resource
042:            private Capabilities capabilities;
043:
044:            public CapabilityValveImpl(Capabilities capabilities) {
045:                this .capabilities = capabilities;
046:            }
047:
048:            /**
049:             * Initialize the valve before using in a pipeline.
050:             */
051:            public void initialize() throws PipelineException {
052:
053:            }
054:
055:            public void invoke(RequestContext request, ValveContext context)
056:                    throws PipelineException {
057:                String agent = request.getRequest().getHeader("User-Agent");
058:
059:                // Get capability map
060:                CapabilityMap cm;
061:                try {
062:                    cm = capabilities.getCapabilityMap(agent);
063:                } catch (UnableToBuildCapabilityMapException e) {
064:                    throw new PipelineException(
065:                            "Falied to create capabilitied:  " + e.getMessage(),
066:                            e);
067:                }
068:
069:                MediaType mediaType = cm.getPreferredMediaType();
070:                MimeType mimeType = cm.getPreferredType();
071:
072:                if (mediaType == null) {
073:                    log.error("CapabilityMap returned a null media type");
074:                    throw new PipelineException(
075:                            "CapabilityMap returned a null media type");
076:                }
077:
078:                if (mimeType == null) {
079:                    log.error("CapabilityMap returned a null mime type");
080:                    throw new PipelineException(
081:                            "CapabilityMap returned a null mime type");
082:                }
083:
084:                String encoding = request.getRequest().getCharacterEncoding();
085:
086:                if (encoding == null) {
087:                    if (mediaType != null
088:                            && mediaType.getCharacterSet() != null) {
089:                        encoding = mediaType.getCharacterSet();
090:                    }
091:                }
092:
093:                if (log.isDebugEnabled()) {
094:                    log.debug("MediaType: " + mediaType.getName());
095:                    log.debug("Encoding: " + encoding);
096:                    log.debug("Mimetype: " + mimeType.getName());
097:                }
098:
099:                // Put the encoding in the request
100:                request.setCharacterEncoding(encoding);
101:
102:                // Put the CapabilityMap into the request
103:                request.setCapabilityMap(cm);
104:
105:                // Put the Media Type into the request
106:                request.setMediaType(mediaType.getName());
107:
108:                // Put the Mime Type into the request
109:                request.setMimeType(mimeType.getName());
110:
111:                // Put the Mime Type and Charset into the response
112:                StringBuffer contentType = new StringBuffer(mimeType.getName());
113:                if (encoding != null) {
114:                    contentType.append("; charset=" + encoding);
115:                }
116:                String type = contentType.toString(); //mapContentType(request, contentType.toString());
117:                request.getResponse().setContentType(type);
118:
119:                // Pass control to the next Valve in the Pipeline
120:                context.invokeNext(request);
121:            }
122:
123:            static String[][] MIME_MAP = { { ".pdf", "application/pdf" } };
124:
125:            protected String mapContentType(RequestContext request,
126:                    String contentType) {
127:                // TODO: get path from servlet request
128:                // this code below fails since the path is not yet parsed
129:                // to far up in the pipeline
130:                String path = request.getPath();
131:                if (path != null) {
132:                    for (int ix = 0; ix < MIME_MAP.length; ix++) {
133:                        if (path.endsWith(MIME_MAP[ix][0])) {
134:                            return MIME_MAP[ix][1];
135:                        }
136:                    }
137:                }
138:                return contentType;
139:            }
140:
141:            public String toString() {
142:                return "CapabilityValveImpl";
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.