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.markup.TagContext;
008: import com.sun.portal.rewriter.util.Constants;
009: import com.sun.portal.rewriter.util.collections.ListSet;
010: import com.sun.portal.rewriter.util.uri.PageSpec;
011:
012: /**
013: * Contains the state info, related to current tag context, so that
014: * any translator could info, if needed
015: */
016: public final class LookAheadInfo {
017: private ListSet neededJSFunctions;
018:
019: private int jsStartIndex = -1;
020: private TagContext tagContext;
021: private boolean inApplet = false;
022: private PageSpec appletCodeBaseSpec = null;
023: private boolean rootRewriterFlag = false;
024: private boolean contentChanged = false;
025:
026: public TagContext getTagContext() {
027: return tagContext == null ? TagContext.EMPTY_TAG_CONTEXT
028: : tagContext;
029: }//getTagContext()
030:
031: public void setTagContext(final TagContext aTagContext) {
032: tagContext = aTagContext;
033: }//setTagContext()
034:
035: public void setAppletCodeBase(String aURI) {
036: if (aURI == null) {
037: appletCodeBaseSpec = null;
038: } else {
039: //Applet codebase is always a directory as per HTTP spec
040: //Both code and archive would use the codebase value and not
041: //either page url or base tag url.
042: //Applet params should be rewritten based in Page URI
043: if (!(aURI.endsWith("/") || aURI.endsWith("\\"))) {
044: aURI = aURI + "/";
045: }
046:
047: appletCodeBaseSpec = new PageSpec(aURI);
048: }
049: }//setAppletCodeBase()
050:
051: public PageSpec getAppletCodeBase() {
052: return appletCodeBaseSpec;
053: }//getAppletCodeBase()
054:
055: public boolean isAppletCodeBaseExists() {
056: return ((appletCodeBaseSpec != null) && isInApplet());
057: }//isArchiveTranslate()
058:
059: /**
060: * We need to translate the archives based on codebase and not by HTML Page
061: * base. Problem comes only when codebase of applet and baseref of HTML are different
062: */
063: public void setInAppletAttributeBegin() {
064: inApplet = true;
065: }//setArchiveTranslateBegin()
066:
067: public void setInAppletAttributeEnd() {
068: inApplet = false;
069: }//setArchiveTranslateEnd()
070:
071: private boolean isInApplet() {
072: return inApplet;
073: }//isArchive()
074:
075: public void addJSFunction(final String aFuncName) {
076: contentChanged = true;
077: if (neededJSFunctions == null) {
078: neededJSFunctions = new ListSet();
079: }
080:
081: neededJSFunctions.add(aFuncName);
082: }//addJSFunction();
083:
084: public boolean isRootRewriter() {
085: //BugNo:4683016, 4747776
086: if (rootRewriterFlag) {
087: return false;
088: }
089:
090: rootRewriterFlag = true;
091: return rootRewriterFlag;
092: }//isRootRewriter()
093:
094: public int getJSStartIndex() {
095: return jsStartIndex;
096: }//getJSStartIndex()
097:
098: public void markJSStartIndex(final StringBuffer sb) {
099: if (jsStartIndex == -1) {
100: jsStartIndex = sb.toString().lastIndexOf('<');
101: }
102: }//markJSStartIndex()
103:
104: public String readJSFunctions(final Translator aTranslator) {
105: if (neededJSFunctions == null) {
106: return "";
107: }
108:
109: StringBuffer sbf;
110: switch (neededJSFunctions.size()) {
111: case 0: {
112: return Constants.EMPTY_STRING;
113: }
114: case 1: {
115: String bFunctionName = neededJSFunctions.get(0).toString();
116: String bFunctionDefination;
117: JSFunctionSpec bJSFunctionSpec = aTranslator
118: .getJSFunctionSpec();
119: if (bFunctionName.equals(bJSFunctionSpec
120: .getExpressionFunctionName())) {
121: bFunctionDefination = aTranslator.getJSFunctionSpec()
122: .getExpressionFunctionDefination(
123: aTranslator.getPageSpec());
124: } else if (bFunctionName.equals(bJSFunctionSpec
125: .getSystemFunctionName())) {
126: bFunctionDefination = aTranslator.getJSFunctionSpec()
127: .getSystemFunctionDefination(
128: aTranslator.getPageSpec());
129: } else {
130: return Constants.EMPTY_STRING;
131: }
132:
133: sbf = new StringBuffer(bFunctionDefination);
134: break;
135: }
136: default: {
137: sbf = new StringBuffer(aTranslator.getJSFunctionSpec()
138: .readAll(aTranslator.getPageSpec()));
139: break;
140: }
141: }//switch/case
142:
143: sbf.insert(0, '\n').append('\n');
144: return sbf.toString();
145: }//readJSFunctions()
146:
147: public boolean isContentChanged() {
148: return contentChanged;
149:
150: }//isContentChanged()
151:
152: public void enableContentChanged() {
153: contentChanged = true;
154: }//enableContentChanged()
155:
156: }//class LookAheadInfo()
|