Source Code Cross Referenced for ProjectPathModule.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » modules » input » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.modules.input 
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:        package org.apache.cocoon.components.modules.input;
018:
019:        import org.apache.avalon.framework.configuration.Configuration;
020:        import org.apache.avalon.framework.configuration.ConfigurationException;
021:        import org.apache.avalon.framework.thread.ThreadSafe;
022:
023:        import org.apache.cocoon.environment.ObjectModelHelper;
024:
025:        import java.util.Iterator;
026:        import java.util.LinkedList;
027:        import java.util.List;
028:        import java.util.Map;
029:        import java.util.Vector;
030:
031:        /**
032:         * ProjectPathModule provides relative and absolute paths with regards to the root of a project.
033:         * <p>Config:
034:         * <pre>
035:         *    &lt;component-instance logger=&quot;core.modules.input&quot;
036:         *           name=&quot;myproject&quot;
037:         *           class=&quot;org.apache.cocoon.components.modules.input.ProjectPathModule&quot;&gt;
038:         *          &lt;uri-prefix&gt;my/project/&lt;/uri-prefix&gt;
039:         *    &lt;/component-instance&gt;
040:         * </pre>
041:         * </p>
042:         * <p>Usage:
043:         * <pre>
044:         *    &lt;map:transform src=&quot;skins/{forrest:skin}/xslt/fo/document2html.xsl&quot;&gt;
045:         *       &lt;map:parameter name=&quot;base&quot; value=&quot;{myproject:relative}&quot;/&gt;
046:         *    &lt;/map:transform&gt;
047:         *</pre>
048:         * And then prepend this to all image paths:
049:         * <pre>
050:         *  ...
051:         *  &lt;xsl:param name=&quot;base&quot;/&gt;
052:         *  ...
053:         *  &lt;xsl:template match=&quot;img&quot;&gt;
054:         *      &lt;img src=&quot;{concat($base, @src)}&quot; ...
055:         *      ...
056:         *  &lt;/xsl:template&gt;
057:         *  </pre>
058:         * Then if you are in my/project/some/folder/page.html, the image will have a relative path bact to the root of the project.
059:         * <pre>
060:         *   &lt;img src=&quot;../../imagename.png&quot;/&gt;
061:         * </pre>
062:         * Using 'myproject:path' would have given you: /some/folder/page.html<br/>
063:         * Using 'myproject:folder' would have given you: /some/folder/
064:         * </p>
065:         * 
066:         * @version $Id$
067:         *
068:         */
069:        public class ProjectPathModule extends AbstractInputModule implements 
070:                ThreadSafe {
071:
072:            protected static final String PROJECT_PARAM_NAME = "uri-prefix";
073:            protected static final String PROJECT_PARAM_DEFAULT = "/";
074:
075:            protected String projectBase;
076:
077:            final static Vector returnNames;
078:            static {
079:                Vector tmp = new Vector();
080:                tmp.add("relative");
081:                tmp.add("path");
082:                tmp.add("folder");
083:                returnNames = tmp;
084:            }
085:
086:            /**
087:             * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
088:             */
089:            public void configure(Configuration conf)
090:                    throws ConfigurationException {
091:                this .projectBase = conf.getChild(PROJECT_PARAM_NAME).getValue();
092:                if (getLogger().isDebugEnabled()) {
093:                    getLogger().debug(
094:                            "Configuration supplied: " + this .projectBase);
095:                }
096:                if (this .projectBase == null) {
097:                    this .projectBase = PROJECT_PARAM_DEFAULT;
098:                    if (getLogger().isWarnEnabled()) {
099:                        getLogger().warn(
100:                                "No configuration supplied, using default: "
101:                                        + PROJECT_PARAM_DEFAULT);
102:                    }
103:                }
104:                if (this .projectBase.length() == 0) {
105:                    this .projectBase = PROJECT_PARAM_DEFAULT;
106:                    if (getLogger().isWarnEnabled()) {
107:                        getLogger().warn(
108:                                "Empty configuration supplied, using default: "
109:                                        + PROJECT_PARAM_DEFAULT);
110:                    }
111:                }
112:            }
113:
114:            /**
115:             * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
116:             */
117:            public Object getAttribute(String name, Configuration modeConf,
118:                    Map objectModel) throws ConfigurationException {
119:                String uri = ObjectModelHelper.getRequest(objectModel)
120:                        .getServletPath();
121:                StringBuffer result = new StringBuffer(uri.length());
122:                int baseIndex = uri.indexOf(this .projectBase);
123:                if (baseIndex != -1) {
124:                    uri = uri.substring(baseIndex + this .projectBase.length());
125:                } else {
126:                    throw new ConfigurationException(
127:                            "No project-base path found in URI");
128:                }
129:                try {
130:                    // provide a relative path back to the project
131:                    if (name.startsWith("relative")) {
132:                        int nextIndex = 0;
133:                        while ((nextIndex = uri.indexOf('/', nextIndex) + 1) > 0) {
134:                            result.append("../");
135:                        }
136:                    } else if (name.startsWith("path")) {
137:                        // provide the full path from the project
138:                        result.append("/");
139:                        result.append(uri);
140:                    } else if (name.startsWith("folder")) {
141:                        // provide the folder path from the project
142:                        result.append("/");
143:                        result.append(uri
144:                                .substring(0, uri.lastIndexOf("/") + 1));
145:                    } else {
146:                        if (getLogger().isWarnEnabled()) {
147:                            getLogger().warn("Invalid verb: " + name);
148:                        }
149:                    }
150:                    return result;
151:                } catch (final Exception mue) {
152:                    throw new ConfigurationException(
153:                            "Problems resolving project path.", mue);
154:                }
155:            }
156:
157:            /**
158:             * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
159:             */
160:            public Iterator getAttributeNames(Configuration modeConf,
161:                    Map objectModel) throws ConfigurationException {
162:                return ProjectPathModule.returnNames.iterator();
163:            }
164:
165:            /**
166:             * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
167:             */
168:            public Object[] getAttributeValues(String name,
169:                    Configuration modeConf, Map objectModel)
170:                    throws ConfigurationException {
171:                List values = new LinkedList();
172:                values.add(this.getAttribute(name, modeConf, objectModel));
173:
174:                return values.toArray();
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.