Java tutorial
//package com.java2s; /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at license/ESCIDOC.LICENSE * or http://www.escidoc.de/license. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at license/ESCIDOC.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ public class Main { private static final String STAGING_AREA_BASE_PATH = "catalina.home"; private static final String STAGING_AREA = "staging"; private static final String STAGING_AREA_UPLOAD = "upload"; private static String uploadStagingArea; /** * @return The path to the upload staigng area. */ public static String getUploadStagingArea() { if (uploadStagingArea == null) { uploadStagingArea = concatenatePath(System.getProperty(STAGING_AREA_BASE_PATH), STAGING_AREA); uploadStagingArea = concatenatePath(uploadStagingArea, STAGING_AREA_UPLOAD); } return uploadStagingArea; } /** * Concatenates the two given path segments and returns a valid path, i.e. the method takes care that there is only * one path seperator between the path segments, and converts ':' to '_' in the appendix * * @param path The path. * @param appendix The path to append. * @return The concatenated path. */ public static String concatenatePath(final String path, final String appendix) { String result = path; String append = appendix.replaceAll(":", "_"); result = result.replace("\\", "/"); append = append.replace("\\", "/"); result += result.endsWith("/") ? append.startsWith("/") ? append.substring(1) : append : append.startsWith("/") ? append : '/' + append; return result; } }