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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

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

Usage

From source file:info.magnolia.jcr.util.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>/some/path/node.prop</code> or
 * <code>/some/path/node.@type</code>.
 */// www  . jav a2s  .  c  o  m
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;
        // explicitly enforce certain syntax
        if (!orgKey.startsWith("/")) {
            throw new IllegalArgumentException("Missing trailing '/' for key: " + orgKey);
        }
        if (StringUtils.countMatches(orgKey, ".") > 1) {
            throw new IllegalArgumentException("Key must not contain more than one '.': " + orgKey);
        }
        if (orgKey.contains("@") && !orgKey.contains(".@")) {
            throw new IllegalArgumentException("Key containing '@' must be preceded by a '.': " + orgKey);
        }
        // if this is a node definition (no property)
        String newKey = orgKey;

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.removeStart(keySuffix, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + ".@type")) {
                    cleaned.put(path + ".@type", NodeTypes.ContentNode.NAME);
                }
                continue;
            }
            throw new IllegalArgumentException(
                    "Key for a path (everything without a '.' is considered to be a path) must not contain a value ('='): "
                            + orgKey);
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:hydrograph.ui.perspective.dialog.PreStartActivity.java

private static boolean checkJDKVersion(String jdkVersion, boolean showPopupAndExit) {
    jdkVersion = StringUtils.removeStart(jdkVersion, "jdk");
    jdkVersion = StringUtils.remove(jdkVersion, ".");
    jdkVersion = StringUtils.remove(jdkVersion, "_");
    long version = Long.parseLong(jdkVersion);
    if (version >= REQUIRED_JDK_VERSION) {
        return true;
    }//ww  w . j  av a  2 s. c  o m
    if (showPopupAndExit) {
        showInvalidJavaHomeDialogAndExit();
    }
    return false;
}

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:gobblin.compaction.dataset.TimeBasedSubDirDatasetsFinder.java

protected String getDatasetName(String path, String basePath) {
    int startPos = path.indexOf(basePath) + basePath.length();
    return StringUtils.removeStart(path.substring(startPos), "/");
}

From source file:com.egt.core.util.EA.java

private static void loadBootstrappingProperties() {
    Bitacora.trace(EA.class, "loadBootstrappingProperties");
    String key;/*from  w  w  w. j  a v a  2s.c  o m*/
    boolean ok = false;
    key = SEV.ENT_APP_BOOTSTRAPPING_PROPERTIES_FILE;
    bootstrapping_properties_file = System.getenv(key);
    if (StringUtils.isNotBlank(bootstrapping_properties_file)) {
        show(key, bootstrapping_properties_file);
        ok = isFile(bootstrapping_properties_file);
    }
    if (!ok) {
        key = SEV.ENT_APP_BOOTSTRAPPING_PROPERTIES_FILE.replace('_', '.').toLowerCase();
        bootstrapping_properties_file = System.getProperties().getProperty(key);
        if (StringUtils.isNotBlank(bootstrapping_properties_file)) {
            show(key, bootstrapping_properties_file);
            ok = isFile(bootstrapping_properties_file);
        }
    }
    if (!ok) {
        String sep = System.getProperties().getProperty("file.separator");
        String glassRoot = System.getProperties().getProperty("com.sun.aas.instanceRoot");
        String jbossBase = System.getProperties().getProperty("jboss.server.base.dir");
        String somedir = coalesceToUserDir(glassRoot, jbossBase);
        key = StringUtils.removeStart(SEV.ENT_APP_BOOTSTRAPPING_PROPERTIES_FILE, SEV.ENT_APP_VAR_PREFFIX);
        bootstrapping_properties_file = somedir + sep + lower_case_code + "." + "properties";
        show(key, bootstrapping_properties_file);
        ok = isFile(bootstrapping_properties_file);
    }
    bootstrapping = new Properties();
    if (ok) {
        try {
            try (FileInputStream inStream = new FileInputStream(bootstrapping_properties_file)) {
                bootstrapping.load(inStream);
            }
        } catch (Exception ex) {
            Bitacora.logFatal(ex);
        }
    }
    ok = !bootstrapping.isEmpty();
    if (ok) {
        showBootstrappingProperties();
    }
}

From source file:info.magnolia.cms.util.InheritanceContentWrapper.java

/**
 * This method returns null if no content has been found.
 *///from ww  w. ja v  a 2 s.com
protected Content getContentSafely(String name) throws RepositoryException {
    if (getWrappedContent().hasContent(name)) {
        return super.getContent(name);
    }

    String innerPath = resolveInnerPath() + "/" + name;
    innerPath = StringUtils.removeStart(innerPath, "/");

    Content inherited = getContentSafely(findNextAnchor(), innerPath);
    return inherited;
}

From source file:info.magnolia.importexport.BootstrapUtil.java

/**
 * I.e. given a resource path like <code>/mgnl-bootstrap/foo/config.server.i18n.xml</code> it will return <code>/server/i18n</code>.
 *///from w  w  w  .  j  ava  2  s.  co  m
public static String getFullpathFromResource(final String resourcePath) {
    String resourceName = StringUtils.replace(resourcePath, "\\", "/");

    String name = getFilenameFromResource(resourceName, ".xml");
    String fullPath = DataTransporter.revertExportPath(name);
    String repository = StringUtils.substringBefore(fullPath, "/");

    return StringUtils.removeStart(fullPath, repository);
}

From source file:com.github.ipaas.ideploy.agent.handler.RollbackCodeHandlerTest.java

/**
 * , USING_VERSION,? ROLLBACKTO_VERSION 
 * //from   www .  j  a va 2  s .c  o  m
 * @throws Exception
 */
@Test
public void rollbackCodeTest() throws Exception {
    String deployRoot = "/www/app" + APP_NAME;

    File usingfile = new File(deployRoot);

    RollbackCodeHandler rollback = new RollbackCodeHandler();

    String localBkPath = "/www/appbk" + APP_NAME + "/firstVer0";
    Map<String, Object> cantRollBackParams = new HashMap<String, Object>();
    cantRollBackParams.put("localBkPath", localBkPath);
    cantRollBackParams.put("deployPath", deployRoot);
    try {
        rollback.execute(null, null, cantRollBackParams, null); // :
        // ,?,?!
        fail("Created fraction 1/0! That's undefined!");
    } catch (Exception e) {
        assertEquals("?,?!", e.getMessage());
    }
    File localBkFile = new File(localBkPath);
    if (!localBkFile.exists()) {
        localBkFile.mkdirs();
    }
    rollback.execute(null, null, cantRollBackParams, null);

    Integer hostStatus4New = 1;
    String savePath = "/www/apptemp/" + USING_VERSION;
    Map<String, Object> firstRollbackParams = new HashMap<String, Object>();
    firstRollbackParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION);
    firstRollbackParams.put("hostStatus", hostStatus4New);
    firstRollbackParams.put("savePath", savePath);
    firstRollbackParams.put("deployPath", deployRoot);
    rollback.execute(null, null, firstRollbackParams, null); // ,,?

    DownloadCodeHandler downLoadHandler = new DownloadCodeHandler();
    Integer notUpdateAll = 2;
    Integer hostStatus4Old = 2;
    Map<String, Object> secondDownLoadParams = new HashMap<String, Object>();
    secondDownLoadParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + ROLLBACKTO_VERSION);
    secondDownLoadParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION);
    secondDownLoadParams.put("hostStatus", hostStatus4Old);
    secondDownLoadParams.put("savePath", "/www/apptemp/rollback_test_vaild");// ??
    secondDownLoadParams.put("updateAll", notUpdateAll);
    downLoadHandler.execute(null, null, secondDownLoadParams, null);
    File updateFile = new File("/www/apptemp/rollback_test_vaild/update.txt");
    List<String> updateList = FileUtils.readLines(updateFile);// ??,?

    String savePath2 = "/www/apptemp/" + ROLLBACKTO_VERSION;
    Map<String, Object> secondRollbackParams = new HashMap<String, Object>();
    secondRollbackParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + ROLLBACKTO_VERSION);
    secondRollbackParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION);
    secondRollbackParams.put("hostStatus", hostStatus4Old);
    secondRollbackParams.put("savePath", savePath2);
    secondRollbackParams.put("deployPath", deployRoot);
    rollback.execute(null, null, secondRollbackParams, null); // ,

    // ?
    for (String str : updateList) {
        if (str.startsWith("+")) {
            // 
            Assert.assertTrue(new File(deployRoot + StringUtils.removeStart(str, "+").trim()).exists());
        } else if (str.startsWith("-")) {
            // 
            String f = deployRoot + StringUtils.removeStart(str, "-").trim();
            Assert.assertFalse(new File(f).exists());
        }
    }

    FileUtils.cleanDirectory(usingfile);
    FileUtils.forceDelete(localBkFile);
    FileUtils.cleanDirectory(new File("/www/apptemp"));
}

From source file:info.magnolia.jcr.wrapper.InheritanceNodeWrapper.java

/**
 * Returns the inner path of the this node up to the anchor.
 *//* ww w .  j  ava 2  s . c om*/
protected String resolveInnerPath() throws RepositoryException {
    final String path;
    InheritanceNodeWrapper anchor = findAnchor();
    // if no anchor left we are relative to the root
    if (anchor == null) {
        path = this.getPath();
    } else {
        path = StringUtils.substringAfter(this.getPath(), anchor.getPath());
    }
    return StringUtils.removeStart(path, "/");
}

From source file:com.google.gdt.eclipse.designer.model.property.css.StylePropertyEditor.java

private static String extractStyleName(String selector) {
    return StringUtils.removeStart(selector, ".");
}