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

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

Introduction

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

Prototype

public static int indexOfAnyBut(final CharSequence seq, final CharSequence searchChars) 

Source Link

Document

Search a CharSequence to find the first index of any character not in the given set of characters.

A null CharSequence will return -1 .

Usage

From source file:kenh.expl.functions.IndexOfAnyBut.java

public int process(String seq, String searchSeq) {
    return StringUtils.indexOfAnyBut(seq, searchSeq);
}

From source file:com.xylocore.copybook.generator.domain.WildcardElementFilter.java

/**
 * FILLIN/*from www.j a v  a  2  s  .  c om*/
 */
private void compilePattern() {
    String myPattern = pattern;

    if (StringUtils.indexOfAny(myPattern, "*?/") == -1) {
        myPattern = "**/" + myPattern;
    } else if (myPattern.endsWith("/")) {
        myPattern += "**";
    }

    int myIndex = 0;
    while ((myIndex = myPattern.indexOf('*', myIndex)) != -1) {
        String myRemainder = myPattern.substring(myIndex + 1);
        if (myRemainder.startsWith("*")) {
            if ((myIndex != 0 && myPattern.charAt(myIndex - 1) != '/')
                    || (myIndex + 2 < myPattern.length() && myPattern.charAt(myIndex + 2) != '/')) {
                // TODO: invalid pattern - better exception
                throw new RuntimeException("invalid element filter pattern: " + pattern);
            }

            int myLast = StringUtils.indexOfAnyBut(myRemainder, "*");
            myRemainder = myRemainder.substring((myLast != -1) ? myLast : myRemainder.length());
            myPattern = myPattern.substring(0, myIndex) + "\t" + myRemainder;
        }

        myIndex++;
    }

    compiledPattern = myPattern;
}

From source file:com.google.dart.tools.ui.internal.text.dartdoc.DartDocAutoIndentStrategy.java

/**
 * Copies the indentation of the previous line
 * {@link #customizeDocumentCommand(IDocument, DocumentCommand)}.
 * /*  ww w . jav a  2  s  . co  m*/
 * @see DartDocAutoIndentStrategy
 * @param d the document to work on
 * @param c the command to deal with
 */
protected void autoIndentAfterNewLine(IDocument d, DocumentCommand c) {
    int offset = c.offset;
    if (offset == -1 || d.getLength() == 0) {
        return;
    }

    try {
        // find start of line
        int p = (offset == d.getLength() ? offset - 1 : offset);
        IRegion info = d.getLineInformationOfOffset(p);
        int start = info.getOffset();
        int end = start + info.getLength();

        // split line
        String strLine = d.get(start, end - start);
        int firstNotWS = StringUtils.indexOfAnyBut(strLine, " \t");
        if (firstNotWS == -1) {
            firstNotWS = 0;
        }
        String strWS = strLine.substring(0, firstNotWS);
        String strAfterWS = strLine.substring(firstNotWS);

        String lineDelimiter = TextUtilities.getDefaultLineDelimiter(d);
        StringBuffer buf = new StringBuffer();

        buf.append(lineDelimiter);
        buf.append(strWS);
        if (strAfterWS.startsWith("/")) {
            buf.append(" ");
        } else if (firstNotWS == 0) {
            buf.append(" ");
        }
        buf.append("* ");
        int newCaretOffset = offset + buf.length();
        if (strLine.endsWith("*/")) {
            buf.append(lineDelimiter);
            buf.append(strWS);
            buf.append(" ");
        } else if (isNewComment(d, offset)) {
            buf.append(lineDelimiter);
            buf.append(strWS);
            buf.append(" */");
        }
        c.shiftsCaret = false;
        c.caretOffset = newCaretOffset;
        c.text = buf.toString();
    } catch (BadLocationException excp) {
        // stop work
    }
}

From source file:de.unentscheidbar.validation.builtin.HostNameValidator.java

private void validateLabel(ValidationResult problems, String label) {

    if (label.length() > 63) {
        problems.add(Id.LABEL_TOO_LONG, label);
    } else if (label.length() == 0) {
        problems.add(Id.LABEL_EMPTY, label);
    }//w ww.  j  a v a 2 s.c  om
    int idx = StringUtils.indexOfAnyBut(label, VALID_LABEL_CHARS);
    if (idx != -1)
        problems.add(Id.BAD_CHAR_IN_HOSTNAME, String.valueOf(label.charAt(idx)));
}

From source file:com.mirth.connect.model.CodeTemplate.java

@Override
public void migrate3_3_0(DonkeyElement element) {
    element.addChildElement("revision", "1");

    try {//from   w  w  w .  ja v a2s  .c  o m
        element.addChildElementFromXml(ObjectXMLSerializer.getInstance().serialize(Calendar.getInstance()))
                .setNodeName("lastModified");
    } catch (DonkeyElementException e) {
        throw new SerializerException("Failed to migrate code template last modified date.", e);
    }

    String type = element.getChildElement("type").getTextContent();
    if (type.equals("CODE") || type.equals("VARIABLE")) {
        element.getChildElement("type").setTextContent("DRAG_AND_DROP_CODE");
    }

    DonkeyElement codeElement = element.getChildElement("code");
    String code = StringUtils.trim(codeElement.getTextContent());
    String toolTip = StringUtils.trim(element.removeChild("tooltip").getTextContent());

    if (StringUtils.isNotBlank(toolTip)) {
        if (code.startsWith("/**")) {
            // Code already has a documentation block, so put the tooltip inside it
            int index = StringUtils.indexOfAnyBut(code.substring(1), '*') + 1;
            StringBuilder builder = new StringBuilder(code.substring(0, index)).append("\n\t")
                    .append(WordUtils.wrap(toolTip, 100, "\n\t", false)).append('\n');
            String remaining = code.substring(index);
            if (StringUtils.indexOfAnyBut(remaining.trim(), '*', '/') == 0) {
                builder.append("\n\t");
            }
            code = builder.append(remaining).toString();
        } else {
            // Add a new documentation block
            code = new StringBuilder("/**\n\t").append(WordUtils.wrap(toolTip, 100, "\n\t", false))
                    .append("\n*/\n").append(code).toString();
        }

        codeElement.setTextContent(code);
    }

    DonkeyElement contextSet = element.addChildElement("contextSet").addChildElement("delegate");

    switch (Integer.parseInt(element.removeChild("scope").getTextContent())) {
    case 0:
    case 1:
        contextSet.addChildElement("contextType", "GLOBAL_DEPLOY");
        contextSet.addChildElement("contextType", "GLOBAL_UNDEPLOY");
        contextSet.addChildElement("contextType", "GLOBAL_PREPROCESSOR");
    case 2:
        contextSet.addChildElement("contextType", "GLOBAL_POSTPROCESSOR");
        contextSet.addChildElement("contextType", "CHANNEL_DEPLOY");
        contextSet.addChildElement("contextType", "CHANNEL_UNDEPLOY");
        contextSet.addChildElement("contextType", "CHANNEL_PREPROCESSOR");
        contextSet.addChildElement("contextType", "CHANNEL_POSTPROCESSOR");
        contextSet.addChildElement("contextType", "CHANNEL_ATTACHMENT");
        contextSet.addChildElement("contextType", "CHANNEL_BATCH");
    case 3:
        contextSet.addChildElement("contextType", "SOURCE_RECEIVER");
        contextSet.addChildElement("contextType", "SOURCE_FILTER_TRANSFORMER");
        contextSet.addChildElement("contextType", "DESTINATION_FILTER_TRANSFORMER");
        contextSet.addChildElement("contextType", "DESTINATION_DISPATCHER");
        contextSet.addChildElement("contextType", "DESTINATION_RESPONSE_TRANSFORMER");
    }
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Mp3Db.java

public File getNaxosImage(String labelId) {
    if (StringUtils.isBlank(labelId) == true) {
        return null;
    }/*from w ww . ja v  a  2s . c  o  m*/

    int idx = labelId.indexOf('.');
    if (idx != -1) {
        labelId = labelId.substring(idx + 1);
    }
    idx = StringUtils.indexOfAnyBut(labelId, "0123456789");
    if (idx != -1) {
        labelId = labelId.substring(0, idx);
    }
    File images = new File(mp3root.getParentFile().getParentFile(), "imagesmediennaxos");
    File image = new File(images, labelId + ".gif");
    if (image.exists() == true) {
        return image;
    }
    return null;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlPage.java

/**
 * If a refresh has been specified either through a meta tag or an HTTP
 * response header, then perform that refresh.
 * @throws IOException if an IO problem occurs
 *///from  ww  w.ja  va2 s. c o  m
private void executeRefreshIfNeeded() throws IOException {
    // If this page is not in a frame then a refresh has already happened,
    // most likely through the JavaScript onload handler, so we don't do a
    // second refresh.
    final WebWindow window = getEnclosingWindow();
    if (window == null) {
        return;
    }

    final String refreshString = getRefreshStringOrNull();
    if (refreshString == null || refreshString.isEmpty()) {
        return;
    }

    final double time;
    final URL url;

    int index = StringUtils.indexOfAnyBut(refreshString, "0123456789");
    final boolean timeOnly = index == -1;

    if (timeOnly) {
        // Format: <meta http-equiv='refresh' content='10'>
        try {
            time = Double.parseDouble(refreshString);
        } catch (final NumberFormatException e) {
            LOG.error("Malformed refresh string (no ';' but not a number): " + refreshString, e);
            return;
        }
        url = getUrl();
    } else {
        // Format: <meta http-equiv='refresh' content='10;url=http://www.blah.com'>
        try {
            time = Double.parseDouble(refreshString.substring(0, index).trim());
        } catch (final NumberFormatException e) {
            LOG.error("Malformed refresh string (no valid number before ';') " + refreshString, e);
            return;
        }
        index = refreshString.toLowerCase(Locale.ROOT).indexOf("url=", index);
        if (index == -1) {
            LOG.error("Malformed refresh string (found ';' but no 'url='): " + refreshString);
            return;
        }
        final StringBuilder buffer = new StringBuilder(refreshString.substring(index + 4));
        if (StringUtils.isBlank(buffer.toString())) {
            //content='10; URL=' is treated as content='10'
            url = getUrl();
        } else {
            if (buffer.charAt(0) == '"' || buffer.charAt(0) == 0x27) {
                buffer.deleteCharAt(0);
            }
            if (buffer.charAt(buffer.length() - 1) == '"' || buffer.charAt(buffer.length() - 1) == 0x27) {
                buffer.deleteCharAt(buffer.length() - 1);
            }
            final String urlString = buffer.toString();
            try {
                url = getFullyQualifiedUrl(urlString);
            } catch (final MalformedURLException e) {
                LOG.error("Malformed URL in refresh string: " + refreshString, e);
                throw e;
            }
        }
    }

    final int timeRounded = (int) time;
    getWebClient().getRefreshHandler().handleRefresh(this, url, timeRounded);
}

From source file:org.jamwiki.parser.jflex.AbstractJAMWikiLexer.java

/**
 * Take Wiki text of the form "|" or "| style='foo' |" and convert to
 * and HTML <td> or <th> tag.
 *
 * @param text The text to be parsed./*from   w  w  w.  j ava2s . c  o  m*/
 * @param tagType The HTML tag type, either "td" or "th".
 * @param markup The Wiki markup for the tag, either "|", "|+" or "!"
 */
protected void parseTableCell(String text, String tagType, String markup) throws ParserException {
    if (text == null) {
        throw new IllegalArgumentException("No text specified while parsing table cell");
    }
    text = text.trim();
    String openTagRaw = null;
    int pos = StringUtils.indexOfAnyBut(text, markup);
    if (pos != -1) {
        text = text.substring(pos);
        pos = text.indexOf('|');
        if (pos != -1) {
            text = text.substring(0, pos);
        }
        openTagRaw = "<" + tagType + " " + text.trim() + ">";
    }
    this.pushTag(tagType, openTagRaw);
}