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

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

Introduction

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

Prototype

public static String stripStart(final String str, final String stripChars) 

Source Link

Document

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

A null input String returns null .

Usage

From source file:org.wrml.runtime.service.file.FileSystemService.java

private Path getManagedDataFilePath(final URI schemaUri, final String dataFileHandle) {

    final Path rootDirectoryPath = getRootDirectoryPath();
    Path dataFilePath = rootDirectoryPath.resolve(StringUtils.stripStart(schemaUri.getPath(), "/"));
    dataFilePath = dataFilePath.resolve(STATIC_PATH_SEGMENT_DATA);
    dataFilePath = dataFilePath.resolve(dataFileHandle + getFileExtension());
    return dataFilePath;
}

From source file:org.wrml.util.UniqueName.java

public UniqueName(final URI uri) {

    this(StringUtils.stripStart(uri.getPath(), "/"));
}

From source file:org.xwiki.officeimporter.internal.filter.ListFilter.java

/**
 * {@inheritDoc}/*from   www . j a va 2 s  . co  m*/
 */
public void filter(Document document, Map<String, String> cleaningParams) {
    List<Element> listItems = filterDescendants(document.getDocumentElement(), new String[] { TAG_LI });
    for (Element listItem : listItems) {
        Node nextChild = listItem.getFirstChild();
        while (nextChild != null) {
            if (nextChild.getNodeType() == Node.TEXT_NODE) {
                String trimmed = StringUtils.stripStart(nextChild.getTextContent(), WHITE_SPACE_CHARS);
                nextChild.setTextContent(trimmed);
                if (trimmed.equals("")) {
                    nextChild = nextChild.getNextSibling();
                    continue;
                }
            } else if (nextChild.getNodeName().equals(TAG_P)) {
                replaceWithChildren((Element) nextChild);
            }
            break;
        }
    }
}

From source file:org.xwiki.url.internal.RelativeExtendedURL.java

@Override
public String serialize() {
    // Make sure the serialized URL is relative
    return StringUtils.stripStart(super.serialize(), "/");
}

From source file:org.zanata.magpie.action.FrontendAssets.java

public String generateAbsolutePath(String contextPath, String file) {
    return contextPath + "/" + StringUtils.stripStart(file, "/");
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java

protected String appendOptionalSuffix(URL url, String suffix) {
    if (StringUtils.isBlank(suffix)) {
        return url.toString();
    }//w  w w . j a va2 s  .c  o  m
    return StringUtils.stripEnd(url.toString(), SLASH) + SLASH + StringUtils.stripStart(suffix, SLASH);
}

From source file:tpt.dbweb.cat.io.TaggedTextXMLReader.java

private Iterator<TaggedText> getIterator(InputStream is, String errorMessageInfo) {

    XMLStreamReader tmpxsr = null;
    try {// w  w w .  j a v a2s.  co m
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
        xif.setProperty(XMLInputFactory.IS_VALIDATING, false);
        tmpxsr = xif.createXMLStreamReader(is);
    } catch (XMLStreamException | FactoryConfigurationError e) {
        e.printStackTrace();
        return null;
    }

    final XMLStreamReader xsr = tmpxsr;
    return new PeekIterator<TaggedText>() {

        @Override
        protected TaggedText internalNext() {
            ArrayList<TextSpan> openMarks = new ArrayList<>();
            StringBuilder pureTextSB = new StringBuilder();
            ArrayList<TextSpan> marks = new ArrayList<>();
            marks.add(new TextSpan(null, 0, 0));
            TaggedText tt = null;

            try {
                loop: while (xsr.hasNext()) {
                    xsr.next();
                    int event = xsr.getEventType();
                    switch (event) {
                    case XMLStreamConstants.START_ELEMENT:
                        if ("articles".equals(xsr.getLocalName())) {
                        } else if ("article".equals(xsr.getLocalName())) {
                            tt = new TaggedText();
                            for (int i = 0; i < xsr.getAttributeCount(); i++) {
                                if ("id".equals(xsr.getAttributeLocalName(i))) {
                                    tt.id = xsr.getAttributeValue(i);
                                }
                                tt.info().put(xsr.getAttributeLocalName(i), xsr.getAttributeValue(i));
                            }

                        } else if ("mark".equals(xsr.getLocalName())) {
                            TextSpan tr = new TextSpan(null, pureTextSB.length(), pureTextSB.length());
                            for (int i = 0; i < xsr.getAttributeCount(); i++) {
                                tr.info().put(xsr.getAttributeLocalName(i), xsr.getAttributeValue(i));
                            }

                            openMarks.add(tr);
                        } else if ("br".equals(xsr.getLocalName())) {
                            // TODO: how to propagate tags from the input to the output?
                        } else {
                            log.warn("ignore tag " + xsr.getLocalName());
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        if ("mark".equals(xsr.getLocalName())) {

                            // search corresponding <mark ...>
                            TextSpan tr = openMarks.remove(openMarks.size() - 1);
                            if (tr == null) {
                                log.warn("markend at " + xsr.getLocation().getCharacterOffset()
                                        + " has no corresponding mark tag");
                                break;
                            }

                            tr.end = pureTextSB.length();
                            marks.add(tr);

                        } else if ("article".equals(xsr.getLocalName())) {
                            tt.text = StringUtils.stripEnd(pureTextSB.toString().trim(), " \t\n");
                            pureTextSB = new StringBuilder();

                            tt.mentions = new ArrayList<>();
                            for (TextSpan mark : marks) {

                                String entity = mark.info().get("entity");
                                if (entity == null) {
                                    entity = mark.info().get("annotation");
                                }
                                if (entity != null) {
                                    EntityMention e = new EntityMention(tt.text, mark.start, mark.end, entity);
                                    String minMention = mark.info().get("min");
                                    String mention = e.getMention();
                                    if (minMention != null && !"".equals(minMention)) {
                                        Pattern p = Pattern.compile(Pattern.quote(minMention));
                                        Matcher m = p.matcher(mention);
                                        if (m.find()) {
                                            TextSpan min = new TextSpan(e.text, e.start + m.start(),
                                                    e.start + m.end());
                                            e.min = min;
                                            if (m.find()) {
                                                log.warn("found " + minMention + " two times in \"" + mention
                                                        + "\"");
                                            }
                                        } else {
                                            String prefix = Utility.findLongestPrefix(mention, minMention);
                                            log.warn("didn't find min mention '" + minMention + "' in text '"
                                                    + mention + "', longest prefix found: '" + prefix
                                                    + "' in article " + tt.id);
                                        }
                                    }

                                    mark.info().remove("min");
                                    mark.info().remove("entity");
                                    if (mark.info().size() > 0) {
                                        e.info().putAll(mark.info());
                                    }
                                    tt.mentions.add(e);
                                }
                            }
                            openMarks.clear();
                            marks.clear();
                            break loop;
                        }
                        break;
                    case XMLStreamConstants.CHARACTERS:
                        String toadd = xsr.getText();
                        if (pureTextSB.length() == 0) {
                            toadd = StringUtils.stripStart(toadd, " \t\n");
                        }
                        if (toadd.contains("thanks")) {
                            log.info("test");
                        }
                        pureTextSB.append(toadd);
                        break;
                    }

                }
            } catch (XMLStreamException e) {
                log.error("{}", errorMessageInfo);
                throw new RuntimeException(e);
            }
            if (tt != null && tt.mentions != null) {
                tt.mentions.sort(null);
            }
            return tt;
        }
    };
}

From source file:tpt.dbweb.cat.tools.RegexWordTokenizer.java

@Override
public List<TextSpan> getTokens(String text) {
    // split text and iterate over its parts
    String[] parts = pattern.split(text);
    List<TextSpan> result = new ArrayList<>();
    int pos = 0;//from w w  w  .ja v  a 2  s  . co  m
    for (int i = 0; i < parts.length; i++) {
        String part = parts[i];
        int nextPos = pos + part.length();
        try {
            // remove whitespace
            String ltrim = StringUtils.stripStart(part, null);
            String trim = StringUtils.stripEnd(ltrim, null);
            int start = pos + (part.length() - ltrim.length());
            int end = start + trim.length();
            // only add non-empty text spans
            if (start < end) {
                result.add(new TextSpan(text, start, end));
            }
        } finally {
            pos = nextPos;
        }
    }
    return result;
}