Source Code Cross Referenced for TranslatorHelper.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.engines.LanguageConstants;
008:        import com.sun.portal.rewriter.util.Constants;
009:        import com.sun.portal.rewriter.util.StringHelper;
010:        import com.sun.portal.rewriter.util.re.Pattern;
011:        import com.sun.portal.rewriter.util.re.RegExp;
012:        import com.sun.portal.rewriter.util.uri.DecoratedURI;
013:        import com.sun.portal.rewriter.util.uri.PageSpec;
014:
015:        import java.net.MalformedURLException;
016:
017:        /**
018:         * This contain utility methods which can be used by
019:         * any one including derived Rewriters
020:         *
021:         * @version 1.0 12/15/2001
022:         * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
023:         */
024:        public final class TranslatorHelper {
025:            public static final String convert2Absolute(
026:                    final PageSpec aPageSpec, final String aOrgURL) {
027:                return AbstractTranslator.doTranslate(aOrgURL, aPageSpec, null);
028:            }//convertURL2Absolute()
029:
030:            /**
031:             * Translates based on the patterns provided used in - Forms and Applets, TagText, Attributes
032:             */
033:            public static final String translateSubStrings(
034:                    final Pattern[] aRuleList, final String aSourceString,
035:                    final Translator aTranslator) {
036:                Pattern rule;
037:                int index;
038:
039:                String result = aSourceString;
040:                boolean translateZeroPosition = false;
041:
042:                final int vpSize = aRuleList.length;
043:                for (int j = vpSize - 1; j >= 0; j--) {
044:                    rule = aRuleList[j];
045:                    if (rule.getInput().equals(
046:                            Constants.ZERO_POSTITION_CHILD_PATTERN_INDICATOR)) {
047:                        translateZeroPosition = true;
048:                        continue;
049:                    }
050:
051:                    if (rule.getInput().length() == 0) {
052:                        // translate full string thinking as if this a simple URL
053:                        result = translateString(result, aTranslator);
054:                    } else {
055:                        //find SUB part of it, which is a Simple URL and translate
056:                        //only that portion of the String
057:
058:                        index = RegExp.indexOf(rule, result);
059:                        if (index == -1 || index >= result.length()) {
060:                            continue;
061:                        }
062:                        result = result.substring(0, index)
063:                                + translateString(rule.isRecursive() ? //BUG#4965568
064:                                translateSubStrings(aRuleList, result
065:                                        .substring(index), aTranslator)
066:                                        : result.substring(index), aTranslator);
067:                    }
068:                }
069:
070:                if (translateZeroPosition && !aSourceString.equals(result)) {
071:                    result = translateString(result, aTranslator);
072:                }
073:
074:                return result;
075:            }//translateSubStrings()
076:
077:            public static final String translateString(final String aString,
078:                    final Translator aTranslator) {
079:                final int i = findLastValidURICharIndex(aString);
080:
081:                if (i == 0) {
082:                    return aString;
083:                }
084:
085:                StringBuffer sb = new StringBuffer(aString.length());
086:                sb.append(aTranslator.translate(aString.substring(0, i)));
087:                sb.append(aString.substring(i));
088:                return sb.toString();
089:            }//translateString()
090:
091:            private static final int findLastValidURICharIndex(
092:                    final String aString) {
093:                int i;
094:                char c;
095:
096:                final String lScheme = StringHelper.normalize(aString);
097:                final int strLen = lScheme.length();
098:                for (i = 0; i < strLen; i++) {
099:                    c = lScheme.charAt(i);
100:                    //File Name can contain both letters and degits
101:                    if (!(Character.isLetterOrDigit(c)
102:                            || //i18n way
103:                            c == '.' || c == '/' || c == ' ' || c == ':'
104:                            || c == '\'' || c == '"')) {
105:                        return i;
106:                    }
107:                }//for loop
108:                return i;
109:            }//findLastValidURICharIndex()
110:
111:            public static final DecoratedURI handleScriptSRC(
112:                    final PageSpec aPageSpec, final DecoratedURI aURI)
113:                    throws MalformedURLException {
114:                DecoratedURI lResult = aURI;
115:
116:                String bScriptSRCBase = aURI.getBaseHREF();
117:                String bScriptReferrerBase = aPageSpec.getBaseURI()
118:                        .getBaseHREF();
119:                if (!bScriptSRCBase.equalsIgnoreCase(bScriptReferrerBase)) {
120:                    String bURIString = lResult.toExternalForm();
121:                    if (aURI.hasQuery()) {
122:                        //check if the URI already has script referer appended. This
123:                        //could happen in URLScrapper pages
124:                        if (aURI.getQuery().indexOf(
125:                                LanguageConstants.SCRIPT_REFERRER) != -1) {
126:                            return lResult;
127:                        }
128:
129:                        //already get param present and assumption is the key with scritrefferer is never present
130:                        if (!bURIString.endsWith(Constants.AND)) {
131:                            bURIString += Constants.AND;
132:                        }
133:                    } else {
134:                        bURIString += Constants.QUESTION_MARK;
135:                    }
136:
137:                    bURIString += LanguageConstants.SCRIPT_REFERRER
138:                            + Constants.EQUALS + bScriptReferrerBase + ".END.";
139:                    lResult = new DecoratedURI(bURIString);
140:                }
141:
142:                return lResult;
143:            }//handleScriptSRC()
144:
145:            public static void main(String[] args) throws Exception {
146:                PageSpec samplePageSpec = new PageSpec(
147:                        "http://rajanagendra.sun.com/Base/Raja/raja.html?name=raja",
148:                        "");
149:                AbsoluteTranslator defaultTranslator = new AbsoluteTranslator(
150:                        samplePageSpec);
151:                String result = defaultTranslator.translate("..");
152:                System.out.println(result);
153:            }//main()
154:
155:        }//class TranslatorHelper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.