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:com.dp2345.plugin.oss.OssPlugin.java

@Override
public void upload(String path, File file, String contentType) {
    PluginConfig pluginConfig = getPluginConfig();
    if (pluginConfig != null) {
        String accessId = pluginConfig.getAttribute("accessId");
        String accessKey = pluginConfig.getAttribute("accessKey");
        String bucketName = pluginConfig.getAttribute("bucketName");
        InputStream inputStream = null;
        try {/*from  www.  j a  va2 s .  co  m*/
            inputStream = new FileInputStream(file);
            OSSClient ossClient = new OSSClient(accessId, accessKey);
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setContentType(contentType);
            objectMetadata.setContentLength(file.length());
            ossClient.putObject(bucketName, StringUtils.removeStart(path, "/"), inputStream, objectMetadata);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }
}

From source file:com.intuit.tank.common.ScriptUtil.java

public static List<ScriptAssignment> getAssignments(ScriptStep step) {
    List<ScriptAssignment> ret = new ArrayList<ScriptAssignment>();
    if (step.getType().equals("request")) {
        for (RequestData rd : step.getResponseData()) {
            if (StringUtils.isNotBlank(rd.getKey())) {
                if (StringUtils.containsIgnoreCase(rd.getType(), "assignment")) {
                    ret.add(new ScriptAssignment(rd.getKey().trim(),
                            StringUtils.removeStart(StringUtils.trim(rd.getValue()), "="),
                            step.getStepIndex()));
                }//from w  w w.j a va  2 s  .  c o m
            }
        }
    }
    return ret;
}

From source file:com.adobe.acs.commons.workflow.bulk.impl.servlets.StartServlet.java

@Override
protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");

    try {/*from www.j  a  v a  2s.  c om*/
        final JSONObject params = new JSONObject(request.getParameter("params"));
        final ValueMap map = new ValueMapDecorator(new HashMap<String, Object>());

        map.put(BulkWorkflowEngine.KEY_QUERY, params.getString(BulkWorkflowEngine.KEY_QUERY));

        map.put(BulkWorkflowEngine.KEY_RELATIVE_PATH,
                StringUtils.removeStart(params.optString(BulkWorkflowEngine.KEY_RELATIVE_PATH, ""), "/"));

        map.put(BulkWorkflowEngine.KEY_WORKFLOW_MODEL, params.getString(BulkWorkflowEngine.KEY_WORKFLOW_MODEL));

        map.put(BulkWorkflowEngine.KEY_BATCH_SIZE,
                params.optInt(BulkWorkflowEngine.KEY_BATCH_SIZE, BulkWorkflowEngine.DEFAULT_BATCH_SIZE));

        map.put(BulkWorkflowEngine.KEY_INTERVAL,
                params.optInt(BulkWorkflowEngine.KEY_INTERVAL, BulkWorkflowEngine.DEFAULT_INTERVAL));

        map.put(BulkWorkflowEngine.KEY_BATCH_TIMEOUT,
                params.optInt(BulkWorkflowEngine.KEY_BATCH_TIMEOUT, BulkWorkflowEngine.DEFAULT_BATCH_TIMEOUT));

        map.put(BulkWorkflowEngine.KEY_ESTIMATED_TOTAL, params.optLong(BulkWorkflowEngine.KEY_ESTIMATED_TOTAL,
                BulkWorkflowEngine.DEFAULT_ESTIMATED_TOTAL));

        map.put(BulkWorkflowEngine.KEY_PURGE_WORKFLOW, params.optBoolean(BulkWorkflowEngine.KEY_PURGE_WORKFLOW,
                BulkWorkflowEngine.DEFAULT_PURGE_WORKFLOW));

        bulkWorkflowEngine.initialize(request.getResource(), map);
        bulkWorkflowEngine.start(request.getResource());

        response.sendRedirect(
                request.getResourceResolver().map(request, request.getResource().getPath()) + ".status.json");

    } catch (JSONException e) {
        log.error("Could not parse HTTP Request params: {}", e);

        HttpErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Could not initialize Bulk Workflow due to invalid parameters."
                        + " Please review the form and try again.",
                e.getMessage());
    } catch (RepositoryException e) {
        log.error("Could not initialize Bulk Workflow: {}", e);

        HttpErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Could not initialize Bulk Workflow.", e.getMessage());

    } catch (IllegalArgumentException e) {
        log.warn("Could not initialize Bulk Workflow due to invalid arguments: {}", e);

        HttpErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Could not initialize Bulk Workflow due to invalid arguments.", e.getMessage());

    } catch (Exception e) {
        log.error("Could not initialize Bulk Workflow due to unexpected error: {}", e);

        HttpErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Could not start Bulk Workflow.", e.getMessage());
    }
}

From source file:com.ewcms.content.resource.service.operator.FileOperator.java

/**
 * ?//w  w w.j ava 2  s .c  om
 * 
 * @param uri ?
 * @return
 */
private File getLocalFile(String uri) {
    String root = rootDirPath;
    root = StringUtils.removeStart(root, "/");
    root = StringUtils.removeEnd(root, "/");
    String path = StringUtils.isBlank(root) ? uri : ("/" + root + uri);
    logger.debug("Resource path is {}", path);
    return new File(path);
}

From source file:com.mmounirou.spotirss.spotify.tracks.XTracks.java

private String cleanTrackName(String trackName) {
    String[] spotifyExtensions = new String[] { " - Explicit Version", " - Live", " - Radio Edit" };
    String strSong = trackName;//from   w w w  .  ja v  a 2 s  .  com

    for (String extensions : spotifyExtensions) {
        if (StringUtils.contains(strSong, extensions)) {
            strSong = "X " + StringUtils.remove(trackName, extensions);
        }
    }

    String[] braces = { "[]", "()" };

    for (String brace : braces) {

        String extendedinfo = null;
        do {
            extendedinfo = StringUtils.defaultString(
                    StringUtils.substringBetween(strSong, brace.charAt(0) + "", brace.charAt(1) + ""));
            if (StringUtils.isNotBlank(extendedinfo)) {
                if (StringUtils.startsWith(extendedinfo, "feat.")) {
                    String strArtist = StringUtils.removeStart("feat.", extendedinfo);
                    strSong = StringUtils.replace(strSong,
                            String.format("%c%s%c", brace.charAt(0), extendedinfo, brace.charAt(1)), "");
                    m_artistsInTrackName.addAll(cleanArtist(strArtist));
                }

                else {
                    strSong = StringUtils.replace(strSong,
                            String.format("%c%s%c", brace.charAt(0), extendedinfo, brace.charAt(1)), "");
                    strSong = "X " + strSong;
                }
            }

        } while (StringUtils.isNotBlank(extendedinfo));

    }

    String[] strSongSplitted = strSong.split("featuring");
    if (strSongSplitted.length > 1) {
        strSong = strSongSplitted[0];
        m_artistsInTrackName.add(strSongSplitted[1]);
    }

    String[] strSongWithFeaturing = strSong.split("-");
    if (strSongWithFeaturing.length > 1 && strSongWithFeaturing[1].contains("feat.")) {
        strSong = strSongWithFeaturing[0];
        m_artistsInTrackName.addAll(cleanArtist(StringUtils.remove(strSongWithFeaturing[1], "feat.")));
    } else {
        strSongWithFeaturing = strSong.split("feat.");
        if (strSongWithFeaturing.length > 1) {
            strSong = strSongWithFeaturing[0];
            m_artistsInTrackName.addAll(cleanArtist(strSongWithFeaturing[1]));
        }
    }

    return strSong.trim().toLowerCase();
}

From source file:com.microsoft.alm.plugin.external.commands.ResolveConflictsCommand.java

/**
 * Outputs the resolved conflicts in the following format:
 * <p/>/*from   w  ww. ja v  a2s  .  co m*/
 * Resolved /Users/leantk/tfvc-tfs/tfsTest_01/TestAdd.txt as KeepYours
 * Resolved /Users/leantk/tfvc-tfs/tfsTest_01/addFold/testHere2 as KeepYours
 *
 * @param stdout
 * @param stderr
 * @return
 */
@Override
public List<Conflict> parseOutput(final String stdout, final String stderr) {
    throwIfError(stderr);

    final List<Conflict> resolved = new ArrayList<Conflict>();
    final String[] lines = getLines(stdout);
    for (String line : lines) {
        if (StringUtils.startsWith(line, RESOLVED_PREFIX)) {
            line = StringUtils.removeStart(line, RESOLVED_PREFIX);
            final int index = line.indexOf(RESOLVED_POST_MSG);
            if (index != -1) {
                resolved.add(new Conflict(line.substring(0, index), Conflict.ConflictType.RESOLVED));
            }
        }
    }

    return resolved;
}

From source file:de.shadowhunt.maven.plugins.packageinfo.PackageInfoPlugin.java

static String toRelativePath(final File root, final File file) {
    final String rootPath = root.getAbsolutePath();
    final String filePath = file.getAbsolutePath();
    final String withoutPrefix = StringUtils.removeStart(filePath, rootPath);
    return StringUtils.removeStart(withoutPrefix, File.separator);
}

From source file:info.magnolia.module.workflow.MgnlParticipant.java

/**
 * @see openwfe.org.embed.engine.EmbeddedParticipant#consume(openwfe.org.engine.workitem.WorkItem)
 *//*from  ww w .  java  2s  .  co  m*/
public void consume(WorkItem wi) throws Exception {

    // get participant name
    if (log.isDebugEnabled()) {
        log.debug("enter consume()..");
    }
    if (wi == null) {
        log.error("work item is null");
        return;
    }
    String parName = ((InFlowWorkItem) (wi)).getParticipantName();
    if (log.isDebugEnabled()) {
        log.debug("participant name = " + parName);
    }
    if (parName.startsWith(WorkflowConstants.PARTICIPANT_PREFIX_COMMAND)) // handle commands
    {
        log.info("consume command " + parName + "...");
        if (log.isDebugEnabled()) {
            log.debug("command name is " + parName);
        }

        try {
            String name = StringUtils.removeStart(parName, WorkflowConstants.PARTICIPANT_PREFIX_COMMAND);
            Command c = CommandsManager.getInstance().getCommand(name);
            if (c != null) {
                log.info("Command has been found through the magnolia catalog:" + c.getClass().getName());

                // set parameters in the context
                Context context = MgnlContext.getInstance();

                context = new WorkItemContext(context, wi);

                // execute
                c.execute(context);

                WorkflowModule.getEngine().reply((InFlowWorkItem) wi);

            } else {
                // not found, do in the old ways
                log.error("No command has been found through the magnolia catalog for name:" + parName);
            }

            log.info("consume command " + parName + " end.");
        } catch (Exception e) {
            log.error("consume command failed", e);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("storage = " + this.storage);
        }
        this.storage.storeWorkItem("", (InFlowWorkItem) wi);
    }

    if (log.isDebugEnabled()) {
        log.debug("leave consume()..");
    }

}

From source file:hudson.plugins.clearcase.ucm.model.UcmSelector.java

protected void init(String selector) {
    Validate.notNull(selector);//  ww  w .  j  a  v  a 2 s  . c o  m
    String simpleSelector = StringUtils.removeStart(selector, getPrefix());
    if (simpleSelector.contains(":"))
        throw new IllegalArgumentException(
                "Selector " + simpleSelector + " doesn't match the current class " + getClass().getName());
    String[] split = simpleSelector.split("@");
    name = split[0];
    if (split.length > 1) {
        pvob = split[1];
    }
}

From source file:com.google.dart.tools.designer.model.HtmlRenderHelper.java

/**
 * @return the image of given HTML content, may be <code>null</code>.
 *///from w ww  .j av a 2 s  .  c  om
public static Image renderImage(final String content) {
    try {
        File tempFile = File.createTempFile("htmlRender", ".html");
        try {
            IOUtils2.writeBytes(tempFile, content.getBytes());
            // start DumpRenderTree
            if (processOutputStream == null) {
                String path;
                {
                    Bundle bundle = DartDesignerPlugin.getDefault().getBundle();
                    URL url = bundle.getEntry("lib/DumpRenderTree.app/Contents/MacOS/DumpRenderTree");
                    path = FileLocator.toFileURL(url).getPath();
                }
                //        ProcessBuilder builder = new ProcessBuilder(path, "-p", tempFile.getAbsolutePath());
                ProcessBuilder builder = new ProcessBuilder(path, "-p", "-");
                builder.redirectErrorStream(true);
                Process process = builder.start();
                processOutputStream = process.getOutputStream();
                processInputStream = process.getInputStream();
                processReader = new BufferedReader(new InputStreamReader(processInputStream));
            }
            long start = System.nanoTime();
            // XXX
            //        processOutputStream.write((tempFile.getAbsolutePath() + "\n").getBytes());
            processOutputStream
                    .write(("http://127.0.0.1:3030/Users/scheglov/dart/dwc_first/web/out/dwc_first.html\n")
                            .getBytes());
            processOutputStream.flush();
            // read tree
            while (true) {
                String line = processReader.readLine();
                System.out.println(line);
                if (line.isEmpty()) {
                    break;
                }
            }
            // read image
            {
                processReader.readLine(); // ActualHash:
                processReader.readLine(); // Content-Type: image/png
                String lengthLine = processReader.readLine(); // Content-Length: 5546
                int pngLength = Integer.parseInt(StringUtils.removeStart(lengthLine, "Content-Length: "));
                //          System.out.println("pngLength: " + pngLength);
                char[] pngChars = new char[pngLength];
                readFully(processReader, pngChars);
                byte[] pngBytes = new String(pngChars).getBytes();
                Image image = new Image(null, new ByteArrayInputStream(pngBytes));
                System.out.println("imageTime: " + (System.nanoTime() - start) / 1000000.0);
                return image;
            }
            //
            //        {
            //          SessionInputBuffer buffer = new AbstractSessionInputBuffer() {
            //            {
            //              init(processInputStream, 1024, new BasicHttpParams());
            //            }
            //
            //            @Override
            //            public boolean isDataAvailable(int timeout) throws IOException {
            //              return false;
            //            }
            //          };
            //          LineParser lineParser = new BasicLineParser(new ProtocolVersion("HTTP", 1, 1));
            //          HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(
            //              buffer,
            //              lineParser,
            //              new DefaultHttpResponseFactory(),
            //              new BasicHttpParams());
            //          HttpResponse response = parser.parse();
            //          System.out.println(response);
            //          HttpParams params = new BasicHttpParams();
            //          SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
            //          HttpMessageParser<BasicHttpResponse> parser = new DefaultResponseParser(
            //              inbuffer,
            //              BasicLineParser.DEFAULT,
            //              new DefaultHttpResponseFactory(),
            //              params);
            //
            //          HttpResponse response = parser.parse();
            //        }
            //        while (true) {
            //          String line = processReader.readLine();
            //          System.out.println(line);
            //        }
            //
            //        byte[] bytes = IOUtils2.readBytes(processInputStream);
            //        int exitValue = process.exitValue();
            //        System.out.println("bytes: " + bytes.length);
            //        System.out.println("bytesTime: " + (System.nanoTime() - start) / 1000000.0);
            //        String output = new String(bytes);
            //        System.out.println(StringUtils.substring(output, -10, 0));
            ////        System.out.println(output);
            //        //
            //        int pngOffset = output.indexOf("Content-Type: image/png");
            //        pngOffset = output.indexOf('\n', pngOffset) + 1;
            //        pngOffset = output.indexOf('\n', pngOffset) + 1;
            //        Image image = new Image(null, new ByteArrayInputStream(bytes, pngOffset, bytes.length
            //            - pngOffset));
            //        System.out.println("imageTime: " + (System.nanoTime() - start) / 1000000.0);
            //        return image;
        } finally {
            tempFile.delete();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return null;
}