List of usage examples for org.apache.commons.lang BooleanUtils toBoolean
public static boolean toBoolean(String str)
Converts a String to a boolean (optimised for performance).
'true'
, 'on'
or 'yes'
(case insensitive) will return true
.
From source file:org.apache.cocoon.forms.formmodel.BooleanField.java
public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // value element contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); String stringValue = BooleanUtils.toBoolean(value) ? definition.getTrueParamValue() : "false"; contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length()); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL); // validation message element: only present if the value is not valid if (validationError != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES); validationError.generateSaxFragment(contentHandler); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL); }/*from w ww. j a va 2 s. c om*/ }
From source file:org.apache.cocoon.Main.java
/** * The <code>main</code> method. * * @param args a <code>String[]</code> of arguments * @exception Exception if an error occurs *///from w ww. j a va2 s . c o m public static void main(String[] args) throws Exception { Main.setOptions(); CommandLine line = new PosixParser().parse(options, args); listener = new OutputStreamListener(System.out); CocoonBean cocoon = new CocoonBean(); cocoon.addListener(listener); if (line.hasOption(HELP_OPT)) { printUsage(); } else if (line.hasOption(VERSION_OPT)) { printVersion(); } else { String uriGroup = null; if (line.hasOption(URI_GROUP_NAME_OPT)) { uriGroup = line.getOptionValue(URI_GROUP_NAME_OPT); } String destDir = null; if (line.hasOption(XCONF_OPT)) { // destDir from command line overrides one in xconf file destDir = Main.processXConf(cocoon, line.getOptionValue(XCONF_OPT), destDir, uriGroup); } if (line.hasOption(DEST_DIR_OPT)) { destDir = line.getOptionValue(DEST_DIR_OPT); } if (line.hasOption(VERBOSE_OPT)) { cocoon.setVerbose(true); } if (line.hasOption(PRECOMPILE_ONLY_OPT)) { cocoon.setPrecompileOnly(true); } if (line.hasOption(WORK_DIR_OPT)) { String workDir = line.getOptionValue(WORK_DIR_OPT); if (workDir.length() == 0) { listener.messageGenerated( "Careful, you must specify a work dir when using the -w/--workDir argument"); System.exit(1); } else { cocoon.setWorkDir(line.getOptionValue(WORK_DIR_OPT)); } } if (line.hasOption(CONTEXT_DIR_OPT)) { String contextDir = line.getOptionValue(CONTEXT_DIR_OPT); if (contextDir.length() == 0) { listener.messageGenerated( "Careful, you must specify a configuration file when using the -c/--contextDir argument"); System.exit(1); } else { cocoon.setContextDir(contextDir); } } if (line.hasOption(CONFIG_FILE_OPT)) { cocoon.setConfigFile(line.getOptionValue(CONFIG_FILE_OPT)); } if (line.hasOption(LOG_KIT_OPT)) { cocoon.setLogKit(line.getOptionValue(LOG_KIT_OPT)); } if (line.hasOption(LOGGER_OPT)) { cocoon.setLogger(line.getOptionValue(LOGGER_OPT)); } if (line.hasOption(LOG_LEVEL_OPT)) { cocoon.setLogLevel(line.getOptionValue(LOG_LEVEL_OPT)); } if (line.hasOption(AGENT_OPT)) { cocoon.setAgentOptions(line.getOptionValue(AGENT_OPT)); } if (line.hasOption(ACCEPT_OPT)) { cocoon.setAcceptOptions(line.getOptionValue(ACCEPT_OPT)); } if (line.hasOption(DEFAULT_FILENAME_OPT)) { cocoon.setDefaultFilename(line.getOptionValue(DEFAULT_FILENAME_OPT)); } if (line.hasOption(BROKEN_LINK_FILE_OPT)) { listener.setReportFile(line.getOptionValue(BROKEN_LINK_FILE_OPT)); } if (line.hasOption(FOLLOW_LINKS_OPT)) { cocoon.setFollowLinks(BooleanUtils.toBoolean(line.getOptionValue(FOLLOW_LINKS_OPT))); } if (line.hasOption(CONFIRM_EXTENSIONS_OPT)) { cocoon.setConfirmExtensions( BooleanUtils.toBoolean(line.getOptionValue(CONFIRM_EXTENSIONS_OPT, "yes"))); } if (line.hasOption(LOAD_CLASS_OPT)) { cocoon.addLoadedClasses(Arrays.asList(line.getOptionValues(LOAD_CLASS_OPT))); } if (line.hasOption(URI_FILE_OPT)) { cocoon.addTargets(BeanConfigurator.processURIFile(line.getOptionValue(URI_FILE_OPT)), destDir); } cocoon.addTargets(line.getArgList(), destDir); listener.messageGenerated(CocoonBean.getProlog()); if (cocoon.getTargetCount() == 0 && cocoon.isPrecompileOnly()) { listener.messageGenerated("Please, specify at least one starting URI."); System.exit(1); } cocoon.initialize(); cocoon.process(); cocoon.dispose(); listener.complete(); int exitCode = (listener.isSuccessful() ? 0 : 1); System.exit(exitCode); } }
From source file:org.apache.cocoon.portal.pluto.om.common.PreferenceImpl.java
public String getReadOnly() { return BooleanUtils.toStringTrueFalse(BooleanUtils.toBoolean(readOnly)); }
From source file:org.apache.cocoon.portlet.CocoonPortlet.java
/** * Initialize this <code>CocoonPortlet</code> instance. * * <p>Uses the following parameters: * portlet-logger//from w w w. ja v a 2s . c o m * enable-uploads * autosave-uploads * overwrite-uploads * upload-max-size * show-time * container-encoding * form-encoding * manage-exceptions * servlet-path * * @param conf The PortletConfig object from the portlet container. * @throws PortletException */ public void init(PortletConfig conf) throws PortletException { super.init(conf); // Check the init-classloader parameter only if it's not already true. // This is useful for subclasses of this portlet that override the value // initially set by this class (i.e. false). if (!this.initClassLoader) { this.initClassLoader = getInitParameterAsBoolean("init-classloader", false); } if (this.initClassLoader) { // Force context classloader so that JAXP can work correctly // (see javax.xml.parsers.FactoryFinder.findClassLoader()) try { Thread.currentThread().setContextClassLoader(this.classLoader); } catch (Exception e) { } } try { // FIXME (VG): We shouldn't have to specify these. Need to override // jaxp implementation of weblogic before initializing logger. // This piece of code is also required in the Cocoon class. String value = System.getProperty("javax.xml.parsers.SAXParserFactory"); if (value != null && value.startsWith("weblogic")) { System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); } } catch (SecurityException e) { // Ignore security exception System.out.println("CocoonPortlet: Could not check system properties, got: " + e); } this.portletContext = conf.getPortletContext(); this.appContext.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, new PortletContext(this.portletContext)); this.portletContextPath = this.portletContext.getRealPath("/"); // first init the work-directory for the logger. // this is required if we are running inside a war file! final String workDirParam = getInitParameter("work-directory"); if (workDirParam != null) { if (this.portletContextPath == null) { // No context path : consider work-directory as absolute this.workDir = new File(workDirParam); } else { // Context path exists : is work-directory absolute ? File workDirParamFile = new File(workDirParam); if (workDirParamFile.isAbsolute()) { // Yes : keep it as is this.workDir = workDirParamFile; } else { // No : consider it relative to context path this.workDir = new File(portletContextPath, workDirParam); } } } else { // TODO: Check portlet specification this.workDir = (File) this.portletContext.getAttribute("javax.servlet.context.tempdir"); if (this.workDir == null) { this.workDir = new File(this.portletContext.getRealPath("/WEB-INF/work")); } this.workDir = new File(workDir, "cocoon-files"); } this.workDir.mkdirs(); this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir); String path = this.portletContextPath; // these two variables are just for debugging. We can't log at this point // as the logger isn't initialized yet. String debugPathOne = null, debugPathTwo = null; if (path == null) { // Try to figure out the path of the root from that of WEB-INF try { path = this.portletContext.getResource("/WEB-INF").toString(); } catch (MalformedURLException me) { throw new PortletException("Unable to get resource 'WEB-INF'.", me); } debugPathOne = path; path = path.substring(0, path.length() - "WEB-INF".length()); debugPathTwo = path; } try { if (path.indexOf(':') > 1) { this.portletContextURL = path; } else { this.portletContextURL = new File(path).toURL().toExternalForm(); } } catch (MalformedURLException me) { // VG: Novell has absolute file names starting with the // volume name which is easily more then one letter. // Examples: sys:/apache/cocoon or sys:\apache\cocoon try { this.portletContextURL = new File(path).toURL().toExternalForm(); } catch (MalformedURLException ignored) { throw new PortletException("Unable to determine portlet context URL.", me); } } try { this.appContext.put("context-root", new URL(this.portletContextURL)); } catch (MalformedURLException ignore) { // we simply ignore this } // Init logger initLogger(); if (getLogger().isDebugEnabled()) { getLogger().debug("getRealPath for /: " + this.portletContextPath); if (this.portletContextPath == null) { getLogger().debug("getResource for /WEB-INF: " + debugPathOne); getLogger().debug("Path for Root: " + debugPathTwo); } } this.forceLoadParameter = getInitParameter("load-class", null); this.forceSystemProperty = getInitParameter("force-property", null); // Output some debug info if (getLogger().isDebugEnabled()) { getLogger().debug("Portlet Context URL: " + this.portletContextURL); if (workDirParam != null) { getLogger().debug("Using work-directory " + this.workDir); } else { getLogger().debug("Using default work-directory " + this.workDir); } } final String uploadDirParam = conf.getInitParameter("upload-directory"); if (uploadDirParam != null) { if (this.portletContextPath == null) { this.uploadDir = new File(uploadDirParam); } else { // Context path exists : is upload-directory absolute ? File uploadDirParamFile = new File(uploadDirParam); if (uploadDirParamFile.isAbsolute()) { // Yes : keep it as is this.uploadDir = uploadDirParamFile; } else { // No : consider it relative to context path this.uploadDir = new File(portletContextPath, uploadDirParam); } } if (getLogger().isDebugEnabled()) { getLogger().debug("Using upload-directory " + this.uploadDir); } } else { this.uploadDir = new File(workDir, "upload-dir" + File.separator); if (getLogger().isDebugEnabled()) { getLogger().debug("Using default upload-directory " + this.uploadDir); } } this.uploadDir.mkdirs(); this.appContext.put(Constants.CONTEXT_UPLOAD_DIR, this.uploadDir); this.enableUploads = getInitParameterAsBoolean("enable-uploads", ENABLE_UPLOADS); this.autoSaveUploads = getInitParameterAsBoolean("autosave-uploads", SAVE_UPLOADS_TO_DISK); String overwriteParam = getInitParameter("overwrite-uploads", "rename"); // accepted values are deny|allow|rename - rename is default. if ("deny".equalsIgnoreCase(overwriteParam)) { this.allowOverwrite = false; this.silentlyRename = false; } else if ("allow".equalsIgnoreCase(overwriteParam)) { this.allowOverwrite = true; this.silentlyRename = false; // ignored in this case } else { // either rename is specified or unsupported value - default to rename. this.allowOverwrite = false; this.silentlyRename = true; } this.maxUploadSize = getInitParameterAsInteger("upload-max-size", MAX_UPLOAD_SIZE); String cacheDirParam = conf.getInitParameter("cache-directory"); if (cacheDirParam != null) { if (this.portletContextPath == null) { this.cacheDir = new File(cacheDirParam); } else { // Context path exists : is cache-directory absolute ? File cacheDirParamFile = new File(cacheDirParam); if (cacheDirParamFile.isAbsolute()) { // Yes : keep it as is this.cacheDir = cacheDirParamFile; } else { // No : consider it relative to context path this.cacheDir = new File(portletContextPath, cacheDirParam); } } if (getLogger().isDebugEnabled()) { getLogger().debug("Using cache-directory " + this.cacheDir); } } else { this.cacheDir = IOUtils.createFile(workDir, "cache-dir" + File.separator); if (getLogger().isDebugEnabled()) { getLogger().debug("cache-directory was not set - defaulting to " + this.cacheDir); } } this.cacheDir.mkdirs(); this.appContext.put(Constants.CONTEXT_CACHE_DIR, this.cacheDir); this.appContext.put(Constants.CONTEXT_CONFIG_URL, getConfigFile(conf.getInitParameter("configurations"))); if (conf.getInitParameter("configurations") == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("configurations was not set - defaulting to... ?"); } } // get allow reload parameter, default is true this.allowReload = getInitParameterAsBoolean("allow-reload", ALLOW_RELOAD); String value = conf.getInitParameter("show-time"); this.showTime = BooleanUtils.toBoolean(value) || (this.hiddenShowTime = "hide".equals(value)); if (value == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("show-time was not set - defaulting to false"); } } parentComponentManagerClass = getInitParameter("parent-component-manager", null); if (parentComponentManagerClass != null) { int dividerPos = parentComponentManagerClass.indexOf('/'); if (dividerPos != -1) { parentComponentManagerInitParam = parentComponentManagerClass.substring(dividerPos + 1); parentComponentManagerClass = parentComponentManagerClass.substring(0, dividerPos); } } this.containerEncoding = getInitParameter("container-encoding", "ISO-8859-1"); this.defaultFormEncoding = getInitParameter("form-encoding", "ISO-8859-1"); this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, this.defaultFormEncoding); this.manageExceptions = getInitParameterAsBoolean("manage-exceptions", true); this.enableInstrumentation = getInitParameterAsBoolean("enable-instrumentation", false); this.requestFactory = new RequestFactory(this.autoSaveUploads, this.uploadDir, this.allowOverwrite, this.silentlyRename, this.maxUploadSize, this.defaultFormEncoding); this.servletPath = getInitParameter("servlet-path", null); if (this.servletPath != null) { if (this.servletPath.startsWith("/")) { this.servletPath = this.servletPath.substring(1); } if (this.servletPath.endsWith("/")) { this.servletPath = servletPath.substring(0, servletPath.length() - 1); } } final String sessionScopeParam = getInitParameter("default-session-scope", "portlet"); if ("application".equalsIgnoreCase(sessionScopeParam)) { this.defaultSessionScope = javax.portlet.PortletSession.APPLICATION_SCOPE; } else { this.defaultSessionScope = javax.portlet.PortletSession.PORTLET_SCOPE; } // Add the portlet configuration this.appContext.put(CONTEXT_PORTLET_CONFIG, conf); this.createCocoon(); }
From source file:org.apache.cocoon.portlet.CocoonPortlet.java
/** Convenience method to access boolean portlet parameters */ protected boolean getInitParameterAsBoolean(String name, boolean defaultValue) { String value = getInitParameter(name); if (value == null) { if (getLogger() != null && getLogger().isDebugEnabled()) { getLogger().debug(name + " was not set - defaulting to '" + defaultValue + "'"); }/*from w ww .jav a 2s. c o m*/ return defaultValue; } return BooleanUtils.toBoolean(value); }
From source file:org.apache.cocoon.portlet.ManagedCocoonPortlet.java
/** * Initialize this <code>CocoonPortlet</code> instance. * * <p>Uses the following parameters: * portlet-logger//from w w w . ja v a 2s. c o m * enable-uploads * autosave-uploads * overwrite-uploads * upload-max-size * show-time * container-encoding * form-encoding * manage-exceptions * servlet-path * * @param conf The PortletConfig object from the portlet container. * @throws PortletException */ public void init(PortletConfig conf) throws PortletException { super.init(conf); String value; this.portletContext = conf.getPortletContext(); this.envPortletContext = new PortletContext(this.portletContext); this.portletContextPath = this.portletContext.getRealPath("/"); // first init the work-directory for the logger. // this is required if we are running inside a war file! final String workDirParam = getInitParameter("work-directory"); if (workDirParam != null) { if (this.portletContextPath == null) { // No context path : consider work-directory as absolute this.workDir = new File(workDirParam); } else { // Context path exists : is work-directory absolute ? File workDirParamFile = new File(workDirParam); if (workDirParamFile.isAbsolute()) { // Yes : keep it as is this.workDir = workDirParamFile; } else { // No : consider it relative to context path this.workDir = new File(portletContextPath, workDirParam); } } } else { // TODO: Check portlet specification this.workDir = (File) this.portletContext.getAttribute("javax.servlet.context.tempdir"); if (this.workDir == null) { this.workDir = new File(this.portletContext.getRealPath("/WEB-INF/work")); } this.workDir = new File(workDir, "cocoon-files"); } this.workDir.mkdirs(); // Init logger initLogger(); String path = this.portletContextPath; if (getLogger().isDebugEnabled()) { getLogger().debug("getRealPath for /: " + path); } if (path == null) { // Try to figure out the path of the root from that of WEB-INF try { path = this.portletContext.getResource("/WEB-INF").toString(); } catch (MalformedURLException me) { throw new PortletException("Unable to get resource 'WEB-INF'.", me); } if (getLogger().isDebugEnabled()) { getLogger().debug("getResource for /WEB-INF: " + path); } path = path.substring(0, path.length() - "WEB-INF".length()); if (getLogger().isDebugEnabled()) { getLogger().debug("Path for Root: " + path); } } try { if (path.indexOf(':') > 1) { this.portletContextURL = path; } else { this.portletContextURL = new File(path).toURL().toExternalForm(); } } catch (MalformedURLException me) { // VG: Novell has absolute file names starting with the // volume name which is easily more then one letter. // Examples: sys:/apache/cocoon or sys:\apache\cocoon try { this.portletContextURL = new File(path).toURL().toExternalForm(); } catch (MalformedURLException ignored) { throw new PortletException("Unable to determine portlet context URL.", me); } } if (getLogger().isDebugEnabled()) { getLogger().debug("URL for Root: " + this.portletContextURL); } final String uploadDirParam = conf.getInitParameter("upload-directory"); if (uploadDirParam != null) { if (this.portletContextPath == null) { this.uploadDir = new File(uploadDirParam); } else { // Context path exists : is upload-directory absolute ? File uploadDirParamFile = new File(uploadDirParam); if (uploadDirParamFile.isAbsolute()) { // Yes : keep it as is this.uploadDir = uploadDirParamFile; } else { // No : consider it relative to context path this.uploadDir = new File(portletContextPath, uploadDirParam); } } if (getLogger().isDebugEnabled()) { getLogger().debug("Using upload-directory " + this.uploadDir); } } else { this.uploadDir = new File(workDir, "upload-dir" + File.separator); if (getLogger().isDebugEnabled()) { getLogger().debug("upload-directory was not set - defaulting to " + this.uploadDir); } } this.uploadDir.mkdirs(); this.enableUploads = getInitParameterAsBoolean("enable-uploads", ENABLE_UPLOADS); this.autoSaveUploads = getInitParameterAsBoolean("autosave-uploads", SAVE_UPLOADS_TO_DISK); String overwriteParam = getInitParameter("overwrite-uploads", "rename"); // accepted values are deny|allow|rename - rename is default. if ("deny".equalsIgnoreCase(overwriteParam)) { this.allowOverwrite = false; this.silentlyRename = false; } else if ("allow".equalsIgnoreCase(overwriteParam)) { this.allowOverwrite = true; this.silentlyRename = false; // ignored in this case } else { // either rename is specified or unsupported value - default to rename. this.allowOverwrite = false; this.silentlyRename = true; } this.maxUploadSize = getInitParameterAsInteger("upload-max-size", MAX_UPLOAD_SIZE); value = conf.getInitParameter("show-time"); this.showTime = BooleanUtils.toBoolean(value) || (this.hiddenShowTime = "hide".equals(value)); if (value == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("show-time was not set - defaulting to false"); } } this.containerEncoding = getInitParameter("container-encoding", "ISO-8859-1"); this.defaultFormEncoding = getInitParameter("form-encoding", "ISO-8859-1"); this.manageExceptions = getInitParameterAsBoolean("manage-exceptions", true); this.requestFactory = new RequestFactory(this.autoSaveUploads, this.uploadDir, this.allowOverwrite, this.silentlyRename, this.maxUploadSize, this.defaultFormEncoding); this.servletPath = getInitParameter("servlet-path", null); if (this.servletPath != null) { if (this.servletPath.startsWith("/")) { this.servletPath = this.servletPath.substring(1); } if (this.servletPath.endsWith("/")) { this.servletPath = servletPath.substring(0, servletPath.length() - 1); } } final String sessionScopeParam = getInitParameter("default-session-scope", "portlet"); if ("application".equalsIgnoreCase(sessionScopeParam)) { this.defaultSessionScope = javax.portlet.PortletSession.APPLICATION_SCOPE; } else { this.defaultSessionScope = javax.portlet.PortletSession.PORTLET_SCOPE; } this.storeSessionPath = getInitParameterAsBoolean("store-session-path", false); }
From source file:org.apache.cocoon.servlet.CocoonServlet.java
/** * Initialize this <code>CocoonServlet</code> instance. You will * notice that I have broken the init into sub methods to make it * easier to maintain (BL). The context is passed to a couple of * the subroutines. This is also because it is better to explicitly * pass variables than implicitely. It is both more maintainable, * and more elegant.//ww w.ja va2 s . co m * * @param conf The ServletConfig object from the servlet engine. * * @throws ServletException */ public void init(ServletConfig conf) throws ServletException { super.init(conf); // Check the init-classloader parameter only if it's not already true. // This is useful for subclasses of this servlet that override the value // initially set by this class (i.e. false). if (!this.initClassLoader) { this.initClassLoader = getInitParameterAsBoolean("init-classloader", false); } if (this.initClassLoader) { // Force context classloader so that JAXP can work correctly // (see javax.xml.parsers.FactoryFinder.findClassLoader()) try { Thread.currentThread().setContextClassLoader(this.classLoader); } catch (Exception e) { // ignore this } } try { // FIXME (VG): We shouldn't have to specify these. Need to override // jaxp implementation of weblogic before initializing logger. // This piece of code is also required in the Cocoon class. String value = System.getProperty("javax.xml.parsers.SAXParserFactory"); if (value != null && value.startsWith("weblogic")) { System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); } } catch (Exception e) { // Ignore security exception System.out.println("CocoonServlet: Could not check system properties, got: " + e); } this.servletContext = conf.getServletContext(); this.appContext.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, new HttpContext(this.servletContext)); this.servletContextPath = this.servletContext.getRealPath("/"); // first init the work-directory for the logger. // this is required if we are running inside a war file! final String workDirParam = getInitParameter("work-directory"); if (workDirParam != null) { if (this.servletContextPath == null) { // No context path : consider work-directory as absolute this.workDir = new File(workDirParam); } else { // Context path exists : is work-directory absolute ? File workDirParamFile = new File(workDirParam); if (workDirParamFile.isAbsolute()) { // Yes : keep it as is this.workDir = workDirParamFile; } else { // No : consider it relative to context path this.workDir = new File(servletContextPath, workDirParam); } } } else { this.workDir = (File) this.servletContext.getAttribute("javax.servlet.context.tempdir"); this.workDir = new File(workDir, "cocoon-files"); } this.workDir.mkdirs(); this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir); String path = this.servletContextPath; // these two variables are just for debugging. We can't log at this point // as the logger isn't initialized yet. String debugPathOne = null, debugPathTwo = null; if (path == null) { // Try to figure out the path of the root from that of WEB-INF try { path = this.servletContext.getResource("/WEB-INF").toString(); } catch (MalformedURLException me) { throw new ServletException("Unable to get resource 'WEB-INF'.", me); } debugPathOne = path; path = path.substring(0, path.length() - "WEB-INF".length()); debugPathTwo = path; } try { if (path.indexOf(':') > 1) { this.servletContextURL = path; } else { this.servletContextURL = new File(path).toURL().toExternalForm(); } } catch (MalformedURLException me) { // VG: Novell has absolute file names starting with the // volume name which is easily more then one letter. // Examples: sys:/apache/cocoon or sys:\apache\cocoon try { this.servletContextURL = new File(path).toURL().toExternalForm(); } catch (MalformedURLException ignored) { throw new ServletException("Unable to determine servlet context URL.", me); } } try { this.appContext.put("context-root", new URL(this.servletContextURL)); } catch (MalformedURLException ignore) { // we simply ignore this } // Init logger initLogger(); if (getLogger().isDebugEnabled()) { getLogger().debug("getRealPath for /: " + this.servletContextPath); if (this.servletContextPath == null) { getLogger().debug("getResource for /WEB-INF: " + debugPathOne); getLogger().debug("Path for Root: " + debugPathTwo); } } this.forceLoadParameter = getInitParameter("load-class", null); this.forceSystemProperty = getInitParameter("force-property", null); // Output some debug info if (getLogger().isDebugEnabled()) { getLogger().debug("Servlet Context URL: " + this.servletContextURL); if (workDirParam != null) { getLogger().debug("Using work-directory " + this.workDir); } else { getLogger().debug("Using default work-directory " + this.workDir); } } final String uploadDirParam = conf.getInitParameter("upload-directory"); if (uploadDirParam != null) { if (this.servletContextPath == null) { this.uploadDir = new File(uploadDirParam); } else { // Context path exists : is upload-directory absolute ? File uploadDirParamFile = new File(uploadDirParam); if (uploadDirParamFile.isAbsolute()) { // Yes : keep it as is this.uploadDir = uploadDirParamFile; } else { // No : consider it relative to context path this.uploadDir = new File(servletContextPath, uploadDirParam); } } if (getLogger().isDebugEnabled()) { getLogger().debug("Using upload-directory " + this.uploadDir); } } else { this.uploadDir = new File(workDir, "upload-dir" + File.separator); if (getLogger().isDebugEnabled()) { getLogger().debug("Using default upload-directory " + this.uploadDir); } } this.uploadDir.mkdirs(); this.appContext.put(Constants.CONTEXT_UPLOAD_DIR, this.uploadDir); this.enableUploads = getInitParameterAsBoolean("enable-uploads", ENABLE_UPLOADS); this.autoSaveUploads = getInitParameterAsBoolean("autosave-uploads", SAVE_UPLOADS_TO_DISK); String overwriteParam = getInitParameter("overwrite-uploads", "rename"); // accepted values are deny|allow|rename - rename is default. if ("deny".equalsIgnoreCase(overwriteParam)) { this.allowOverwrite = false; this.silentlyRename = false; } else if ("allow".equalsIgnoreCase(overwriteParam)) { this.allowOverwrite = true; this.silentlyRename = false; // ignored in this case } else { // either rename is specified or unsupported value - default to rename. this.allowOverwrite = false; this.silentlyRename = true; } this.maxUploadSize = getInitParameterAsInteger("upload-max-size", MAX_UPLOAD_SIZE); String cacheDirParam = conf.getInitParameter("cache-directory"); if (cacheDirParam != null) { if (this.servletContextPath == null) { this.cacheDir = new File(cacheDirParam); } else { // Context path exists : is cache-directory absolute ? File cacheDirParamFile = new File(cacheDirParam); if (cacheDirParamFile.isAbsolute()) { // Yes : keep it as is this.cacheDir = cacheDirParamFile; } else { // No : consider it relative to context path this.cacheDir = new File(servletContextPath, cacheDirParam); } } if (getLogger().isDebugEnabled()) { getLogger().debug("Using cache-directory " + this.cacheDir); } } else { this.cacheDir = IOUtils.createFile(workDir, "cache-dir" + File.separator); if (getLogger().isDebugEnabled()) { getLogger().debug("cache-directory was not set - defaulting to " + this.cacheDir); } } this.cacheDir.mkdirs(); this.appContext.put(Constants.CONTEXT_CACHE_DIR, this.cacheDir); this.appContext.put(Constants.CONTEXT_CONFIG_URL, getConfigFile(conf.getInitParameter("configurations"))); if (conf.getInitParameter("configurations") == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("configurations was not set - defaulting to... ?"); } } // get allow reload parameter, default is true this.allowReload = getInitParameterAsBoolean("allow-reload", ALLOW_RELOAD); String value = conf.getInitParameter("show-time"); this.showTime = BooleanUtils.toBoolean(value) || (this.hiddenShowTime = "hide".equals(value)); if (value == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("show-time was not set - defaulting to false"); } } this.showCocoonVersion = getInitParameterAsBoolean("show-cocoon-version", true); parentComponentManagerClass = getInitParameter("parent-component-manager", null); if (parentComponentManagerClass != null) { int dividerPos = parentComponentManagerClass.indexOf('/'); if (dividerPos != -1) { parentComponentManagerInitParam = parentComponentManagerClass.substring(dividerPos + 1); parentComponentManagerClass = parentComponentManagerClass.substring(0, dividerPos); } } this.containerEncoding = getInitParameter("container-encoding", "ISO-8859-1"); this.defaultFormEncoding = getInitParameter("form-encoding", "ISO-8859-1"); this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, this.defaultFormEncoding); this.manageExceptions = getInitParameterAsBoolean("manage-exceptions", true); this.enableInstrumentation = getInitParameterAsBoolean("enable-instrumentation", false); this.requestFactory = new RequestFactory(this.autoSaveUploads, this.uploadDir, this.allowOverwrite, this.silentlyRename, this.maxUploadSize, this.containerEncoding); // Add the servlet configuration this.appContext.put(CONTEXT_SERVLET_CONFIG, conf); this.createCocoon(); }
From source file:org.apache.cocoon.servlet.multipart.MultipartConfigurationHelper.java
/** * Configure this from the settings object. * @param settings/*from w w w . j a v a 2 s .co m*/ */ public void configure(Settings settings, Log logger) { String value; value = settings.getProperty(KEY_UPLOADS_ENABLE); if (value != null) { setEnableUploads(BooleanUtils.toBoolean(value)); } value = settings.getProperty(KEY_UPLOADS_DIRECTORY); if (value != null) { setUploadDirectory(value); } value = settings.getProperty(KEY_UPLOADS_AUTOSAVE); if (value != null) { setAutosaveUploads(BooleanUtils.toBoolean(value)); } value = settings.getProperty(KEY_UPLOADS_OVERWRITE); if (value != null) { setOverwriteUploads(value); } value = settings.getProperty(KEY_UPLOADS_MAXSIZE); if (value != null) { setMaxUploadSize(Integer.valueOf(value).intValue()); } final String uploadDirParam = getUploadDirectory(); File uploadDir; if (uploadDirParam != null) { uploadDir = new File(uploadDirParam); if (logger.isDebugEnabled()) { logger.debug("Using upload-directory " + uploadDir); } } else { uploadDir = new File(settings.getWorkDirectory(), "upload-dir" + File.separator); if (logger.isDebugEnabled()) { logger.debug("Using default upload-directory " + uploadDir); } } uploadDir.mkdirs(); setUploadDirectory(uploadDir.getAbsolutePath()); }
From source file:org.apache.cocoon.servlet.ServletSettings.java
public ServletSettings(Settings s) { // set defaults this.showTime = SHOW_TIME; this.hideShowTime = HIDE_SHOW_TIME; this.showCocoonVersion = SHOW_COCOON_VERSION; this.manageExceptions = MANAGE_EXCEPTIONS; if (s != null) { String value;//from w w w . j a va 2 s.c om value = s.getProperty(KEY_SHOWTIME); if (value != null) { this.setShowTime(BooleanUtils.toBoolean(value)); } value = s.getProperty(KEY_HIDE_SHOWTIME); if (value != null) { this.setHideShowTime(BooleanUtils.toBoolean(value)); } value = s.getProperty(KEY_SHOW_VERSION); if (value != null) { this.setShowCocoonVersion(BooleanUtils.toBoolean(value)); } value = s.getProperty(KEY_MANAGE_EXCEPTIONS); if (value != null) { this.setManageExceptions(BooleanUtils.toBoolean(value)); } } }
From source file:org.apache.cocoon.template.instruction.Out.java
public Event execute(final XMLConsumer consumer, ExpressionContext expressionContext, ExecutionContext executionContext, MacroContext macroContext, Event startEvent, Event endEvent) throws SAXException { Object val; try {//from www . j a v a 2 s. c o m val = this.compiledExpression.getNode(expressionContext); boolean stripRoot = BooleanUtils.toBoolean(this.stripRoot); //TODO: LG, I do not see a good way to do this. if (BooleanUtils.isTrue(this.xmlize)) { if (val instanceof Node || val instanceof Node[] || val instanceof XMLizable) Invoker.executeNode(consumer, val, stripRoot); else { ServiceManager serviceManager = executionContext.getServiceManager(); SAXParser parser = null; try { parser = (SAXParser) serviceManager.lookup(SAXParser.ROLE); InputSource source = new InputSource(new ByteArrayInputStream(val.toString().getBytes())); IncludeXMLConsumer includeConsumer = new IncludeXMLConsumer(consumer); includeConsumer.setIgnoreRootElement(stripRoot); parser.parse(source, includeConsumer); } finally { serviceManager.release(parser); } } } else Invoker.executeNode(consumer, val, stripRoot); } catch (Exception e) { throw new SAXParseException(e.getMessage(), getLocation(), e); } return getNext(); }