Author: rich
Date: Mon Sep 27 14:36:12 2004
New Revision: 47334
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/WebappPathType.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/StrutsApp.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/FileUtils.java
Log:
Added an APT option that allows compilation of page flows that are in source
trees separate from the webapp root. To use this, add the following option to
the APT call used to compile the page flows:
-AalternateWebRootDir=<your webapp root directory>
Also, re-added some utility methods in PageFlowUtils.
DRT: netui (WinXP)
BB: self (linux)
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/FlowControllerChecker.java
Mon Sep 27 14:36:12 2004
@@ -20,7 +20,6 @@
import org.apache.beehive.netui.compiler.grammar.ActionGrammar;
import org.apache.beehive.netui.compiler.grammar.ExceptionHandlerGrammar;
import org.apache.beehive.netui.compiler.genmodel.GenStrutsApp;
-import org.apache.beehive.netui.compiler.model.StrutsApp;
import org.apache.beehive.netui.compiler.model.NoWebInfDirectoryException;
import org.apache.xmlbeans.XmlException;
import com.sun.mirror.declaration.*;
@@ -130,14 +129,7 @@
// Run additional .jpf- or .app-specific checks.
//
File sourceFile = CompilerUtils.getOriginalFile( jclass );
- try
- {
- doAdditionalClassChecks( jclass, StrutsApp.getWebappRootFromJpf(
sourceFile ) );
- }
- catch ( NoWebInfDirectoryException e )
- {
- getDiagnostics().addError( jclass, "error.web-inf-not-found",
sourceFile.getPath() );
- }
+ doAdditionalClassChecks( jclass, getWebappRoot() );
endCheckClass( jclass );
_fcInfo.endBuild();
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
Mon Sep 27 14:36:12 2004
@@ -214,4 +214,9 @@
}
public static final String ERROR_TYPE_STR = "<error>";
+
+ /**
+ * When this APT option is set, the logic that warns about missing files
looks here for web files, like .jsps.
+ */
+ public static final String ALTERNATE_WEB_ROOT_DIR_OPTION =
"-AalternateWebRootDir";
}
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/WebappPathType.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/WebappPathType.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/grammar/WebappPathType.java
Mon Sep 27 14:36:12 2004
@@ -118,20 +118,12 @@
}
else
{
- try
- {
- // @TODO cache the stringValue of getWebappRootFromJpf.
It's expensive to calculate.
- File webappRoot = StrutsApp.getWebappRootFromJpf( jpfFile
);
- fileToCheck = new File( webappRoot + filePath );
-
- if ( ! fileToCheck.exists() && ! ( ignoreDirectories() &&
fileToCheck.isDirectory() ) )
- {
- fileExists = false;
- }
- }
- catch ( NoWebInfDirectoryException e )
+ File webappRoot = getWebFilesRoot( jpfFile, true );
+ fileToCheck = new File( webappRoot + filePath );
+
+ if ( ! fileToCheck.exists() && ! ( ignoreDirectories() &&
fileToCheck.isDirectory() ) )
{
- // ignore
+ fileExists = false;
}
}
}
@@ -158,26 +150,29 @@
}
else
{
- String jpfFilePath = jpfFile.getPath();
- File parentFile = jpfFile.getParentFile();
+ File webappRoot = getWebFilesRoot( jpfFile, false );
+ File webFilesRoot = getWebFilesRoot( jpfFile, true );
+ File jpfParent = jpfFile.getAbsoluteFile().getParentFile();
+ assert jpfParent.getPath().startsWith( webappRoot.getPath() )
: jpfParent.getPath();
+ String jpfParentRelativePath = jpfParent.getPath().substring(
webappRoot.getPath().length() );
//
// Check if this page flow is in WEB-INF/src. If so, the
"local" dir is actually out
// in the web-addressable part of the webapp, unless we're
looking for a .jpf (in the
// case that there's a forward to the current page flow from
within the page flow).
//
- if ( ! mustBeInPageFlowDir() && ! filePath.endsWith(
JPF_FILE_EXTENSION ) )
+ if ( ! mustBeInPageFlowDir() )
{
- int webinfSrcPos = jpfFilePath.replace( '\\', '/'
).indexOf( WEBINF_SRC_DIR );
- if ( webinfSrcPos != -1 )
+ jpfParentRelativePath = jpfParentRelativePath.replace(
'\\', '/' );
+
+ if ( jpfParentRelativePath.startsWith( WEBINF_SRC_DIR ) )
{
- parentFile = new File( jpfFilePath.substring( 0,
webinfSrcPos )
- + jpfFilePath.substring(
webinfSrcPos + WEBINF_SRC_DIR.length() ) );
- parentFile = parentFile.getParentFile();
+ jpfParentRelativePath =
jpfParentRelativePath.substring( WEBINF_SRC_DIR.length() );
}
}
- fileToCheck = new File( parentFile, filePath );
+ File desiredParentDir = new File( webFilesRoot +
jpfParentRelativePath );
+ fileToCheck = new File( desiredParentDir, filePath );
if ( ! fileToCheck.exists() && ! ( ignoreDirectories() &&
fileToCheck.isDirectory() ) )
{
@@ -205,6 +200,40 @@
if ( fileToCheck != null ) _flowControllerInfo.addReferencedFile(
fileToCheck );
return null;
+ }
+
+ protected File getWebFilesRoot( File jpfFile, boolean useAlternateLocation
)
+ {
+ try
+ {
+ String alternateRoot = null;
+ if ( useAlternateLocation )
+ {
+ alternateRoot = getEnv().getOptions().get(
ALTERNATE_WEB_ROOT_DIR_OPTION );
+
+ // TODO: there appears to be a bug in APT where both the
key/value are contained in the key
+ if ( alternateRoot == null )
+ {
+ for ( Object i : getEnv().getOptions().keySet() )
+ {
+ String key = ( String ) i;
+
+ if ( key.startsWith( ALTERNATE_WEB_ROOT_DIR_OPTION +
'=' ) )
+ {
+ alternateRoot = key.substring(
ALTERNATE_WEB_ROOT_DIR_OPTION.length() + 1 );
+ break;
+ }
+ }
+ }
+ }
+
+ return alternateRoot != null ? new File( alternateRoot ) :
StrutsApp.getWebappRootFromJpf( jpfFile );
+ }
+ catch ( NoWebInfDirectoryException e )
+ {
+ assert false : e; // must be caught earlier, before
FlowControllerChecker is invoked
+ return null;
+ }
}
protected boolean checkAnyExtension()
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/StrutsApp.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/StrutsApp.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/StrutsApp.java
Mon Sep 27 14:36:12 2004
@@ -278,6 +278,7 @@
{
File webappRoot = null;
+ // TODO: cache the stringValue of getWebappRootFromJpf. It's
expensive to calculate.
for ( File dir = jpf.getAbsoluteFile().getParentFile(); dir != null &&
webappRoot == null; dir = dir.getParentFile() )
{
if ( new File( dir, WEBINF_DIR_NAME ).isDirectory() )
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
Mon Sep 27 14:36:12 2004
@@ -25,6 +25,7 @@
import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
import org.apache.beehive.netui.pageflow.scoping.internal.ScopedRequestImpl;
import org.apache.beehive.netui.util.FileUtils;
+import org.apache.beehive.netui.util.ServletUtils;
import org.apache.beehive.netui.util.logging.Logger;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionForm;
@@ -37,6 +38,7 @@
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -44,6 +46,8 @@
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
+import java.io.IOException;
+import java.io.PrintStream;
import static org.apache.beehive.netui.pageflow.internal.InternalConstants.*;
import static org.apache.beehive.netui.pageflow.PageFlowConstants.*;
@@ -668,6 +672,15 @@
{
return InternalUtils.getServerAdapter().isSecureResource( uri,
request, servletContext );
}
+
+ /**
+ * @deprecated Use [EMAIL PROTECTED] #isSecureResource(String,
ServletContext, HttpServletRequest)} instead.
+ */
+ public static Boolean isSecureResource( String uri, ServletContext context
)
+ {
+ // TODO: once DefaultServerAdapter has this functionality, delegate to
it.
+ return null;
+ }
/**
* Set a named action output, which corresponds to an input declared by
the <code>pageInput</code> JSP tag.
@@ -897,5 +910,186 @@
{
String actionName = mapping.getPath();
return ( actionName.charAt( 0 ) == '/' ? actionName.substring( 1 ) :
actionName );
+ }
+
+ /**
+ * Get or create the current [EMAIL PROTECTED] GlobalApp} instance.
+ * @deprecated Use [EMAIL PROTECTED] #getGlobalApp} instead.
+ *
+ * @param request the current HttpServletRequest.
+ * @param response the current HttpServletResponse
+ * @return the current [EMAIL PROTECTED] GlobalApp} from the user session,
or a newly-instantiated one
+ * (based on the user's Global.app file) if none was in the
session. Failing that,
+ * return <code>null</code>.
+ */
+ public static GlobalApp ensureGlobalApp( HttpServletRequest request,
HttpServletResponse response )
+ {
+ return ( GlobalApp ) InternalUtils.ensureSharedFlow( request, response
);
+ }
+
+ /**
+ * Get or create the current [EMAIL PROTECTED] GlobalApp} instance.
+ * @deprecated Use [EMAIL PROTECTED] #getGlobalApp} instead.
+ *
+ * @param request the current HttpServletRequest.
+ * @param response the current HttpServletResponse
+ * @return the current [EMAIL PROTECTED] GlobalApp} from the user session,
or a newly-instantiated one
+ * (based on the user's Global.app file) if none was in the
session. Failing that,
+ * return <code>null</code>.
+ */
+ public static GlobalApp ensureGlobalApp( HttpServletRequest request,
HttpServletResponse response,
+ ServletContext servletContext )
+ {
+ return ( GlobalApp ) InternalUtils.ensureSharedFlow( request,
response, servletContext );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#getBindingUpdateErrors} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static Map getBindingUpdateErrors( ServletRequest request )
+ {
+ return InternalUtils.getBindingUpdateErrors( request );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#ensureModuleConfig} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static ModuleConfig ensureModuleConfig( String modulePath,
ServletRequest request, ServletContext context )
+ throws IOException, ServletException
+ {
+ return InternalUtils.ensureModuleConfig( modulePath, request, context
);
+ }
+
+ /**
+ * @deprecated This will be removed with no replacement in a future
release.
+ */
+ public static ModuleConfig getGlobalAppConfig( ServletContext
servletContext )
+ {
+ return InternalUtils.getModuleConfig( GLOBALAPP_MODULE_CONTEXT_PATH,
servletContext );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#getModuleConfig} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static ModuleConfig getModuleConfig( String modulePath,
ServletContext context )
+ {
+ return InternalUtils.getModuleConfig( modulePath, context );
+ }
+
+ /**
+ * Get the file extension from a file name.
+ * @deprecated Use [EMAIL PROTECTED] FileUtils#getFileExtension} instead.
+ *
+ * @param filename the file name.
+ * @return the file extension (everything after the last '.'), or the
empty string if there is no file extension.
+ */
+ public static String getFileExtension( String filename )
+ {
+ return FileUtils.getFileExtension( filename );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#getFlowControllerClassName} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static String getPageFlowClassName( String modulePath,
ServletRequest request, ServletContext context )
+ {
+ return InternalUtils.getFlowControllerClassName( modulePath, request,
context );
+ }
+
+ /**
+ * @deprecated This method no longer has any effect, and will be removed
without replacement in a future release.
+ */
+ public static boolean ensureAppDeployment( HttpServletRequest request,
HttpServletResponse response,
+ ServletContext servletContext )
+ {
+ return false;
+ }
+
+ /**
+ * Tell whether a given URI is absolute, i.e., whether it contains a
scheme-part (e.g., "http:").
+ * @deprecated Use [EMAIL PROTECTED] FileUtils#isAbsoluteURI} instead.
+ *
+ * @param uri the URI to test.
+ * @return <code>true</code> if the given URI is absolute.
+ */
+ public static boolean isAbsoluteURI( String uri )
+ {
+ return FileUtils.isAbsoluteURI( uri );
+ }
+
+ /**
+ * @deprecated Use [EMAIL PROTECTED] #getCurrentPageFlow} instead.
+ */
+ public static final PageFlowController ensureCurrentPageFlow(
HttpServletRequest request,
+
HttpServletResponse response,
+
ServletContext servletContext )
+ {
+ return InternalUtils.ensureCurrentPageFlow( request, response );
+ }
+
+ /**
+ * @deprecated Use [EMAIL PROTECTED] #getCurrentPageFlow} instead.
+ */
+ public static final PageFlowController ensureCurrentPageFlow(
HttpServletRequest request,
+
HttpServletResponse response )
+ {
+ return InternalUtils.ensureCurrentPageFlow( request, response );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#addBindingUpdateError} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static void addBindingUpdateError( ServletRequest request, String
expression, String message, Throwable e )
+ {
+ InternalUtils.addBindingUpdateError( request, expression, message, e );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#dumpRequest} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static void dumpRequest( HttpServletRequest request, PrintStream
output )
+ {
+ InternalUtils.dumpRequest( request, output );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#dumpServletContext} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static void dumpServletContext( ServletContext context, PrintStream
output )
+ {
+ InternalUtils.dumpServletContext( context, output );
+ }
+
+ /**
+ * @deprecated Use [EMAIL PROTECTED] ServletUtils#preventCache} instead.
+ */
+ public static void preventCache( HttpServletResponse response )
+ {
+ ServletUtils.preventCache( response );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#setCurrentActionResolver} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static void setCurrentActionResolver( ActionResolver resolver,
HttpServletRequest request )
+ {
+ InternalUtils.setCurrentActionResolver( resolver, request );
+ }
+
+ /**
+ * @deprecated This is an internal utility. [EMAIL PROTECTED]
InternalUtils#getServerAdapter} can be used, but it is
+ * not guaranteed to be supported in the future.
+ */
+ public static final ServerAdapter getServerAdapter()
+ {
+ return InternalUtils.getServerAdapter();
}
}
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/annotations/Jpf.java
Mon Sep 27 14:36:12 2004
@@ -735,7 +735,7 @@
@Retention( RUNTIME )
public @interface FormBean
{
- String defaultMessageBundle() default "";
+ String messageBundle() default "";
}
@Target( FIELD )
Modified:
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/FileUtils.java
==============================================================================
---
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/FileUtils.java
(original)
+++
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/FileUtils.java
Mon Sep 27 14:36:12 2004
@@ -77,6 +77,7 @@
/**
* Get the file extension from a file name.
+ *
* @param filename the file name.
* @return the file extension (everything after the last '.'), or the
empty string if there is no
* file extension.