List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:eu.stratosphere.client.web.WebInterfaceServer.java
/** * Creates a new web interface server. The server runs the servlets that implement the logic * to upload, list, delete and submit jobs, to compile them and to show the optimizer plan. * It serves the asynchronous requests for the plans and all other static resources, like * static web pages, stylesheets or javascript files. * // w w w .j a v a 2 s .co m * @param nepheleConfig * The configuration for the nephele job manager. All compiled jobs will be sent * to the manager described by this configuration. * @param port * The port to launch the server on. * @throws IOException * Thrown, if the server setup failed for an I/O related reason. */ public WebInterfaceServer(Configuration nepheleConfig, int port) throws IOException { Configuration config = GlobalConfiguration.getConfiguration(); // if no explicit configuration is given, use the global configuration if (nepheleConfig == null) { nepheleConfig = config; } // get base path of Stratosphere installation String basePath = nepheleConfig.getString(ConfigConstants.STRATOSPHERE_BASE_DIR_PATH_KEY, ""); File webDir; File tmpDir; File uploadDir; File planDumpDir; String webDirPath = config.getString(ConfigConstants.WEB_ROOT_PATH_KEY, ConfigConstants.DEFAULT_WEB_ROOT_DIR); if (webDirPath.startsWith("/")) { // absolute path webDir = new File(webDirPath); } else { // path relative to base dir webDir = new File(basePath + "/" + webDirPath); } String tmpDirPath = config.getString(ConfigConstants.WEB_TMP_DIR_KEY, ConfigConstants.DEFAULT_WEB_TMP_DIR); tmpDir = new File(tmpDirPath); if (tmpDir.isAbsolute()) { // absolute path, everything all right } else { // path relative to base dir tmpDir = new File(basePath + "/" + tmpDirPath); } String uploadDirPath = config.getString(ConfigConstants.WEB_JOB_UPLOAD_DIR_KEY, ConfigConstants.DEFAULT_WEB_JOB_STORAGE_DIR); uploadDir = new File(uploadDirPath); if (uploadDir.isAbsolute()) { // absolute path, everything peachy } else { // path relative to base dir uploadDir = new File(basePath + "/" + uploadDirPath); } String planDumpDirPath = config.getString(ConfigConstants.WEB_PLAN_DUMP_DIR_KEY, ConfigConstants.DEFAULT_WEB_PLAN_DUMP_DIR); planDumpDir = new File(planDumpDirPath); if (planDumpDir.isAbsolute()) { // absolute path, nice and dandy } else { // path relative to base dir planDumpDir = new File(basePath + "/" + planDumpDirPath); } if (LOG.isInfoEnabled()) { LOG.info( "Setting up web frontend server, using web-root directory '" + webDir.getAbsolutePath() + "'."); LOG.info("Web frontend server will store temporary files in '" + tmpDir.getAbsolutePath() + "', uploaded jobs in '" + uploadDir.getAbsolutePath() + "', plan-json-dumps in '" + planDumpDir.getAbsolutePath() + "'."); LOG.info("Web-frontend will submit jobs to nephele job-manager on " + config.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, null) + ", port " + config.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, ConfigConstants.DEFAULT_JOB_MANAGER_IPC_PORT) + "."); } server = new Server(port); // ensure that the directory with the web documents exists if (!webDir.exists()) { throw new FileNotFoundException( "The directory containing the web documents does not exist: " + webDir.getAbsolutePath()); } // ensure, that all the directories exist checkAndCreateDirectories(tmpDir, true); checkAndCreateDirectories(uploadDir, true); checkAndCreateDirectories(planDumpDir, true); int jobManagerWebPort = config.getInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, ConfigConstants.DEFAULT_JOB_MANAGER_WEB_FRONTEND_PORT); // ----- the handlers for the servlets ----- ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContext.setContextPath("/"); servletContext.addServlet(new ServletHolder(new PactJobJSONServlet(uploadDir)), "/pactPlan"); servletContext.addServlet(new ServletHolder(new JobsInfoServlet(nepheleConfig)), "/jobsInfo"); servletContext.addServlet(new ServletHolder(new PlanDisplayServlet(jobManagerWebPort)), "/showPlan"); servletContext.addServlet(new ServletHolder(new JobsServlet(uploadDir, tmpDir, "launch.html")), "/jobs"); servletContext.addServlet( new ServletHolder(new JobSubmissionServlet(nepheleConfig, uploadDir, planDumpDir)), "/runJob"); // ----- the hander serving the written pact plans ----- ResourceHandler pactPlanHandler = new ResourceHandler(); pactPlanHandler.setDirectoriesListed(false); pactPlanHandler.setResourceBase(planDumpDir.getAbsolutePath()); ContextHandler pactPlanContext = new ContextHandler(); pactPlanContext.setContextPath("/ajax-plans"); pactPlanContext.setHandler(pactPlanHandler); // ----- the handler serving all the static files ----- ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setDirectoriesListed(false); resourceHandler.setResourceBase(webDir.getAbsolutePath()); // ----- add the handlers to the list handler ----- HandlerList handlers = new HandlerList(); handlers.addHandler(servletContext); handlers.addHandler(pactPlanContext); handlers.addHandler(resourceHandler); // ----- create the login module with http authentication ----- File af = null; String authFile = config.getString(ConfigConstants.WEB_ACCESS_FILE_KEY, ConfigConstants.DEFAULT_WEB_ACCESS_FILE_PATH); if (authFile != null) { af = new File(authFile); if (!af.exists()) { LOG.error("The specified file '" + af.getAbsolutePath() + "' with the authentication information is missing. Starting server without HTTP authentication."); af = null; } } if (af != null) { HashLoginService loginService = new HashLoginService("Stratosphere Query Engine Interface", authFile); server.addBean(loginService); Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setAuthenticate(true); constraint.setRoles(new String[] { "user" }); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec("/*"); mapping.setConstraint(constraint); ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); sh.addConstraintMapping(mapping); sh.setAuthenticator(new BasicAuthenticator()); sh.setLoginService(loginService); sh.setStrict(true); // set the handers: the server hands the request to the security handler, // which hands the request to the other handlers when authenticated sh.setHandler(handlers); server.setHandler(sh); } else { server.setHandler(handlers); } }
From source file:org.apache.flink.client.web.WebInterfaceServer.java
/** * Creates a new web interface server. The server runs the servlets that implement the logic * to upload, list, delete and submit jobs, to compile them and to show the optimizer plan. * It serves the asynchronous requests for the plans and all other static resources, like * static web pages, stylesheets or javascript files. * /*from w w w. j a va 2 s . c o m*/ * @param nepheleConfig * The configuration for the nephele job manager. All compiled jobs will be sent * to the manager described by this configuration. * @param port * The port to launch the server on. * @throws IOException * Thrown, if the server setup failed for an I/O related reason. */ public WebInterfaceServer(Configuration nepheleConfig, int port) throws IOException { Configuration config = GlobalConfiguration.getConfiguration(); // if no explicit configuration is given, use the global configuration if (nepheleConfig == null) { nepheleConfig = config; } // get base path of Flink installation String basePath = nepheleConfig.getString(ConfigConstants.FLINK_BASE_DIR_PATH_KEY, ""); File webDir; File tmpDir; File uploadDir; File planDumpDir; String webDirPath = config.getString(ConfigConstants.WEB_ROOT_PATH_KEY, ConfigConstants.DEFAULT_WEB_ROOT_DIR); if (webDirPath.startsWith("/")) { // absolute path webDir = new File(webDirPath); } else { // path relative to base dir webDir = new File(basePath + "/" + webDirPath); } String tmpDirPath = config.getString(ConfigConstants.WEB_TMP_DIR_KEY, ConfigConstants.DEFAULT_WEB_TMP_DIR); tmpDir = new File(tmpDirPath); if (tmpDir.isAbsolute()) { // absolute path, everything all right } else { // path relative to base dir tmpDir = new File(basePath + "/" + tmpDirPath); } String uploadDirPath = config.getString(ConfigConstants.WEB_JOB_UPLOAD_DIR_KEY, ConfigConstants.DEFAULT_WEB_JOB_STORAGE_DIR); uploadDir = new File(uploadDirPath); if (uploadDir.isAbsolute()) { // absolute path, everything peachy } else { // path relative to base dir uploadDir = new File(basePath + "/" + uploadDirPath); } String planDumpDirPath = config.getString(ConfigConstants.WEB_PLAN_DUMP_DIR_KEY, ConfigConstants.DEFAULT_WEB_PLAN_DUMP_DIR); planDumpDir = new File(planDumpDirPath); if (planDumpDir.isAbsolute()) { // absolute path, nice and dandy } else { // path relative to base dir planDumpDir = new File(basePath + "/" + planDumpDirPath); } if (LOG.isInfoEnabled()) { LOG.info( "Setting up web frontend server, using web-root directory '" + webDir.getAbsolutePath() + "'."); LOG.info("Web frontend server will store temporary files in '" + tmpDir.getAbsolutePath() + "', uploaded jobs in '" + uploadDir.getAbsolutePath() + "', plan-json-dumps in '" + planDumpDir.getAbsolutePath() + "'."); LOG.info("Web-frontend will submit jobs to nephele job-manager on " + config.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, null) + ", port " + config.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, ConfigConstants.DEFAULT_JOB_MANAGER_IPC_PORT) + "."); } server = new Server(port); // ensure that the directory with the web documents exists if (!webDir.exists()) { throw new FileNotFoundException( "The directory containing the web documents does not exist: " + webDir.getAbsolutePath()); } // ensure, that all the directories exist checkAndCreateDirectories(tmpDir, true); checkAndCreateDirectories(uploadDir, true); checkAndCreateDirectories(planDumpDir, true); int jobManagerWebPort = config.getInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, ConfigConstants.DEFAULT_JOB_MANAGER_WEB_FRONTEND_PORT); // ----- the handlers for the servlets ----- ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContext.setContextPath("/"); servletContext.addServlet(new ServletHolder(new PactJobJSONServlet(uploadDir)), "/pactPlan"); servletContext.addServlet(new ServletHolder(new JobsInfoServlet(nepheleConfig)), "/jobsInfo"); servletContext.addServlet(new ServletHolder(new PlanDisplayServlet(jobManagerWebPort)), "/showPlan"); servletContext.addServlet(new ServletHolder(new JobsServlet(uploadDir, tmpDir, "launch.html")), "/jobs"); servletContext.addServlet( new ServletHolder(new JobSubmissionServlet(nepheleConfig, uploadDir, planDumpDir)), "/runJob"); // ----- the hander serving the written pact plans ----- ResourceHandler pactPlanHandler = new ResourceHandler(); pactPlanHandler.setDirectoriesListed(false); pactPlanHandler.setResourceBase(planDumpDir.getAbsolutePath()); ContextHandler pactPlanContext = new ContextHandler(); pactPlanContext.setContextPath("/ajax-plans"); pactPlanContext.setHandler(pactPlanHandler); // ----- the handler serving all the static files ----- ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setDirectoriesListed(false); resourceHandler.setResourceBase(webDir.getAbsolutePath()); // ----- add the handlers to the list handler ----- HandlerList handlers = new HandlerList(); handlers.addHandler(servletContext); handlers.addHandler(pactPlanContext); handlers.addHandler(resourceHandler); // ----- create the login module with http authentication ----- File af = null; String authFile = config.getString(ConfigConstants.WEB_ACCESS_FILE_KEY, ConfigConstants.DEFAULT_WEB_ACCESS_FILE_PATH); if (authFile != null) { af = new File(authFile); if (!af.exists()) { LOG.error("The specified file '" + af.getAbsolutePath() + "' with the authentication information is missing. Starting server without HTTP authentication."); af = null; } } if (af != null) { HashLoginService loginService = new HashLoginService("Flink Query Engine Interface", authFile); server.addBean(loginService); Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setAuthenticate(true); constraint.setRoles(new String[] { "user" }); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec("/*"); mapping.setConstraint(constraint); ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); sh.addConstraintMapping(mapping); sh.setAuthenticator(new BasicAuthenticator()); sh.setLoginService(loginService); sh.setStrict(true); // set the handers: the server hands the request to the security handler, // which hands the request to the other handlers when authenticated sh.setHandler(handlers); server.setHandler(sh); } else { server.setHandler(handlers); } }
From source file:org.apache.catalina.startup.HostConfig.java
/** * Return a File object representing the "application root" directory * for our associated Host./*from www . j a v a 2 s . c o m*/ */ protected File appBase() { if (appBase != null) { return appBase; } File file = new File(host.getAppBase()); if (!file.isAbsolute()) file = new File(System.getProperty("catalina.base"), host.getAppBase()); try { appBase = file.getCanonicalFile(); } catch (IOException e) { appBase = file; } return (appBase); }
From source file:org.cloudifysource.esc.driver.provisioning.BaseProvisioningDriver.java
/** * Handles credentials for accessing the server - in this order: 1. pem file * (set as a key file on the user block in the groovy file) 2. machine's * remote password (set previously by the cloud driver) * * @param machineDetails/*from w w w . ja v a2 s.c o m*/ * The MachineDetails object that represents this server * @param template * the cloud template. * @throws CloudProvisioningException * Indicates missing credentials or IOException (when a key file * is used) */ protected void handleServerCredentials(final MachineDetails machineDetails, final ComputeTemplate template) throws CloudProvisioningException { File keyFile = null; // using a key (pem) file if (machineDetails.getKeyFile() != null) { keyFile = machineDetails.getKeyFile(); if (!keyFile.isFile()) { throw new CloudProvisioningException( "The specified key file could not be found: " + keyFile.getAbsolutePath()); } } else if (StringUtils.isNotBlank(template.getKeyFile())) { final String keyFileStr = template.getKeyFile(); // fixConfigRelativePaths(cloud, template); keyFile = new File(keyFileStr); if (!keyFile.isAbsolute()) { keyFile = new File(template.getAbsoluteUploadDir(), keyFileStr); } if (keyFile != null && !keyFile.exists()) { throw new CloudProvisioningException( "The specified key file could not be found: " + keyFile.getAbsolutePath()); } } else { // using a password final String remotePassword = machineDetails.getRemotePassword(); if (StringUtils.isNotBlank(remotePassword)) { // is this actually a pem file? if (CredentialUtils.isPrivateKeyCredential(remotePassword)) { logger.fine("Cloud has provided a key file for connections to new machines"); try { keyFile = File.createTempFile("gs-esm-key", ".pem"); keyFile.deleteOnExit(); FileUtils.write(keyFile, remotePassword); // template.setKeyFile(keyFile.getAbsolutePath()); machineDetails.setKeyFile(keyFile); } catch (final IOException e) { throw new CloudProvisioningException( "Failed to create a temporary " + "file for cloud server's key file", e); } } else { // this is a password logger.fine("Cloud has provided a password for remote connections to new machines"); } } else { // if we got here - there is no key file or password on the // cloud or node. logger.severe("No Password or key file specified in the cloud configuration file - connection to" + " the new machine is not possible."); throw new CloudProvisioningException( "No credentials (password or key file) supplied with the cloud configuration file"); } } logServerDetails(machineDetails, keyFile); }
From source file:architecture.ee.plugin.impl.PluginManagerImpl.java
protected void loadDevPlugins() { List<String> paths = PluginUtils.getDevPluginPaths(); if (!paths.isEmpty()) { for (String dirString : paths) { try { File pluginDir = new File(dirString); File dir;// www . j av a 2 s . c om if (pluginDir.isAbsolute()) { dir = pluginDir; } else { String workingDir = System.getProperty("user.dir"); dir = new File(workingDir, dirString); } if (!getDevPlugins().contains(dir.toString())) { PluginEntityObject bean = new PluginEntityObject(); bean.setName(dir.getName()); loadPlugin(dir, bean); getDevPlugins().add(dir.toString()); } } catch (Exception e) { log.error(e.getMessage(), e); } } } }
From source file:org.apache.sling.auth.form.impl.FormAuthenticationHandler.java
/** * Returns an absolute file indicating the file to use to persist the * security tokens.//from w w w.jav a 2 s. com * <p> * This method is not part of the API of this class and is package private * to enable unit tests. * * @param tokenFileName The configured file name, must not be null * @param bundleContext The BundleContext to use to make an relative file * absolute * @return The absolute file */ File getTokenFile(final String tokenFileName, final BundleContext bundleContext) { File tokenFile = new File(tokenFileName); if (tokenFile.isAbsolute()) { return tokenFile; } tokenFile = bundleContext.getDataFile(tokenFileName); if (tokenFile == null) { final String slingHome = bundleContext.getProperty("sling.home"); if (slingHome != null) { tokenFile = new File(slingHome, tokenFileName); } else { tokenFile = new File(tokenFileName); } } return tokenFile.getAbsoluteFile(); }
From source file:org.alfresco.extension.bulkfilesystemimport.impl.AbstractBulkFilesystemImporter.java
/** * If the path is an absolute path, then good; otherwise determine the absolute path. * @return/* w w w.j a v a 2 s .co m*/ */ private String validatePath(String path) { File file = new File(path); if (file.isAbsolute()) return path; final String dir = System.getProperty("user.dir"); return dir + File.separator + path; }
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 .j a v a2 s . c om * 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.cloudifysource.usm.launcher.DefaultProcessLauncher.java
private void modifyWindowsCommandLine(final List<String> commandLineParams, final File workingDir) { final String firstParam = commandLineParams.get(0); if (firstParam.endsWith(".bat") || firstParam.endsWith(".cmd")) { for (int i = 0; i < WINDOWS_BATCH_FILE_PREFIX_PARAMS.length; i++) { commandLineParams.add(i, WINDOWS_BATCH_FILE_PREFIX_PARAMS[i]); }// w w w .j a v a 2 s.c om } // if the file does not exist, this is probably an operating system // command File file = new File(firstParam); if (!file.isAbsolute()) { file = new File(workingDir, firstParam); } if (!file.exists()) { // this is not an executable file, so add the cmd interpreter // prefix for (int i = 0; i < WINDOWS_BATCH_FILE_PREFIX_PARAMS.length; i++) { commandLineParams.add(i, WINDOWS_BATCH_FILE_PREFIX_PARAMS[i]); } } // remove quotes final ListIterator<String> commandIterator = commandLineParams.listIterator(); while (commandIterator.hasNext()) { final String param = commandIterator.next(); commandIterator.remove(); commandIterator.add(StringUtils.replace(param, "\"", "")); } }
From source file:com.silverpeas.importExport.control.GEDImportExport.java
/** * Methode chargee de copier les fichiers images references par le contenu wysiwyg sur le serveur * et de mettre a jour le contenu wysiwyg avec ces nouveaux liens * * @param wysiwygText - contenu wysiwyg passe en parametre * @return - le contenu wysiwyg mis a jour *///from w w w . j a v a 2s . c o m private String replaceWysiwygImagesPathForImport(ImportReportManager reportManager, UnitReport unitReport, int pubId, String wysiwygImportedPath, String wysiwygText, String imageContext) throws ImportExportException { int finPath = 0; int debutPath; StringBuilder newWysiwygText = new StringBuilder(); if (wysiwygText.indexOf("img src=\"", finPath) == -1) { newWysiwygText.append(wysiwygText); } else { // Algorithme d extraction des fichiers images du contenu while ((debutPath = wysiwygText.indexOf("img src=\"", finPath)) != -1) { debutPath += 9; newWysiwygText.append(wysiwygText.substring(finPath, debutPath)); finPath = wysiwygText.indexOf('"', debutPath); String imageSrc = wysiwygText.substring(debutPath, finPath); if (imageSrc.indexOf("http://") != 0) { AttachmentDetail attDetail = new AttachmentDetail(); attDetail.setPhysicalName(imageSrc); File f = new File(imageSrc); if (!f.isAbsolute()) { // si le wysiwyg est issu d une export, les liens image ne comporte que leur nom(donc // pour l import, l utilisateur doit placer // les images wysiwyg dans le meme dossier que le wysiwyg OU remplacer leur chemin par // l absolu attDetail.setPhysicalName( wysiwygImportedPath + File.separator + attDetail.getPhysicalName()); } // TODO: chercher autres infos utiles pour la creation des attachments ensuite try { attDetail = attachmentIE.importWysiwygAttachment(String.valueOf(pubId), getCurrentComponentId(), attDetail, imageContext); reportManager.addNumberOfFilesProcessed(1); if (attDetail == null || attDetail.getSize() == 0) { unitReport.setError(UnitReport.ERROR_NOT_EXISTS_OR_INACCESSIBLE_FILE_FOR_CONTENT); throw new ImportExportException("GEDImportExport.replaceWysiwygImagesPathForImport()", "importExport.EX_CANT_CREATE_CONTENT", "pic = " + imageSrc); } // On additionne la taille des fichiers importes au niveau du rapport reportManager.addImportedFileSize(attDetail.getSize(), getCurrentComponentId()); //TODO FEATURE 82 newWysiwygText.append(webContext).append(attDetail.getAttachmentURL // ()); } catch (Exception e) { SilverTrace.error("importExport", "GEDImportExport.replaceWysiwygImagesPathForImport()", "importExport.CANNOT_FIND_FILE", e); newWysiwygText.append(imageSrc); } } else { newWysiwygText.append(imageSrc); } } newWysiwygText.append(wysiwygText.substring(finPath)); } return newWysiwygText.toString(); }