Source Code Cross Referenced for AbstractTranslator.java in  » Portal » Open-Portal » com » sun » portal » rewriter » 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 » Open Portal » com.sun.portal.rewriter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.rewriter;
006:
007:        import com.sun.portal.rewriter.util.ConfigManager;
008:        import com.sun.portal.rewriter.util.Constants;
009:        import com.sun.portal.rewriter.util.Debug;
010:        import com.sun.portal.rewriter.util.StringHelper;
011:        import com.sun.portal.rewriter.util.uri.DecoratedURI;
012:        import com.sun.portal.rewriter.util.uri.PageSpec;
013:
014:        /**
015:         * Implements the Translator methods related to AbsoluteJSFunctionSpec
016:         *
017:         * @version 1.0 12/15/2001
018:         * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
019:         */
020:        public abstract class AbstractTranslator implements  Translator {
021:            public static final String PROPERTY_IS_ADD_SCRIPT_REFERRER = "IS_ADD_SCRIPT_REFERRER";
022:            private static final boolean IS_ADD_SCRIPT_REFERRER = ConfigManager
023:                    .getBoolean(PROPERTY_IS_ADD_SCRIPT_REFERRER);
024:            private static final String JAR_PROTOCOL = "jar:";
025:
026:            private final LookAheadInfo lookAheadInfo = new LookAheadInfo();
027:            private final PageSpec pageSpec;
028:            private final JSFunctionSpec jsFunctionSpec;
029:
030:            protected AbstractTranslator(final PageSpec aPageSpec) {
031:                this (aPageSpec, AbsoluteJSFunctionSpec.getDefault());
032:            }//constructor
033:
034:            protected AbstractTranslator(final PageSpec aPageSpec,
035:                    final JSFunctionSpec aJSFunctionSpec) {
036:                pageSpec = aPageSpec;
037:                jsFunctionSpec = aJSFunctionSpec;
038:            }//constructor
039:
040:            public PageSpec getPageSpec() {
041:                return pageSpec;
042:            }//getPageSpec()
043:
044:            public JSFunctionSpec getJSFunctionSpec() {
045:                lookAheadInfo.enableContentChanged();
046:                return jsFunctionSpec;
047:            }//getJSFunctionSpec()
048:
049:            public final LookAheadInfo getLookAheadInfo() {
050:                return lookAheadInfo;
051:            }//getLookAheadInfo()
052:
053:            /**
054:             * Template Method which would call the hookTraslate() method after
055:             * converting the URI to absolute
056:             * @param aOrgURL
057:             * @return
058:             */
059:            public final String translate(final String aOrgURL) {
060:                /**
061:                 * first decide which basespec to be used
062:                 * Base Spec is either applet codebase uri or HTML <base> Tag uri
063:                 */
064:                lookAheadInfo.enableContentChanged();
065:                final PageSpec lPageSpec;
066:                if (lookAheadInfo.isAppletCodeBaseExists()) {
067:                    lPageSpec = lookAheadInfo.getAppletCodeBase();
068:                } else {
069:                    lPageSpec = getPageSpec();
070:                }
071:
072:                return doTranslate(aOrgURL, lPageSpec, this );
073:            }//translate()
074:
075:            static final String doTranslate(final String aOrgURL,
076:                    final PageSpec aResolveSpec, final Translator aTranslator) {
077:                //Do Not translated the Applet URI's if the codebase pagespec
078:                //is invalid - This could happen if codebase="javascript:getCodeBase()"
079:                if (!aResolveSpec.isValid()) {
080:                    if (Debug.isWarningEnabled()) {
081:                        Object param[] = { aOrgURL };
082:                        Debug.recordURIWarning("PSRW_CSPR_0001", param);
083:                    }
084:                    return aOrgURL;
085:                }
086:
087:                final String[] parts = StringHelper.regExpSplit(aOrgURL,
088:                        Constants.REG_EX_FOR_TRIMING_QUOTES);
089:
090:                //after removing these special chars see if the remaing are spaces
091:                //pre-condition, i.e it should not be null or empty string
092:                //or value should not be null - this happends when function params are being rewritten
093:                if (parts.length != 3 || parts[1].length() == 0) {
094:                    if (Debug.isWarningEnabled()) {
095:                        Object param[] = { aOrgURL };
096:                        Debug.recordURIWarning("PSRW_CSPR_0002", param);
097:                    }
098:
099:                    return aOrgURL;
100:                }
101:
102:                String urlPart = parts[1];
103:
104:                //BugNo:4790402, 4790445, 4890520
105:                if (urlPart.equals("#") || urlPart.equals("?")
106:                        || urlPart.startsWith("+")) {
107:                    if (Debug.isWarningEnabled()) {
108:                        Object param[] = { aOrgURL };
109:                        Debug.recordURIWarning("PSRW_CSPR_0003", param);
110:                    }
111:                    return aOrgURL;
112:                }
113:
114:                //Bug No: 4701655
115:                if (urlPart.startsWith("\\")) {
116:                    urlPart = "/" + urlPart.substring(1);
117:                }
118:                //Bug No: 4701655
119:
120:                //BugNo:jar protocol support
121:                if (StringHelper.startsWithIgnoreCase(urlPart, JAR_PROTOCOL)) {
122:                    parts[0] = parts[0]
123:                            + urlPart.substring(0, JAR_PROTOCOL.length());
124:                    urlPart = urlPart.substring(JAR_PROTOCOL.length());
125:                }
126:
127:                try {
128:                    StringBuffer sb = new StringBuffer(Math.round(aOrgURL
129:                            .length() * 1.25f));
130:                    sb.append(parts[0]); //Append the first part
131:                    DecoratedURI lAbsoluteURI = aResolveSpec.getBaseURI()
132:                            .resolve(urlPart);
133:
134:                    if (aTranslator != null) {
135:                        DecoratedURI lWithScriptReffer = lAbsoluteURI;
136:
137:                        //Bug No: 4526286, 4890520
138:                        if (IS_ADD_SCRIPT_REFERRER
139:                                && aTranslator.getLookAheadInfo()
140:                                        .getTagContext().isScriptSRC()) {
141:                            lWithScriptReffer = TranslatorHelper
142:                                    .handleScriptSRC(aResolveSpec, lAbsoluteURI);
143:                        }
144:                        //Bug No: 4526286, 4890520
145:
146:                        String hookTranslatedURI = aTranslator.hook4Translate(
147:                                lAbsoluteURI, lWithScriptReffer);
148:                        sb.append(hookTranslatedURI);
149:                        recordURI(aTranslator.getPageSpec(), aResolveSpec,
150:                                aOrgURL, lAbsoluteURI, hookTranslatedURI);
151:                    } else {
152:                        sb.append(lAbsoluteURI.toExternalForm());
153:                        recordURI(aResolveSpec, aResolveSpec, aOrgURL,
154:                                lAbsoluteURI,
155:                                "Asked for conversion to absolute URI only");
156:                    }
157:
158:                    sb.append(parts[2]); //Append the Lastpart
159:                    return sb.toString();
160:                } catch (Exception e) {
161:                    if (Debug.isWarningEnabled()) {
162:                        if (e.getMessage().startsWith("mailto")) {
163:                            Object param0[] = { aResolveSpec };
164:                            Object param1[] = { aOrgURL };
165:                            /*Debug.recordURIMessage( "mailto: not rewritten:\n\t" +
166:                            	"Page Info:" + aResolveSpec + ",\n\t" +
167:                            	"Original URI:" + aOrgURL + ",\n" );*/
168:                            Debug.recordURIMessage("PSRW_CSPR_0004");
169:                            Debug.recordURIMessage("PSRW_CSPR_0005", param0);
170:                            Debug.recordURIMessage("PSRW_CSPR_0006", param1);
171:                            //System.out.println("**********************\n firstPSRW_CSPR_0006\n**************");
172:                        } else {
173:                            Object param0[] = { aResolveSpec };
174:                            Object param1[] = { aOrgURL };
175:                            /*Debug.recordURIWarning( "Invalid URI:\n\t" +
176:                            	"Page Info:" + aResolveSpec + ",\n\t" +
177:                            	"Original URI:" + aOrgURL + ",\n",e );*/
178:                            Debug.recordURIWarning("PSRW_CSPR_0007");
179:                            Debug.recordURIWarning("PSRW_CSPR_0005", param0);
180:                            Debug.recordURIWarning("PSRW_CSPR_0006", param1);
181:                            //System.out.println("**********************\n firstPSRW_CSPR_0006\n**************");                
182:                        }
183:                    }
184:                    return aOrgURL;
185:                }
186:            }//doTranslate()
187:
188:            private static void recordURI(final PageSpec aPageSpec,
189:                    final PageSpec aResolveSpec, final String aOrgURL,
190:                    final DecoratedURI aAbsoluteURI,
191:                    final String aHookTranslatedURI) {
192:                //System.out.println("**********************\nPSRW_CSPR_0010\n*************"+Debug.isMessageEnabled());        
193:                if (Debug.isMessageEnabled()) {
194:                    //{BaseURI, OrignalURI, DefaultHandling, CustomHandling},
195:                    //Resolve URI Could be different than page URI specially when Applet
196:                    //codebase translations etc..
197:                    /*Debug.recordURIMessage( "\n{\n\t" +
198:                    		    "Page URI: " + aPageSpec.getInputString() + ",\n\t" +
199:                    		    ( ( aPageSpec != aResolveSpec ) ?
200:                    		      "Resolve URI: " + aResolveSpec.getBaseURI().toExternalForm() + ",\n\t" : "" ) +
201:                    		    "Original URI: " + aOrgURL + ",\n\t" +
202:                    		    "Resolved Absolute URI: " + aAbsoluteURI.toExternalForm() + ",\n\t" +
203:                    		    "Result of Custom Translation: " + aHookTranslatedURI +
204:                    		    "\n},\n" );    */
205:                    Object[] param0 = { (aPageSpec != aResolveSpec) ? aResolveSpec
206:                            .getBaseURI().toExternalForm()
207:                            : "" };
208:                    Object[] param1 = { aOrgURL };
209:                    Object[] param2 = { aAbsoluteURI.toExternalForm() };
210:                    Object[] param3 = { aHookTranslatedURI };
211:                    //System.out.println("recordURI()  method  ");
212:                    Debug.recordURIMessage("PSRW_CSPR_0008");
213:                    Debug.recordURIMessage("PSRW_CSPR_0009", param0);
214:                    Debug.recordURIMessage("PSRW_CSPR_0010", param1);
215:                    Debug.recordURIMessage("PSRW_CSPR_0011", param2);
216:                    Debug.recordURIMessage("PSRW_CSPR_0012", param3);
217:
218:                }
219:            }//recordURI()
220:
221:        }//class AbstractTranslator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.