Example usage for org.apache.commons.lang StringUtils removeEnd

List of usage examples for org.apache.commons.lang StringUtils removeEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils removeEnd.

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:info.magnolia.cms.module.ModuleUtil.java

public static void bootstrap(String[] resourceNames) throws IOException, RegisterException {

    HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.CONFIG);

    // sort by length --> import parent node first
    List list = new ArrayList(Arrays.asList(resourceNames));

    Collections.sort(list, new Comparator() {

        public int compare(Object name1, Object name2) {
            return ((String) name1).length() - ((String) name2).length();
        }// w  ww. j  a va  2s .  com
    });

    for (Iterator iter = list.iterator(); iter.hasNext();) {
        String resourceName = (String) iter.next();

        // windows again
        resourceName = StringUtils.replace(resourceName, "\\", "/");

        String name = StringUtils.removeEnd(StringUtils.substringAfterLast(resourceName, "/"), ".xml");

        String repository = StringUtils.substringBefore(name, ".");
        String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(name, "."), "."); //$NON-NLS-1$
        String nodeName = StringUtils.substringAfterLast(name, ".");
        String fullPath;
        if (StringUtils.isEmpty(pathName)) {
            pathName = "/";
            fullPath = "/" + nodeName;
        } else {
            pathName = "/" + StringUtils.replace(pathName, ".", "/");
            fullPath = pathName + "/" + nodeName;
        }

        // if the path already exists --> delete it
        try {
            if (hm.isExist(fullPath)) {
                hm.delete(fullPath);
                if (log.isDebugEnabled())
                    log.debug("already existing node [{}] deleted", fullPath);
            }

            // if the parent path not exists just create it
            if (!pathName.equals("/")) {
                ContentUtil.createPath(hm, pathName, ItemType.CONTENT);
            }
        } catch (Exception e) {
            throw new RegisterException("can't register bootstrap file: [" + name + "]", e);
        }
        InputStream stream = ModuleUtil.class.getResourceAsStream(resourceName);
        DataTransporter.executeImport(pathName, repository, stream, name, false,
                ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, true, true);
    }
}

From source file:edu.mayo.qdm.webapp.rest.store.Md5HashFileSystemResolver.java

private File getStorageDir(String id, boolean create) {
    String hash = this.getMd5Hash(id);

    String splitHash = this.splitHash(hash);

    splitHash = StringUtils.removeStart(splitHash, File.separator);
    splitHash = StringUtils.removeEnd(splitHash, File.separator);

    String directoryPath = this.getDataDir() + File.separator + splitHash;

    File dir = new File(directoryPath);
    if (!dir.exists() && !create) {
        throw new ExecutionNotFoundException();
    } else {//from   w w  w  .  ja va 2  s .c o  m
        dir.mkdirs();
    }

    return dir;
}

From source file:info.magnolia.init.DefaultMagnoliaInitPaths.java

/**
 * Figures out the root path where the webapp is deployed.
 *//*w w w  .  j a  va  2 s  .c om*/
protected String determineRootPath(ServletContext context) {
    final String retroCompatMethodCall = magnoliaServletContextListener.initRootPath(context);
    if (retroCompatMethodCall != null) {
        DeprecationUtil.isDeprecated(
                "You should update your code and override determineRootPath(ServletContext) instead of initRootPath(ServletContext)");
        return retroCompatMethodCall;
    }

    String realPath = StringUtils.replace(context.getRealPath(StringUtils.EMPTY), "\\", "/");
    realPath = StringUtils.removeEnd(realPath, "/");
    if (realPath == null) {
        // don't use new java.io.File("x").getParentFile().getAbsolutePath() to find out real directory, could throw
        // a NPE for unexpanded war
        throw new RuntimeException(
                "Magnolia is not configured properly and therefore unable to start: real path can't be obtained [ctx real path:"
                        + context.getRealPath(StringUtils.EMPTY)
                        + "]. Please refer to the Magnolia documentation for installation instructions specific to your environment.");
    }
    return realPath;
}

From source file:gov.nih.nci.cabig.caaers.web.admin.AgentImporter.java

/**
* This method accepts a String which should be like 
* "723227","(161-180)ESO-1 Peptide" /*from ww w.  j  a va 2 s  . c o  m*/
* It splits the string into 2 tokens and creates a Agent object.
* If the number of token are less than 2 the record/line is rejected.
* @param agentString
* @param lineNumber
* @return
*/
protected DomainObjectImportOutcome<Agent> processAgent(String agentString, int lineNumber) {

    DomainObjectImportOutcome<Agent> agentImportOutcome = null;
    Agent agent = null;
    StringTokenizer st = null;
    String nscNumber;
    String agentName;

    if (StringUtils.isNotEmpty(agentString)) {

        logger.debug("Orginial line from file -- >>> " + agentString);
        agentString = agentString.trim();
        //Replace ", with "|
        //This is done to set a delimiter other than ,
        agentString = StringUtils.replace(agentString, "\",", "\"|");
        logger.debug("Modified line -- >>> " + agentString);
        //Generate tokens from input String.
        st = new StringTokenizer(agentString, "|");

        //If there are 2 tokens as expected, process the record. Create a Agent object.
        if (st.hasMoreTokens() && st.countTokens() == 2) {
            agentImportOutcome = new DomainObjectImportOutcome<Agent>();
            agent = new Agent();

            nscNumber = StringUtils.removeStart(st.nextToken(), "\"").trim();
            nscNumber = StringUtils.removeEnd(nscNumber, "\"");
            agentName = StringUtils.removeStart(st.nextToken(), "\"").trim();
            agentName = StringUtils.removeEnd(agentName, "\"");

            agent.setNscNumber(nscNumber);
            agent.setName(agentName);

            agentImportOutcome.setImportedDomainObject(agent);
            agentImportOutcome.setSavable(Boolean.TRUE);

        } else {
            logger.debug("Error in record -- >>> " + agentString);
            agentImportOutcome = new DomainObjectImportOutcome<Agent>();
            StringBuilder msgBuilder = new StringBuilder("Invalid agent record found at line ::: ");
            msgBuilder.append(lineNumber);
            agentImportOutcome.addErrorMessage(msgBuilder.toString(), Severity.ERROR);
        }
    }
    return agentImportOutcome;
}

From source file:ips1ap101.lib.core.db.util.InterpreteSqlOracle.java

@Override
public String getComandoExecute(String comando, int argumentos, EnumTipoResultadoSQL tipoResultado) {
    String command = StringUtils.stripToNull(comando);
    if (command != null) {
        String prefix;/*from  w  w  w. j ava  2 s .  c om*/
        String suffix;
        switch (tipoResultado) {
        case COMPOUND:
            prefix = COMANDO_EXECUTE_COMPUESTO;
            suffix = FIN_COMANDO_EXECUTE_COMPUESTO;
            break;
        case SIMPLE:
            prefix = COMANDO_EXECUTE_SIMPLE;
            suffix = FIN_COMANDO_EXECUTE_SIMPLE;
            break;
        default:
            prefix = COMANDO_EXECUTE;
            suffix = FIN_COMANDO_EXECUTE;
            break;
        }
        if (!StringUtils.startsWithIgnoreCase(command, prefix)) {
            command = prefix + " " + command;
        }
        String parametros = "";
        if (argumentos > 0) {
            for (int i = 0; i < argumentos; i++, parametros += ",?") {
            }
            parametros = "(" + parametros.substring(1) + ")";
        }
        if (!command.endsWith(";")) {
            if (!command.endsWith(parametros)) {
                command += parametros;
            }
            if (!command.endsWith(suffix)) {
                command += " " + suffix;
            }
        }
        command = StringUtils.removeEnd(command, ";");
        //          command = "{" + command + "}";
    }
    return command;
}

From source file:adalid.util.sql.SqlRoutineParameter.java

private String remove(String name, String table) {
    return StringUtils.removeStart(StringUtils.removeEnd(name, "_" + table), table + "_");
}

From source file:com.norconex.collector.http.robot.impl.DefaultRobotsTxtProvider.java

private String getBaseURL(String url) {
    String baseURL = url.replaceFirst("(.*?://.*?/)(.*)", "$1");
    if (baseURL.endsWith("/")) {
        baseURL = StringUtils.removeEnd(baseURL, "/");
    }/*from w ww .java2s.c  o  m*/
    return baseURL;
}

From source file:com.egt.core.db.util.InterpreteSqlOracle.java

@Override
public String getComandoExecute(String comando, int argumentos, EnumTipoResultadoSQL tipoResultado) {
    String command = StringUtils.stripToNull(comando);
    if (command != null) {
        String prefix;// w ww . j  ava 2  s . com
        String suffix;
        switch (tipoResultado) {
        case COMPUESTO:
            prefix = COMANDO_EXECUTE_COMPUESTO;
            suffix = FIN_COMANDO_EXECUTE_COMPUESTO;
            break;
        case SIMPLE:
            prefix = COMANDO_EXECUTE_SIMPLE;
            suffix = FIN_COMANDO_EXECUTE_SIMPLE;
            break;
        default:
            prefix = COMANDO_EXECUTE;
            suffix = FIN_COMANDO_EXECUTE;
            break;
        }
        if (!StringUtils.startsWithIgnoreCase(command, prefix)) {
            command = prefix + " " + command;
        }
        String parametros = "";
        if (argumentos > 0) {
            for (int i = 0; i < argumentos; i++, parametros += ",?") {
            }
            parametros = "(" + parametros.substring(1) + ")";
        }
        if (!command.endsWith(";")) {
            if (!command.endsWith(parametros)) {
                command += parametros;
            }
            if (!command.endsWith(suffix)) {
                command += " " + suffix;
            }
        }
        command = StringUtils.removeEnd(command, ";");
        //          command = "{" + command + "}";
    }
    return command;
}

From source file:net.bpelunit.framework.control.ws.WebServiceHandler.java

/**
 * Find the partner name in the incoming request URI. Is supposed to be the
 * last segment of the path URI.//  w  w  w  .  j a v a 2  s.c  o  m
 * 
 * @param path
 * @return
 */
private static String getPartnerName(String path) {

    String stringToTest = path;

    // Remove trailing slash, if any.
    stringToTest = StringUtils.removeEnd(stringToTest, "/");
    // Get last part of the URL.
    stringToTest = StringUtils.substringAfterLast(stringToTest, "/");
    return stringToTest;
}

From source file:com.tlabs.eve.HttpClientTest.java

protected String get(String url, final List<NameValuePair> parameters) {
    String printurl = (parameters.size() == 0) ? url : url + "?";
    for (NameValuePair pair : parameters) {
        printurl = printurl + pair.getName() + "=" + pair.getValue() + "&";
    }//w w  w .  j av a  2s. com
    printurl = StringUtils.removeEnd(printurl, "&");

    HttpClient httpclient = new DefaultHttpClient(connectionManager);
    try {
        HttpGet get = new HttpGet(printurl);
        return httpclient.execute(get, new BasicResponseHandler());
    } catch (Exception e) {
        e.printStackTrace(System.err);
        //fail(e.getLocalizedMessage());
        return null;
        //throw e;
    }
}