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

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

Introduction

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

Prototype

public static String substringBeforeLast(String str, String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:info.magnolia.cms.beans.runtime.Document.java

/**
 * Used to create a document pased on a existing file.
 * @param file/*from  ww  w  . j a  v a  2 s.  c om*/
 * @param type
 */
public Document(java.io.File file, String type) {
    String fileName = file.getName();
    this.setFile(file);
    this.setType(type);
    this.setExtention(StringUtils.substringAfterLast(fileName, "."));
    this.setFileName(StringUtils.substringBeforeLast(fileName, "."));
}

From source file:biz.netcentric.cq.tools.actool.helper.InitialContentHelper.java

private static boolean createPathWithInitialContent(final Session session, String path, String initialContent,
        AcInstallationHistoryPojo history)
        throws RepositoryException, PathNotFoundException, ItemExistsException, ConstraintViolationException,
        VersionException, InvalidSerializedDataException, LockException, AccessDeniedException {
    String parentPath = StringUtils.substringBeforeLast(path, "/");
    try {//from   w ww  .ja  va2 s  .  co  m
        session.getNode(parentPath);
    } catch (PathNotFoundException e) {
        history.addWarning("Skipped installing initial content for path " + path + " since parent " + parentPath
                + " does not exist");
        return false;
    }

    String rootElementStr = "<jcr:root ";
    if (!initialContent.contains(rootElementStr)) {
        throw new IllegalStateException("Invalid initial content for path " + path + ": " + rootElementStr
                + " must be provided as root element in XML");
    }
    String initialContentAdjusted = initialContent;
    if (!initialContentAdjusted.contains("xmlns:cq")) {
        initialContentAdjusted = initialContentAdjusted.replace(rootElementStr,
                rootElementStr + " xmlns:cq=\"http://www.day.com/jcr/cq/1.0\" ");
    }
    if (!initialContentAdjusted.contains("xmlns:jcr")) {
        initialContentAdjusted = initialContentAdjusted.replace(rootElementStr,
                rootElementStr + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" ");
    }
    if (!initialContentAdjusted.contains("xmlns:sling")) {
        initialContentAdjusted = initialContentAdjusted.replace(rootElementStr,
                rootElementStr + " xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" ");
    }

    String nodeName = StringUtils.substringAfterLast(path, "/");
    initialContentAdjusted = initialContentAdjusted.replace("jcr:root", nodeName);

    history.addVerboseMessage("Adding initial content for path " + path + "\n" + initialContentAdjusted);
    try {
        session.importXML(parentPath, new ByteArrayInputStream(initialContentAdjusted.getBytes()),
                ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);

        history.addMessage("Created initial content for path " + path);
    } catch (IOException e) {
        history.addWarning("Failed creating initial content for path " + path + ": " + e);
        return false;
    }
    return true;
}

From source file:edu.mayo.cts2.framework.plugin.service.lexevs.naming.VersionNameConverter.java

/**
 * From cts2 code system version name.//  w  ww  .ja va  2s.  c  o m
 *
 * @param cts2CodeSystemVersionName the cts2 code system version name
 * @return the name version pair
 * @throws InvaildVersionNameException 
 */
public NameVersionPair fromCts2VersionName(String cts2CodeSystemVersionName)
        throws InvaildVersionNameException {
    if (!this.isValidVersionName(cts2CodeSystemVersionName)) {
        throw new InvaildVersionNameException(cts2CodeSystemVersionName);
    }

    String version = StringUtils.substringAfterLast(cts2CodeSystemVersionName, SEPARATOR);
    String name = StringUtils.substringBeforeLast(cts2CodeSystemVersionName, SEPARATOR);

    return new NameVersionPair(this.codingSchemeNameTranslator.translateToLexGrid(name),
            this.unescapeVersion(version));
}

From source file:com.github.trask.sandbox.isolation.ClassLoaderExtension.java

Class<?> findClass(String name) throws ClassNotFoundException {
    if (bridgeInterface != null && bridgeInterface.getName().equals(name)) {
        return bridgeInterface;
    }/*from   ww w.  j a  v  a 2  s .c o m*/
    String resourceName = name.replace('.', '/') + ".class";
    InputStream input = extensibleClassLoader.getResourceAsStream(resourceName);
    if (input == null) {
        throw new ClassNotFoundException(name);
    }
    byte[] b;
    try {
        b = IOUtils.toByteArray(input);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    if (name.indexOf('.') != -1) {
        String packageName = StringUtils.substringBeforeLast(name, ".");
        extensibleClassLoader.createPackageIfNecessary(packageName);
    }
    try {
        return extensibleClassLoader.defineClass(name, b);
    } catch (IOException e) {
        throw new ClassNotFoundException(name, e);
    }
}

From source file:info.magnolia.nodebuilder.ContentOps.java

public static NodeOperation setBinaryNodeData(final String name, final String fileName, final long size,
        final InputStream inputStream) {
    return new AbstractNodeOperation() {

        @Override// ww  w  . ja  v a  2  s .  c  o  m
        protected Content doExec(Content context, ErrorHandler errorHandler) throws RepositoryException {
            NodeData binary = context.setNodeData(name, inputStream);
            binary.setAttribute(FileProperties.PROPERTY_FILENAME,
                    StringUtils.substringBeforeLast(fileName, "."));
            binary.setAttribute(FileProperties.PROPERTY_EXTENSION,
                    StringUtils.substringAfterLast(fileName, "."));
            binary.setAttribute(FileProperties.PROPERTY_SIZE, Long.toString(size));
            return context;
        }
    };
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResult.java

/**
 *
 * @param variableName/* w  w  w  .j av  a 2  s .c om*/
 * @param methodName
 * @param returnType
 */
public MemberLookupResult(String variableName, String methodName, String returnType) {
    this.variableName = variableName;
    this.methodName = methodName;

    //TODO: this is a hack to get support for list, set, map, enumeration, array and collection
    String tmp = returnType;
    if (StringUtils.startsWith(returnType, List.class.getName())
            || StringUtils.startsWith(returnType, Set.class.getName())
            || StringUtils.startsWith(returnType, Map.class.getName())
            || StringUtils.startsWith(returnType, Iterator.class.getName())
            || StringUtils.startsWith(returnType, Enum.class.getName())
            || StringUtils.startsWith(returnType, Collection.class.getName())) {
        while (StringUtils.contains(tmp, "<") && StringUtils.contains(tmp, ">")) {
            tmp = StringUtils.substringBetween(tmp, "<", ">");
        }
        if (StringUtils.contains(tmp, ",")) {
            // we want the first variable
            tmp = StringUtils.substringBefore(tmp, ",");
        }
    } else if (StringUtils.endsWith(returnType, "[]")) {
        tmp = StringUtils.substringBeforeLast(returnType, "[]");
    }

    this.returnType = tmp;
}

From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java

@SuppressWarnings("unchecked")
private static void autoconf(File tmp, String autoconfigPath, String autoconfigFile, PrintStream out)
        throws Exception {
    Enumeration<URL> urls = AntxconfigUtil.class.getClassLoader().getResources(autoconfigFile);
    for (; urls.hasMoreElements();) {
        URL url = urls.nextElement();
        // copy xml
        File autoconfFile = new File(tmp, autoconfigFile);
        writeUrlToFile(url, autoconfFile);
        // copy vm
        SAXBuilder b = new SAXBuilder();
        Document document = b.build(autoconfFile);
        List<Element> elements = XPath.selectNodes(document, GEN_PATH);
        for (Element element : elements) {
            String path = url.getPath();
            String vm = element.getAttributeValue("template");
            String vmPath = StringUtils.substringBeforeLast(path, "/") + "/" + vm;
            URL vmUrl = new URL(url.getProtocol(), url.getHost(), vmPath);
            File vmFile = new File(tmp, autoconfigPath + "/" + vm);
            writeUrlToFile(vmUrl, vmFile);
        }//from  ww w .j a  v a2  s  .  c  om
        // call antxconfig
        String args = "";
        if (new File(DEFAULT_ANTX_FILE).isFile()) {
            args = " -u " + DEFAULT_ANTX_FILE;
        }

        Process p = Runtime.getRuntime().exec(ANTXCONFIG_CMD + args, null, tmp);
        BufferedInputStream in = new BufferedInputStream(p.getInputStream());
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String s;
        while ((s = br.readLine()) != null) {
            out.println(new String(s.getBytes(), ENDODING));
        }
        FileUtils.deleteDirectory(new File(tmp, autoconfigPath));
    }
}

From source file:com.echosource.ada.core.AdaDirectory.java

/**
 * Match file pattern./*from   w w w . ja  v  a 2s .c om*/
 * 
 * @param antPattern
 *          the ant pattern
 * @return true, if match file pattern
 * @see org.sonar.api.resources.Resource#matchFilePattern(java.lang.String)
 */
@Override
public boolean matchFilePattern(String antPattern) {
    String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, ".");
    WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, ".");
    return matcher.match(getKey());
}

From source file:com.alibaba.cobar.client.router.DefaultCobarClientInternalRouter.java

public RoutingResult doRoute(IBatisRoutingFact routingFact) throws RoutingException {
    Validate.notNull(routingFact);//from   ww w .j  a  va 2s .com
    String action = routingFact.getAction();
    Validate.notEmpty(action);
    String namespace = StringUtils.substringBeforeLast(action, ".");
    List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> rules = getRulesGroupByNamespaces().get(namespace);

    RoutingResult result = new RoutingResult();
    result.setResourceIdentities(new ArrayList<String>());

    if (!CollectionUtils.isEmpty(rules)) {
        IRoutingRule<IBatisRoutingFact, List<String>> ruleToUse = null;
        for (Set<IRoutingRule<IBatisRoutingFact, List<String>>> ruleSet : rules) {
            ruleToUse = searchMatchedRuleAgainst(ruleSet, routingFact);
            if (ruleToUse != null) {
                break;
            }
        }

        if (ruleToUse != null) {
            logger.info("matched with rule:{} with fact:{}", ruleToUse, routingFact);
            result.getResourceIdentities().addAll(ruleToUse.action());
        } else {
            logger.info("No matched rule found for routing fact:{}", routingFact);
        }
    }

    return result;
}

From source file:info.magnolia.module.delta.BackupTask.java

/**
 * @param workspace the workspace that contains path
 * @param path the path to the node that is to be backed up.
 * @param info indicates if an info message should be displayed.
 *//*from ww w.  j  a v  a 2  s .co m*/
public BackupTask(String workspace, String path, boolean info) {
    super("Backup", "Does a backup of the node path '" + path + "' in the " + workspace + " workspace.");
    this.workspace = workspace;
    this.path = path;
    this.info = info;

    final String parentPath = StringUtils.substringBeforeLast(path, "/");
    final String backupParentPath = getBackupPath() + parentPath;
    this.backupPath = backupParentPath + "/" + StringUtils.substringAfterLast(path, "/");
    final CreateNodePathTask backupParent = new CreateNodePathTask("Create node",
            "Creates the " + path + " backup location.", workspace, backupParentPath);
    final MoveNodeTask moveNodeToBackupPath = new MoveNodeTask("Move node",
            "Moves " + path + " to the " + backupPath + " backup location.", workspace, path, backupPath, true);
    addTask(backupParent);
    addTask(moveNodeToBackupPath);
}