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

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

Introduction

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

Prototype

public static String stripStart(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the start of a String.

Usage

From source file:com.thoughtworks.gauge.scan.RegistryMethodVisitor.java

private String trimQuotes(String text) {
    return StringUtils.stripEnd(StringUtils.stripStart(text, "\""), "\"");
}

From source file:com.intellij.lang.jsgraphql.endpoint.doc.psi.JSGraphQLEndpointDocPsiUtil.java

/**
 * Gets the text of the continuous comments placed directly above the specified element
 * @param element element whose previous siblings are enumerated and included if they're documentation comments
 * @return the combined text of the documentation comments, preserving line breaks, or <code>null</code> if no documentation is available
 *//*from   w w w.  j  a  va  2 s .co  m*/
public static String getDocumentation(PsiElement element) {
    final PsiComment comment = PsiTreeUtil.getPrevSiblingOfType(element, PsiComment.class);
    if (isDocumentationComment(comment)) {
        final List<PsiComment> siblings = Lists.newArrayList(comment);
        getDocumentationCommentSiblings(comment, siblings, PsiElement::getPrevSibling);
        Collections.reverse(siblings);
        return siblings.stream().map(c -> StringUtils.stripStart(c.getText(), "# "))
                .collect(Collectors.joining("\n"));
    }
    return null;
}

From source file:com.intuit.tank.vm.common.util.JSONBuilder.java

private Object findValueOfType(String value) {
    if (StringUtils.isEmpty(value) || "null".equalsIgnoreCase(value)) {
        return JSONObject.NULL;
    }//w  w  w.  j av a 2 s .  c o m
    try {
        if (!value.startsWith("0")) {
            if (value.matches("^\\d*$")) {
                return Long.valueOf(value);
            }
            if (value.matches("^\\d*\\.\\d+")) {
                return Double.valueOf(value);
            }

            if (value.equalsIgnoreCase("true")) {
                return Boolean.TRUE;
            }
            if (value.equalsIgnoreCase("false")) {
                return Boolean.FALSE;
            }
        }
    } catch (NumberFormatException e) {
        LOG.warn("Error rying to parse a number  value: " + e);
    }
    // strip leading and trainling quotes
    value = StringUtils.stripEnd(value, "\"");
    value = StringUtils.stripStart(value, "\"");
    return value;
}

From source file:com.tupilabs.human_name_parser.HumanNameParserParser.java

/**
 * Combines a first initial and first name, e.g. "J. Edgar Hoover", would return "J. Edgar"
 *//*from  w  w  w  .j  a  va  2  s  .  c o m*/
public String getFullFirst() {
    return StringUtils.stripStart(getLeadingInit() + " " + getFirst(), null);
}

From source file:com.enonic.cms.upgrade.task.datasource.DataSourceConverterUpgradeModel206.java

private String getStrippedElExpression(String expression) {
    expression = StringUtils.stripStart(expression, "${");
    expression = StringUtils.stripEnd(expression, "}");
    return expression;
}

From source file:com.gs.obevo.db.apps.reveng.AbstractDdlReveng.java

private void revengMain(AquaRevengArgs args) {
    String schema = args.getDbSchema();
    File file = args.getInputPath();
    boolean generateBaseline = args.isGenerateBaseline();
    File outputDir = args.getOutputPath();

    MutableList<ChangeEntry> changeEntries = Lists.mutable.empty();

    final MutableList<String> dataLines;
    if (file.isFile()) {
        dataLines = FileUtilsCobra.readLines(file);
    } else {// w  w  w .  j av a2  s  . co  m
        dataLines = ArrayAdapter.adapt(file.listFiles()).select(new Predicate<File>() {
            @Override
            public boolean accept(File file) {
                return file.isFile();
            }
        }).flatCollect(new Function<File, Iterable<String>>() {
            @Override
            public Iterable<String> valueOf(File file) {
                return FileUtilsCobra.readLines(file);
            }
        });
    }

    dataLines.forEachWithIndex(new ObjectIntProcedure<String>() {
        @Override
        public void value(String line, int i) {
            if (line.startsWith("--------------------") && dataLines.get(i + 1).startsWith("-- DDL Statements")
                    && dataLines.get(i + 2).startsWith("--------------------")) {
                dataLines.set(i, "");
                dataLines.set(i + 1, "");
                dataLines.set(i + 2, "");
            } else if (line.startsWith("--------------------")
                    && dataLines.get(i + 2).startsWith("-- DDL Statements")
                    && dataLines.get(i + 4).startsWith("--------------------")) {
                dataLines.set(i, "");
                dataLines.set(i + 1, "");
                dataLines.set(i + 2, "");
                dataLines.set(i + 3, "");
                dataLines.set(i + 4, "");
            } else if (line.startsWith("-- DDL Statements for ")) {
                dataLines.set(i, "");
            }
        }
    });

    String data = dataLines.makeString(SystemUtils.LINE_SEPARATOR);

    MutableList<String> entries = stringSplitter.valueOf(data);

    String candidateObject = "UNKNOWN";
    ChangeType candidateObjectType = UnclassifiedChangeType.INSTANCE;

    int selfOrder = 0;
    int objectOrder = 0;

    // Find object names
    MutableSet<String> objectNames = Sets.mutable.empty();
    for (String candidateLine : entries) {
        candidateLine = StringUtils.stripStart(candidateLine, "\r\n \t");

        if (StringUtils.isNotBlank(candidateLine) && Predicates.noneOf(skipPredicates).accept(candidateLine)) {
            candidateLine = candidateLine.replaceAll(schema + "\\.dbo\\.", ""); // sybase ASE
            candidateLine = candidateLine.replaceAll("'dbo\\.", "'"); // sybase ASE
            candidateLine = candidateLine.replaceAll("\"" + schema + "\\s*\"\\.", ""); // DB2
            candidateLine = candidateLine.replaceAll(schema + "\\.", ""); // alternate DB2 for views
            candidateLine = removeQuotesFromProcxmode(candidateLine); // sybase ASE

            RevengPattern chosenRevengPattern = null;
            String secondaryName = null;
            for (RevengPattern revengPattern : revengPatterns) {
                RevengPatternOutput patternMatch = revengPattern.evaluate(candidateLine);
                if (patternMatch != null) {
                    System.out.println("OBJECT NAME " + patternMatch.getPrimaryName());
                    objectNames.add(patternMatch.getPrimaryName());
                    chosenRevengPattern = revengPattern;
                    candidateObject = patternMatch.getPrimaryName();
                    if (patternMatch.getSecondaryName() != null) {
                        secondaryName = patternMatch.getSecondaryName();
                    }
                    candidateObjectType = platform.getChangeType(revengPattern.getChangeType());
                    objectOrder = 0;
                    break;
                }
            }
        }
    }

    MutableMap<String, AtomicInteger> countByObject = Maps.mutable.empty();

    for (String candidateLine : entries) {
        try {

            candidateLine = StringUtils.stripStart(candidateLine, "\r\n \t");

            if (StringUtils.isNotBlank(candidateLine)
                    && Predicates.noneOf(skipPredicates).accept(candidateLine)) {
                for (String objectName : objectNames) {
                    candidateLine = candidateLine.replaceAll(schema + "\\s*\\." + objectName, objectName); // sybase ASE
                    candidateLine = candidateLine.replaceAll(
                            schema.toLowerCase() + "\\s*\\." + objectName.toLowerCase(),
                            objectName.toLowerCase()); // sybase ASE
                }
                candidateLine = candidateLine.replaceAll(schema + "\\.dbo\\.", ""); // sybase ASE
                candidateLine = candidateLine.replaceAll("'dbo\\.", "'"); // sybase ASE
                candidateLine = candidateLine.replaceAll("\"" + schema + "\\s*\"\\.", ""); // DB2
                candidateLine = candidateLine.replaceAll(schema + "\\.", ""); // alternate DB2 for views
                candidateLine = removeQuotesFromProcxmode(candidateLine); // sybase ASE

                RevengPattern chosenRevengPattern = null;
                String secondaryName = null;
                for (RevengPattern revengPattern : revengPatterns) {
                    RevengPatternOutput patternMatch = revengPattern.evaluate(candidateLine);
                    if (patternMatch != null) {
                        chosenRevengPattern = revengPattern;
                        candidateObject = patternMatch.getPrimaryName();
                        if (patternMatch.getSecondaryName() != null) {
                            secondaryName = patternMatch.getSecondaryName();
                        }
                        candidateObjectType = platform.getChangeType(revengPattern.getChangeType());
                        objectOrder = 0;
                        break;
                    }
                }

                AtomicInteger objectOrder2 = countByObject.getIfAbsentPut(candidateObject,
                        new Function0<AtomicInteger>() {
                            @Override
                            public AtomicInteger value() {
                                return new AtomicInteger(0);
                            }
                        });

                if (secondaryName == null) {
                    secondaryName = "change" + objectOrder2.getAndIncrement();
                }
                RevEngDestination destination = new RevEngDestination(schema, candidateObjectType,
                        candidateObject, false);

                String annotation = chosenRevengPattern != null ? chosenRevengPattern.getAnnotation() : null;
                MutableList<Function<String, LineParseOutput>> postProcessSqls = chosenRevengPattern != null
                        ? chosenRevengPattern.getPostProcessSqls()
                        : Lists.mutable.<Function<String, LineParseOutput>>empty();

                for (Function<String, LineParseOutput> postProcessSql : postProcessSqls) {
                    LineParseOutput lineParseOutput = postProcessSql.valueOf(candidateLine);
                    candidateLine = lineParseOutput.getLineOutput();
                }

                ChangeEntry change = new ChangeEntry(destination, candidateLine + "\nGO", secondaryName,
                        annotation, selfOrder++);

                postProcessChange.value(change, candidateLine);

                changeEntries.add(change);
            }
        } catch (RuntimeException e) {
            throw new RuntimeException("Failed parsing on statement " + candidateLine, e);
        }
    }

    new RevengWriter().write(platform, changeEntries, outputDir, generateBaseline,
            RevengWriter.defaultShouldOverwritePredicate(), args.getDbHost(), args.getDbPort(),
            args.getDbServer());
}

From source file:com.facultyshowcase.app.cmscomp.professor.viewer.ProfessorProfileGenerator.java

private String getSlug(CmsRequest<ProfessorProfileCMSBean> request) {
    return request.getPageElementPath().isWildcard() ? StringUtils.stripStart(request.getPathInfo(), "/")
            : request.getParameter("slug_id");
}

From source file:de.griffel.confluence.plugins.plantuml.type.ConfluenceLink.java

Calendar getBlogPostDay() {
    final String dayString = StringUtils.stripStart(StringUtils.substringBeforeLast(getPageTitle(), "/"), "/");
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    final Calendar day = Calendar.getInstance();
    try {//from  w w w.ja  va 2s.  c  om
        day.setTime(sdf.parse(dayString));
    } catch (ParseException e) {
        throw new RuntimeException("Cannot parse blog post date string: " + dayString, e);
    }
    return day;
}

From source file:com.activecq.api.helpers.DesignHelper.java

/**
 * Used to create path from Design resource, asset type prefix (css, images,
 * js, etc) and path (usually file name)
 *
 * @param resource// ww w  .j  a  v a2s  . co  m
 * @param pathPrefix
 * @param path
 * @return
 */
protected static String makePath(Resource resource, String pathPrefix, String path) {
    if (StringUtils.startsWith(path, "/")) {
        // Absolute paths ignore the pathPrefix
        return resource.getPath() + path;
    } else {
        return resource.getPath() + "/" + StringUtils.stripStart(pathPrefix, "/") + "/"
                + StringUtils.stripStart(path, "/");
    }
}

From source file:com.dream.messaging.engine.fixformat.FixformatDataHandler.java

@Override
public Object createValue(Object msgData, Node node) throws DataConvertException {

    Object result = null;/*from  ww w . j  av a  2 s  .c  o m*/

    if (msgData instanceof byte[]) {
        // parser the byte[] to a String which presents the object value
        String clsname = QueryNode.getAttribute(node, ElementAttr.Attr_Class);

        boolean isNumber = this.isNumber(clsname);

        String encoding = (String) this.engine.getProperties().get(FixformatMessageEngine.ENCORDING);
        String type = isNumber ? FixformatMessageEngine.NUMBER : FixformatMessageEngine.TEXT;
        boolean fromLeft = Boolean.getBoolean(
                (String) this.engine.getProperties().get(type + FixformatMessageEngine.START_FROM_LEFT));
        String fillUpWith = (String) this.engine.getProperties()
                .get(type + FixformatMessageEngine.FILL_UP_WITH);

        String aString = null;
        try {
            aString = new String((byte[]) msgData, encoding);
        } catch (UnsupportedEncodingException e) {
            throw new DataConvertException("encoding " + encoding + " is not supported,please check it.", e);
        }

        // remove fill up
        if (fromLeft) {
            aString = StringUtils.stripEnd(aString, fillUpWith);
        } else {
            aString = StringUtils.stripStart(aString, fillUpWith);
        }

        // check if the string empty
        if (StringUtils.isEmpty(aString)) {
            if (isNumber) {
                aString = "0";
            } else {
                aString = "";
            }

            return this.createValue(aString, node);
        }

        if (isNumber) {
            // remove sign
            String sign = "";
            if (aString.equals("+") || aString.equals("-")) {
                aString = aString + "0";
            }
            if (aString.endsWith("+") || aString.endsWith("-")) {
                sign = aString.substring(aString.length() - 1);
                aString = sign + aString.substring(0, aString.length() - 1);
            }

            if (clsname.equalsIgnoreCase(ElementClassType.CLASS_DECIMAL)
                    || clsname.equalsIgnoreCase(ElementClassType.CLASS_FLOAT)
                    || (clsname.equalsIgnoreCase(ElementClassType.CLASS_DOUBLE))) {
                String format = QueryNode.getAttribute(node, ElementAttr.Attr_Format);
                int index = format.indexOf('p');
                if (index < 0) {
                    index = format.indexOf('P');
                }
                int fractionLen = Integer.valueOf(format.substring(index + 1));
                if (aString.length() - fractionLen > 0) {
                    aString = aString.substring(0, aString.length() - fractionLen) + "."
                            + aString.substring(aString.length() - fractionLen);
                } else {
                    StringBuffer sb = new StringBuffer(aString);
                    while (sb.length() < fractionLen) {
                        sb.insert(0, fillUpWith);
                    }
                    aString = sb.toString();
                    aString = "0." + aString;
                }

            }
        }
        result = this.createValue(aString, node);
    } else {
        throw new UnsupportedOperationException("The object for createValue must be a byte array");
    }

    return result;

}