LookAheadInfo.java :  » Portal » Open-Portal » com » sun » portal » rewriter » Java Open Source

Java Open Source » Portal » Open Portal 
Open Portal » com » sun » portal » rewriter » LookAheadInfo.java
/*
 * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
 * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
 */
package com.sun.portal.rewriter;

import com.sun.portal.rewriter.engines.markup.TagContext;
import com.sun.portal.rewriter.util.Constants;
import com.sun.portal.rewriter.util.collections.ListSet;
import com.sun.portal.rewriter.util.uri.PageSpec;

/**
 * Contains the state info, related to current tag context, so that
 * any translator could info, if needed
 */
public final class LookAheadInfo
{
    private ListSet neededJSFunctions;

    private int jsStartIndex = -1;
    private TagContext tagContext;
    private boolean inApplet = false;
    private PageSpec appletCodeBaseSpec = null;
    private boolean rootRewriterFlag = false;
    private boolean contentChanged = false;

    public TagContext getTagContext()
    {
  return tagContext == null ? TagContext.EMPTY_TAG_CONTEXT : tagContext;
    }//getTagContext()

    public void setTagContext( final TagContext aTagContext )
    {
  tagContext = aTagContext;
    }//setTagContext()

    public void setAppletCodeBase( String aURI )
    {
  if ( aURI == null )
  {
      appletCodeBaseSpec = null;
  }
  else
  {
      //Applet codebase is always a directory as per HTTP spec
      //Both code and archive would use the codebase value and not
      //either page url or base tag url.
      //Applet params should be rewritten based in Page URI
      if ( !( aURI.endsWith( "/" ) || aURI.endsWith( "\\" ) ) )
      {
    aURI = aURI + "/";
      }

      appletCodeBaseSpec = new PageSpec( aURI );
  }
    }//setAppletCodeBase()

    public PageSpec getAppletCodeBase()
    {
  return appletCodeBaseSpec;
    }//getAppletCodeBase()

    public boolean isAppletCodeBaseExists()
    {
  return ( ( appletCodeBaseSpec != null ) && isInApplet() );
    }//isArchiveTranslate()

    /**
     * We need to translate the archives based on codebase and not by HTML Page
     * base. Problem comes only when codebase of applet and baseref of HTML are different
     */
    public void setInAppletAttributeBegin()
    {
  inApplet = true;
    }//setArchiveTranslateBegin()

    public void setInAppletAttributeEnd()
    {
  inApplet = false;
    }//setArchiveTranslateEnd()

    private boolean isInApplet()
    {
  return inApplet;
    }//isArchive()

    public void addJSFunction( final String aFuncName )
    {
  contentChanged = true;
  if ( neededJSFunctions == null )
  {
      neededJSFunctions = new ListSet();
  }

  neededJSFunctions.add( aFuncName );
    }//addJSFunction();

    public boolean isRootRewriter()
    {
  //BugNo:4683016, 4747776
  if ( rootRewriterFlag )
  {
      return false;
  }

  rootRewriterFlag = true;
  return rootRewriterFlag;
    }//isRootRewriter()

    public int getJSStartIndex()
    {
  return jsStartIndex;
    }//getJSStartIndex()

    public void markJSStartIndex( final StringBuffer sb )
    {
  if ( jsStartIndex == -1 )
  {
      jsStartIndex = sb.toString().lastIndexOf( '<' );
  }
    }//markJSStartIndex()

    public String readJSFunctions( final Translator aTranslator )
    {
  if ( neededJSFunctions == null )
  {
      return "";
  }

  StringBuffer sbf;
  switch ( neededJSFunctions.size() )
  {
      case 0:
    {
        return Constants.EMPTY_STRING;
    }
      case 1:
    {
        String bFunctionName = neededJSFunctions.get( 0 ).toString();
        String bFunctionDefination;
        JSFunctionSpec bJSFunctionSpec = aTranslator.getJSFunctionSpec();
        if ( bFunctionName.equals( bJSFunctionSpec.getExpressionFunctionName() ) )
        {
      bFunctionDefination = aTranslator.getJSFunctionSpec()
        .getExpressionFunctionDefination( aTranslator.getPageSpec() );
        }
        else if ( bFunctionName.equals( bJSFunctionSpec.getSystemFunctionName() ) )
        {
      bFunctionDefination =
        aTranslator.getJSFunctionSpec()
        .getSystemFunctionDefination( aTranslator.getPageSpec() );
        }
        else
        {
      return Constants.EMPTY_STRING;
        }

        sbf = new StringBuffer( bFunctionDefination );
        break;
    }
      default:
    {
        sbf = new StringBuffer( aTranslator.getJSFunctionSpec()
              .readAll( aTranslator.getPageSpec() ) );
        break;
    }
  }//switch/case

  sbf.insert( 0, '\n' ).append( '\n' );
  return sbf.toString();
    }//readJSFunctions()

    public boolean isContentChanged()
    {
  return contentChanged;

    }//isContentChanged()

    public void enableContentChanged()
    {
  contentChanged = true;
    }//enableContentChanged()

}//class LookAheadInfo()
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.