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

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

Introduction

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

Prototype

public static String removeStart(final String str, final String remove) 

Source Link

Document

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

A null source string will return null .

Usage

From source file:org.eclipse.recommenders.utils.Names.java

/**
 * Takes a (dot-based) type descriptor as used in JDT completion proposals
 * and returns a standardized VM type descriptor.
 * //from   w w w.j  av a2s .c om
 * @see #src2vmType(String)
 */
public static String jdt2vmType(String jdtTypeDescriptor) {
    ensureIsNotNull(jdtTypeDescriptor, "jdtTypeDescriptor");
    String tmp = jdtTypeDescriptor;
    if (tmp.endsWith(";")) {
        tmp = StringUtils.removeStart(tmp, "L");
        tmp = StringUtils.removeEnd(tmp, ";");
    }
    return src2vmType(tmp);
}

From source file:org.eclipse.recommenders.utils.Zips.java

/**
 * Creates a standard path for the given type name. Package names are
 * replaced by "/". The final name is constructed as follows:
 * "<package≶/<className≶<extension≶
 * <p>// w  w  w  . j ava 2s .co  m
 * Note: if the path should contain a "." before the extension, it needs to
 * be specified in the extension (e.g., by specifying ".json" instead of
 * just using "json").
 */
public static String path(ITypeName type, @Nullable String suffix) {
    String name = StringUtils.removeStart(type.getIdentifier(), "L");
    return suffix == null ? name : name + suffix;
}

From source file:org.jamwiki.servlets.UploadServlet.java

/**
 *
 *///  www. j a v a 2 s  .  c o m
private String processDestinationFilename(String virtualWiki, String destinationFilename, String filename) {
    if (StringUtils.isBlank(destinationFilename)) {
        return destinationFilename;
    }
    if (!StringUtils.isBlank(FilenameUtils.getExtension(filename))
            && StringUtils.isBlank(FilenameUtils.getExtension(destinationFilename))) {
        // if original has an extension, the renamed version must as well
        destinationFilename += (!destinationFilename.endsWith(".") ? "." : "")
                + FilenameUtils.getExtension(filename);
    }
    // if the user entered a file name of the form "File:Foo.jpg" strip the namespace
    return StringUtils.removeStart(destinationFilename,
            Namespace.namespace(Namespace.FILE_ID).getLabel(virtualWiki) + Namespace.SEPARATOR);
}

From source file:org.jasig.cas.services.RegisteredServicePublicKeyImpl.java

@Override
public PublicKey createInstance() throws Exception {
    try {/*from  w w w  . ja v  a2 s.  c  o  m*/
        final PublicKeyFactoryBean factory = publicKeyFactoryBeanClass.newInstance();
        if (this.location.startsWith("classpath:")) {
            factory.setLocation(new ClassPathResource(StringUtils.removeStart(this.location, "classpath:")));
        } else {
            factory.setLocation(new FileSystemResource(this.location));
        }
        factory.setAlgorithm(this.algorithm);
        factory.setSingleton(false);
        return factory.getObject();
    } catch (final Exception e) {
        logger.warn(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:org.jinstagram.Instagram.java

/**
 * Get the next page of recent media objects from a previously executed request
 * @param pagination/*from  w  w  w  .  ja  v  a 2 s  .co m*/
 * @throws InstagramException
 */
public MediaFeed getRecentMediaNextPage(Pagination pagination) throws InstagramException {
    return createInstagramObject(Verbs.GET, MediaFeed.class,
            StringUtils.removeStart(pagination.getNextUrl(), Constants.API_URL), null);
}

From source file:org.jszip.rhino.OptimizeContextAction.java

public Object run(Context context) {
    context.setErrorReporter(new MavenLogErrorReporter(log));
    PseudoFileSystem fileSystem = new PseudoFileSystem(layers);
    context.putThreadLocal(Log.class, log);
    fileSystem.installInContext();/* w w  w.  java2 s . co m*/
    try {

        if (log.isDebugEnabled()) {
            log.debug("Virtual filesystem exposed to r.js:");
            Stack<Iterator<PseudoFile>> stack = new Stack<Iterator<PseudoFile>>();
            stack.push(Arrays.asList(fileSystem.root().listFiles()).iterator());
            while (!stack.isEmpty()) {
                Iterator<PseudoFile> iterator = stack.pop();
                while (iterator.hasNext()) {
                    PseudoFile f = iterator.next();
                    if (f.isFile()) {
                        log.debug("  " + f.getAbsolutePath() + " [file]");
                    } else {
                        log.debug("  " + f.getAbsolutePath() + " [dir]");
                        stack.push(iterator);
                        iterator = Arrays.asList(f.listFiles()).iterator();
                    }
                }
            }
        }

        List<String> argsList = new ArrayList<String>();
        argsList.add("-o");
        argsList.add("/build/" + profileJs.getName());
        String appDir = null;
        String baseUrl = "./";
        String dir = null;
        try {
            String profile = FileUtils.fileRead(profileJs, "UTF-8");
            Scriptable scope = context.newObject(global);
            scope.setPrototype(global);
            scope.setParentScope(null);
            Object parsedProfile = context.evaluateString(scope, profile, profileJs.getName(), 0, null);
            if (parsedProfile instanceof Scriptable) {
                final Scriptable scriptable = (Scriptable) parsedProfile;
                appDir = getStringWithDefault(scriptable, "appDir", null);
                baseUrl = getStringWithDefault(scriptable, "baseUrl", "./");
                dir = getStringWithDefault(scriptable, "dir", null);
            }
        } catch (IOException e) {
            log.debug("Cannot infer profile fixups", e);
        } catch (JavaScriptException e) {
            log.warn("JavaScript exception while parsing " + profileJs.getAbsolutePath() + ": " + e.details());
        } catch (Throwable e) {
            log.warn("Cannot infer if profile needs appDir and dir remapping to virtual directory structure",
                    e);
        }
        if (appDir == null) {
            argsList.add("appDir=/virtual/");
            argsList.add("baseUrl=" + baseUrl);
        } else if (!appDir.startsWith("/virtual/") && !appDir.equals("/virtual")) {
            argsList.add("appDir=/virtual/" + StringUtils.removeEnd(StringUtils.removeStart(appDir, "/"), "/")
                    + "/");
            argsList.add("baseUrl=" + baseUrl);
        }
        if (dir == null) {
            argsList.add("dir=/target/");
        } else if (!dir.startsWith("/target/") && !dir.equals("/target")) {
            argsList.add("dir=/target/" + StringUtils.removeEnd(StringUtils.removeStart(dir, "/"), "/") + "/");
        }

        global.defineFunctionProperties(new String[] { "print", "quit" }, GlobalFunctions.class,
                ScriptableObject.DONTENUM);

        Script script = context.compileString(source, "r.js", lineNo, null);
        script.getClass();

        Scriptable argsObj = context.newArray(global, argsList.toArray());
        global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);

        Scriptable scope = GlobalFunctions.createPseudoFileSystemScope(global, context);

        log.info("Applying r.js profile " + profileJs.getPath());
        log.debug("Executing r.js with arguments: " + StringUtils.join(argsList, " "));
        GlobalFunctions.setExitCode(0);
        script.exec(context, scope);
        return GlobalFunctions.getExitCode();
    } finally {
        fileSystem.removeFromContext();
        context.putThreadLocal(OptimizeContextAction.class, null);
    }
}

From source file:org.junit.extensions.dynamicsuite.engine.DirectoryScanner.java

protected String extractClassName(String basePath, String classFileName) {
    String className = classFileName;
    className = StringUtils.removeStart(className, basePath);
    className = StringUtils.removeStart(className, File.separator);
    className = StringUtils.removeEnd(className, CLASS_ENDING);
    className = StringUtils.removeEnd(className, SOURCE_ENDING);
    className = StringUtils.replace(className, File.separator, ".");
    return className;
}

From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.MappingData.java

private IStatus readMapping(final Object key, final String filename) {
    final IStatusCollector log = new StatusCollector(KalypsoUIRRMPlugin.getID());

    final Map<String, TimeseriesIndexEntry> mappings = new HashMap<>();
    m_mappings.put(key, mappings);//from  w w  w  . ja  v a 2s  . com

    try {
        final IPath observationConfPath = new Path(INaProjectConstants.PATH_OBSERVATION_CONF);

        final File mappingSourceFolder = new File(m_sourceProjectDir, observationConfPath.toOSString());
        final File mappingSourceFile = new File(mappingSourceFolder, filename);

        final GMLWorkspace mappingWorkspace = GmlSerializer.createGMLWorkspace(mappingSourceFile,
                GmlSerializer.DEFAULT_FACTORY);
        final Feature rootFeature = mappingWorkspace.getRootFeature();
        final FeatureList mappingList = (FeatureList) rootFeature
                .getProperty(DeegreeUrlCatalog.RESULT_LIST_PROP);
        for (final Object object : mappingList) {
            final Feature feature = (Feature) object;
            final ZmlLink oldLink = new ZmlLink(feature, DeegreeUrlCatalog.RESULT_TS_IN_PROP);

            final String name = feature.getName();
            final String href = oldLink.getHref();
            final String projectRelativeHref = StringUtils.removeStart(href,
                    UrlResolver.PROJECT_PROTOCOLL + "/"); //$NON-NLS-1$

            if (!StringUtils.isBlank(href)) {
                final TimeseriesIndexEntry entry = m_timeseriesIndex
                        .findTimeseriesByOldHref(projectRelativeHref);
                mappings.put(name, entry);
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
        log.add(IStatus.WARNING, Messages.getString("ObservationconfConverter_3"), e, filename); //$NON-NLS-1$
    }

    final String msg = String.format(Messages.getString("ObservationconfConverter_4"), filename); //$NON-NLS-1$
    return log.asMultiStatus(msg);
}

From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.MappingData.java

@SuppressWarnings("deprecation")
private IStatus readOmrbometer(final Object key, final String filename) {
    final IStatusCollector log = new StatusCollector(KalypsoUIRRMPlugin.getID());

    final Map<String, TimeseriesIndexEntry> mappings = new HashMap<>();
    m_mappings.put(key, mappings);/*from w  w w  .  j a  v  a2s .  c o  m*/

    final QName collectionMemberName = new QName(NaModelConstants.NS_OMBROMETER, "ombrometerMember"); //$NON-NLS-1$
    final QName timeseriesPropertyName = new QName(NaModelConstants.NS_OMBROMETER, "NRepository"); //$NON-NLS-1$

    try {
        final IPath observationConfPath = new Path(INaProjectConstants.PATH_OBSERVATION_CONF);

        final File mappingSourceFolder = new File(m_sourceProjectDir, observationConfPath.toOSString());
        final File mappingSourceFile = new File(mappingSourceFolder, filename);

        final GMLWorkspace mappingWorkspace = GmlSerializer.createGMLWorkspace(mappingSourceFile,
                GmlSerializer.DEFAULT_FACTORY);
        final Feature rootFeature = mappingWorkspace.getRootFeature();

        final FeatureList mappingList = (FeatureList) rootFeature.getProperty(collectionMemberName);
        for (final Object object : mappingList) {
            final Feature feature = (Feature) object;
            final ZmlLink oldLink = new ZmlLink(feature, timeseriesPropertyName);

            final String name = feature.getName();
            final String href = oldLink.getHref();
            final String projectRelativeHref = StringUtils.removeStart(href,
                    UrlResolver.PROJECT_PROTOCOLL + "/"); //$NON-NLS-1$

            if (!StringUtils.isBlank(href)) {
                final TimeseriesIndexEntry entry = m_timeseriesIndex
                        .findTimeseriesByOldHref(projectRelativeHref);
                mappings.put(name, entry);
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
        log.add(IStatus.WARNING, Messages.getString("ObservationconfConverter_3"), e, filename); //$NON-NLS-1$
    }

    final String msg = String.format(Messages.getString("ObservationconfConverter_4"), filename); //$NON-NLS-1$
    return log.asMultiStatus(msg);
}

From source file:org.ligoj.app.http.proxy.HtmlProxyFilter.java

/**
 * Return the base name of resource from the request.
 *///from w ww  . j  av  a 2 s . com
private String getBaseName(final ServletRequest request) {
    final String servletPath = ((HttpServletRequest) request).getServletPath();
    final String base = StringUtils.removeStart(servletPath, "/");
    return getBaseName(base.isEmpty() ? "index.html" : base);
}