FileDocCategorySizeDatePackage
JSPCompiler.javaAPI DocGlassfish v2 API11815Fri May 04 22:34:32 BST 2007com.sun.enterprise.deployment.backend

JSPCompiler

public final class JSPCompiler extends Object

Fields Summary
private static final String
startMessage
private static final String
finishMessage
private static final Logger
logger
Constructors Summary
Methods Summary
public static voidcompile(java.io.File inWebDir, java.io.File outWebDir, com.sun.enterprise.deployment.WebBundleDescriptor wbd)

		compile(inWebDir, outWebDir, wbd, null);
	
public static voidcompile(java.io.File inWebDir, java.io.File outWebDir, com.sun.enterprise.deployment.WebBundleDescriptor wbd, java.util.List classpathList)

		JspC jspc = new JspC();

		if (classpathList != null) 
		{
			String classpath = getClasspath(classpathList);
		
			if (classpath != null) 
				jspc.setClassPath(classpath);
		}

                // START SJSAS 6311155
                String appName = wbd.getApplication().getName();
                String sysClassPath = ASClassLoaderUtil.getWebModuleClassPath(appName);
                jspc.setSystemClassPath(sysClassPath);
                // END SJSAS 6311155

		verify(inWebDir, outWebDir);

		configureJspc(jspc, wbd);
		jspc.setOutputDir(outWebDir.getAbsolutePath());
		jspc.setUriroot(inWebDir.getAbsolutePath());
		jspc.setCompile(true);
		logger.info(startMessage);

		try 
		{
			jspc.execute();
		} 
		catch (Exception je) 
		{
			throw new IASDeploymentException("JSP Compilation Error: " + je, je);
		}
		finally
		{
			// bnevins 9-9-03 -- There may be no jsp files in this web-module
			// in such a case the code above will create a useless, and possibly
			// problematic empty directory.	 If the directory is empty -- delete
			// the directory.
			
			String[] files = outWebDir.list();
			
			if(files == null || files.length <= 0)
				outWebDir.delete();
			
			logger.info(finishMessage);
		}
	
private static voidconfigureJspc(org.apache.jasper.JspC jspc, com.sun.enterprise.deployment.WebBundleDescriptor wbd)


	    SunWebApp sunWebApp = wbd.getSunDescriptor();
	    if (sunWebApp == null) {
		return;
	    }

            // START SJSAS 6384538
            if (sunWebApp.sizeWebProperty() > 0) {
                WebProperty[] props = sunWebApp.getWebProperty();
                for (int i = 0; i < props.length; i++) {
                    String pName = props[i].getAttributeValue("name");
                    String pValue = props[i].getAttributeValue("value");
                    if (pName == null || pValue == null) {
                        throw new IllegalArgumentException(
                            "Missing sun-web-app property name or value");
                    }
                    if ("enableTldValidation".equals(pName)) {
                        jspc.setIsValidationEnabled(
                            Boolean.valueOf(pValue).booleanValue());
                    }
                }
            }
            // END SJSAS 6384538

            // START SJSAS 6170435
            /*
             * Configure JspC with the init params of the JspServlet
             */
            Set set = wbd.getWebComponentDescriptorsSet();         
            if (!set.isEmpty()) {
                Iterator<WebComponentDescriptor> iterator = set.iterator();
                while (iterator.hasNext()) {
                    WebComponentDescriptor webComponentDesc = iterator.next();
                    if ("jsp".equals(webComponentDesc.getCanonicalName())) {
                        Enumeration<InitializationParameter> en
                            = webComponentDesc.getInitializationParameters();
                        if (en != null) {
                            while (en.hasMoreElements()) {
                                InitializationParameter initP = en.nextElement();
                                configureJspc(jspc,
                                              initP.getName(),
                                              initP.getValue());
                            }
                        }
                        break;
                    }
                }
            }
            // END SJSAS 6170435

            /*
             * Configure JspC with jsp-config properties from sun-web.xml,
             * which override JspServlet init params of the same name.
             */
            JspConfig jspConfig = sunWebApp.getJspConfig();
            if (jspConfig == null) {
                return;
            }
            WebProperty[] props = jspConfig.getWebProperty();
            for (int i=0; props!=null && i<props.length; i++) {
                configureJspc(jspc,
                              props[i].getAttributeValue("name"),
                              props[i].getAttributeValue("value"));
            }
        
private static voidconfigureJspc(org.apache.jasper.JspC jspc, java.lang.String pName, java.lang.String pValue)


            if (pName == null || pValue == null) {
                throw new IllegalArgumentException(
                    "Null property name or value");
            }

            if ("xpoweredBy".equals(pName)) {
                jspc.setXpoweredBy(Boolean.valueOf(pValue).booleanValue());
            } else if ("classdebuginfo".equals(pName)) {
                jspc.setClassDebugInfo(Boolean.valueOf(pValue).booleanValue());
            } else if ("enablePooling".equals(pName)) {
                jspc.setPoolingEnabled(Boolean.valueOf(pValue).booleanValue());
            } else if ("ieClassId".equals(pName)) {
                jspc.setIeClassId(pValue);
            } else if ("trimSpaces".equals(pName)) {
                jspc.setTrimSpaces(Boolean.valueOf(pValue).booleanValue());
            } else if ("genStrAsCharArray".equals(pName)) {
                jspc.setGenStringAsCharArray(
                    Boolean.valueOf(pValue).booleanValue());
            } else if ("errorOnUseBeanInvalidClassAttribute".equals(pName)) {
                jspc.setErrorOnUseBeanInvalidClassAttribute(
                    Boolean.valueOf(pValue).booleanValue());
            } else if ("ignoreJspFragmentErrors".equals(pName)) {
                jspc.setIgnoreJspFragmentErrors(
                    Boolean.valueOf(pValue).booleanValue());
            }
        
private static java.lang.StringgetClasspath(java.util.List paths)

		if(paths == null)
			return null;
		
		String classpath = null;

		StringBuffer sb = new StringBuffer();
		boolean first = true;

		for (Iterator it = paths.iterator(); it.hasNext(); ) 
		{
			String path = (String)it.next();

			if (first) 
				first = false;
			else 
				sb.append(File.pathSeparatorChar);

			sb.append(path);
		}

		if (sb.length() > 0) 
			classpath = sb.toString();

		return classpath;	
	
private static com.sun.enterprise.util.i18n.StringManagergetStringManager()


	////////////////////////////////////////////////////////////////////////////
	
          
      
        return StringManager.getManager( JSPCompiler.class );
    
private static voidverify(java.io.File inWebDir, java.io.File outWebDir)

		// inWebDir must exist, outWebDir must either exist or be creatable
		if (!FileUtils.safeIsDirectory(inWebDir)) 
		{
			throw new IASDeploymentException("inWebDir is not a directory: " + inWebDir);
		}
	 
		if (!FileUtils.safeIsDirectory(outWebDir)) 
		{
			outWebDir.mkdirs();
		
			if (!FileUtils.safeIsDirectory(outWebDir)) 
			{
				throw new IASDeploymentException("outWebDir is not a directory, and it can't be created: " + outWebDir);
			}
		}