Source Code Cross Referenced for MarkupRewriterHelper.java in  » Portal » Open-Portal » com » sun » portal » rewriter » engines » markup » 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.engines.markup 
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.engines.markup;
006:
007:        import com.sun.portal.rewriter.Translator;
008:        import com.sun.portal.rewriter.TranslatorHelper;
009:        import com.sun.portal.rewriter.engines.LanguageConstants;
010:        import com.sun.portal.rewriter.util.ConfigManager;
011:        import com.sun.portal.rewriter.util.Constants;
012:        import com.sun.portal.rewriter.util.xml.Tag;
013:        import com.sun.portal.rewriter.util.xml.TagParser;
014:
015:        import java.util.List;
016:
017:        final class MarkupRewriterHelper {
018:            private static final boolean commentBaseHREF = ConfigManager
019:                    .getBoolean(MarkupRewriter.PROPERTY_IS_COMMENT_BASE_HREF);
020:            private static final boolean commentBodyBackGround = ConfigManager
021:                    .getBoolean(MarkupRewriter.PROPERTY_IS_COMMENT_BODY_BACKGROUND);
022:
023:            static boolean isEmptyTag(final String aContent, int aEndIndex) {
024:                if (aContent.charAt(aEndIndex - 1) == '/') {
025:                    //BugNo: 4758709
026:                    char backByTwo = aContent.charAt(aEndIndex - 2);
027:                    //TODO:REGEXP
028:                    if (Character.isWhitespace(backByTwo) || backByTwo == '\"'
029:                            || backByTwo == '\'' || backByTwo == '\\') {
030:                        return true;
031:                    }
032:                }
033:                return false;
034:            }//isEmptyTag()
035:
036:            static void commentAttributes(final String aTagName,
037:                    final StringBuffer aTagResultBuffer,
038:                    final String aEndedWith, final Translator aTranslator) {
039:                //BugNo: 4413145, 4767077, 4529513, 4696780, 4687285, 4692006
040:                //comment the Base tag's href attribute only
041:                if (commentBaseHREF
042:                        && aTagName.equalsIgnoreCase(LanguageConstants.BASE)) {
043:                    aTranslator.getLookAheadInfo().enableContentChanged();
044:                    commentBaseHREF(aTagResultBuffer, aEndedWith);
045:                } else if (commentBodyBackGround
046:                        && aTagName.equalsIgnoreCase(LanguageConstants.BODY)) {
047:                    //BugNo:4870334
048:                    aTranslator.getLookAheadInfo().enableContentChanged();
049:                    commentAttribute(aTagResultBuffer,
050:                            LanguageConstants.BACKGROUND, aEndedWith);
051:                }
052:            }//commentAttributes()
053:
054:            static void commentBaseHREF(final StringBuffer aTagBuff,
055:                    final String aEndedWith) {
056:                //if href and target are present comment only href and not
057:                //target
058:                Tag lBaseTag = TagParser.parse(aTagBuff.toString());
059:                String lHREF = lBaseTag.get(LanguageConstants.HREF);
060:
061:                if (lHREF != null && lHREF.trim().length() != 0)//BugNo:4740650,4819702
062:                {
063:                    if (lBaseTag.get(LanguageConstants.TARGET) == null)//only href present
064:                    {
065:                        aTagBuff.insert(0, "!-- ");
066:                        aTagBuff.append(" --");
067:                    } else //both href and target are present
068:                    {
069:                        aTagBuff.setLength(0);
070:
071:                        //comment only href and not target
072:                        aTagBuff.append(lBaseTag.getName());
073:                        aTagBuff.append(Constants.SINGLE_SPACE);
074:                        aTagBuff.append(LanguageConstants.TARGET);
075:                        aTagBuff.append(Constants.EQUALS);
076:                        aTagBuff.append(lBaseTag.get(LanguageConstants.TARGET));
077:                        aTagBuff.append(Constants.SINGLE_SPACE);//BugNo:4853610
078:                        aTagBuff.append(aEndedWith);
079:                        aTagBuff.append(" <!-- ");
080:                        aTagBuff.append(LanguageConstants.HREF);
081:                        aTagBuff.append(Constants.EQUALS);
082:                        aTagBuff.append(lHREF);
083:                        aTagBuff.append(" --");
084:                    }
085:                }
086:            }//commentBaseHREF()
087:
088:            private static void commentAttribute(final StringBuffer aTagBuff,
089:                    final String aAttributeName, final String aEndedWith) {
090:                Tag lTag = TagParser.parse(aTagBuff.toString());
091:                String lBackGround = lTag.get(aAttributeName);
092:
093:                if (lBackGround != null && lBackGround.trim().length() != 0)//BugNo:4740650, 4819702
094:                {
095:                    aTagBuff.setLength(0);
096:                    aTagBuff.append(lTag.getName());
097:                    aTagBuff.append(Constants.SINGLE_SPACE);
098:
099:                    List lAttributeList = lTag.getAttributeMap().keyList();
100:                    for (int i = 0; i < lAttributeList.size(); i++) {
101:                        String bAttName = lAttributeList.get(i).toString();
102:                        if (bAttName.equalsIgnoreCase(aAttributeName)) {
103:                            continue;
104:                        }
105:
106:                        aTagBuff.append(bAttName);
107:                        aTagBuff.append(Constants.EQUALS);
108:                        aTagBuff.append(lTag.get(bAttName));
109:                        aTagBuff.append(Constants.SINGLE_SPACE);
110:                    }
111:
112:                    //make sure there is atleast a single space before endedWith tag
113:                    //BugNo:4853610
114:                    aTagBuff.append(aEndedWith);
115:                    aTagBuff.append(" <!-- ");
116:                    aTagBuff.append(aAttributeName);
117:                    aTagBuff.append(Constants.EQUALS);
118:                    aTagBuff.append(lBackGround);
119:                    aTagBuff.append(" --");
120:                }
121:            }//commentAttribute()
122:
123:            static void rewriteMetaTag(final StringBuffer aTagBuff,
124:                    final String aAttributeValue, final Translator aTranslator) {
125:                int index = aAttributeValue.indexOf(";");
126:                if (index == -1) {
127:                    aTagBuff.append(aAttributeValue);
128:                } else {
129:                    //Bug No: 4689375
130:                    index = aAttributeValue.toLowerCase()
131:                            .indexOf("url=", index);
132:                    if (index == -1) {
133:                        aTagBuff.append(aAttributeValue);
134:                    } else {
135:                        aTagBuff
136:                                .append(aAttributeValue.substring(0, index + 4));
137:                        aTagBuff.append(aTranslator.translate(aAttributeValue
138:                                .substring(index + 4)));
139:                    }
140:                }//if/else
141:            }//rewriteMetaTag()
142:
143:            static String setBaseSpec(final Translator aTranslator,
144:                    final String aAttributeValue) {
145:                final String lAbsoluteBASE = TranslatorHelper.convert2Absolute(
146:                        aTranslator.getPageSpec(), aAttributeValue);
147:                aTranslator.getPageSpec().setBase(lAbsoluteBASE);
148:                return lAbsoluteBASE;
149:            }//setBaseSpec()
150:
151:            static void setLookAheadCodeBaseInfo(final Translator aTranslator,
152:                    final Tag aTag) {
153:                String lCodeBaseValue = aTag.get(LanguageConstants.CODEBASE);
154:
155:                //set the codebase value only if this not a javascript call
156:                //will a bug if one is asked to rewrite archive and code in this senario
157:                //BugNo:4747776
158:                if (lCodeBaseValue != null) {
159:                    if (!lCodeBaseValue.trim().regionMatches(true, 0,
160:                            LanguageConstants.JS_SCRIPT_PROTOCOL, 0, 11)) {
161:                        lCodeBaseValue = TranslatorHelper.convert2Absolute(
162:                                aTranslator.getPageSpec(), lCodeBaseValue);
163:                    }
164:                    aTranslator.getLookAheadInfo().setAppletCodeBase(
165:                            lCodeBaseValue);
166:                }
167:            }//setLookAheadCodeBaseInfo()
168:
169:            static void checkAndSetAppletBegin(final TagContext aTagContext,
170:                    final Translator aTranslator) {
171:                if (aTagContext.attributeName
172:                        .equals(LanguageConstants.CODEBASE)) {
173:                    aTagContext.enableCodeBase();
174:                }
175:
176:                if (aTagContext.attributeName.equals(LanguageConstants.CODE)
177:                        || aTagContext.attributeName
178:                                .equals(LanguageConstants.ARCHIVE)
179:                        || aTagContext.attributeName
180:                                .equals(LanguageConstants.CLASSID)) {
181:                    aTranslator.getLookAheadInfo().setInAppletAttributeBegin();
182:                }
183:            }//checkAndSetAppletBegin()
184:
185:            static String getBlockTag(final String aContent,
186:                    final StringBuffer aBlockBuff) {
187:                final int index = aContent.lastIndexOf('<');
188:                final String tmptag;
189:                if (index != -1) {
190:                    tmptag = aContent.substring(index + 1);
191:                    aBlockBuff.append(aContent.substring(0, index + 1));
192:                } else {
193:                    tmptag = aContent;
194:                }
195:
196:                return tmptag;
197:            }//getBlockTag()
198:
199:            static int skip2EndOfTag(final String aLowerCaseContent,
200:                    final int aLookFromIndex, final String aTagName) {
201:                final int length = aTagName.length();
202:                final int k = aLowerCaseContent.indexOf(aTagName,
203:                        aLookFromIndex);
204:                if (k == -1) {
205:                    return -1;
206:                }
207:
208:                int l = aLowerCaseContent.indexOf('>', k + length);
209:
210:                if (l == -1) {
211:                    return -1;
212:                }
213:
214:                String gap = aLowerCaseContent.substring(k + length, l);
215:                if (gap.trim().length() == 0) {
216:                    return l + 1;
217:                } else {
218:                    return -1;
219:                }
220:            }//skip2EndOfTag()
221:
222:            static boolean isValidNextTagChar(final String aPrevContent,
223:                    final String aTag) {
224:                final int lPrevContentLength = aPrevContent.length();
225:                final int lTagLength = aTag.length();
226:
227:                char charNext2Tag = '>';
228:
229:                if (lPrevContentLength > lTagLength) {
230:                    charNext2Tag = aPrevContent.charAt(lTagLength);
231:                }
232:
233:                //Bug No: 4742022
234:                if (charNext2Tag == '>' || Character.isWhitespace(charNext2Tag)) {
235:                    return true;
236:                }
237:
238:                return false;
239:            }//isValidNextTagChar()
240:
241:            static final StringBuffer createBuffer() {
242:                return new StringBuffer(200);
243:            }//createBuffer()
244:
245:        }//class RewriterHelper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.