Example usage for java.lang StringBuffer charAt

List of usage examples for java.lang StringBuffer charAt

Introduction

In this page you can find the example usage for java.lang StringBuffer charAt.

Prototype

@Override
public synchronized char charAt(int index) 

Source Link

Usage

From source file:my.home.model.datasource.AutoCompleteItemDataSourceImpl.java

public void markCurrentInput(Context context, String inputString) {
    Log.d(TAG, "mark: " + inputString);
    StringBuffer inputBuffer = new StringBuffer(inputString);
    StringBuffer msgBuffer = new StringBuffer();
    boolean in_if_state = false;
    boolean in_if_then_state = false;
    boolean in_while_state = false;
    boolean in_msg_or_time_ind_state = false;
    String lastString = null;// w  ww  . ja va  2 s  .  c  om
    String preMsgString = null;
    String curState = mInitState;
    while (inputBuffer.length() > 0) {
        if (in_msg_or_time_ind_state) {
            if (inputBuffer.toString().startsWith(mMessageSeq) || inputBuffer.toString().startsWith(mTimeSeq)) {
                in_msg_or_time_ind_state = false;
                MsgHistoryItem msgHistoryItem = new MsgHistoryItem();
                msgHistoryItem.setFrom(preMsgString);
                msgHistoryItem.setMsg(msgBuffer.toString());
                DBStaticManager.addMsgHistoryItem(context, msgHistoryItem);

                msgBuffer.delete(0, msgBuffer.length());
                preMsgString = null;
            } else {
                msgBuffer.append(inputBuffer.charAt(0));
            }
            inputBuffer.deleteCharAt(0);
            continue;
        }
        boolean found = false;
        String tempInput = inputBuffer.toString();
        if (!mLinks.containsKey(curState)) {
            return;
        }
        for (String nextState : mLinks.get(curState)) {
            if (!in_if_state && !in_while_state) {
                if (nextState.equals("then") || nextState.equals("compare") || nextState.equals("logical"))
                    continue;
            }
            if (!in_if_then_state) {
                if (nextState.equals("else"))
                    continue;
            }
            for (String val : mNodes.get(nextState)) {
                if (tempInput.startsWith(val)) {
                    if (lastString != null) {
                        addNewHistoryItem(context, lastString, val);
                    }

                    inputBuffer.delete(0, val.length());
                    found = true;
                    if (nextState.equals("message") || nextState.equals("time")) {
                        in_msg_or_time_ind_state = true;
                        preMsgString = lastString;
                    } else if (nextState.equals("if")) {
                        in_if_state = true;
                    } else if (nextState.equals("while")) {
                        in_while_state = true;
                    } else if (nextState.equals("then")) {
                        if (in_if_state)
                            in_if_then_state = true;
                        in_if_state = false;
                        in_while_state = false;
                    } else if (in_if_then_state && nextState.equals("else")) {
                        in_if_then_state = false;
                    }
                    lastString = val;
                    curState = nextState;
                    break;
                }
            }
            if (found || inputBuffer.length() == 0)
                break;
        }
        if (inputBuffer.length() == 0) {
            break;
        }
        if (found) {
            if (msgBuffer.length() != 0) {
                MsgHistoryItem msgHistoryItem = new MsgHistoryItem();
                msgHistoryItem.setFrom(preMsgString);
                msgHistoryItem.setMsg(msgBuffer.toString());
                DBStaticManager.addMsgHistoryItem(context, msgHistoryItem);

                msgBuffer.delete(0, msgBuffer.length());
                preMsgString = null;
            }
            continue;
        }
        if (curState.equals("message") || mLinks.get(curState).contains("message")) {
            found = true;
            curState = "message";
            preMsgString = lastString;
            msgBuffer.append(inputBuffer.charAt(0));
            inputBuffer.deleteCharAt(0);
        } else if (curState.equals("time") || mLinks.get(curState).contains("time")) {
            found = true;
            curState = "time";
            preMsgString = lastString;
            msgBuffer.append(inputBuffer.charAt(0));
            inputBuffer.deleteCharAt(0);
        }
        if (!found)
            break;
    }
    if (msgBuffer.length() != 0) {
        MsgHistoryItem msgHistoryItem = new MsgHistoryItem();
        msgHistoryItem.setFrom(preMsgString);
        msgHistoryItem.setMsg(msgBuffer.toString());
        DBStaticManager.addMsgHistoryItem(context, msgHistoryItem);
    }
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoImportWizard.java

protected String camelCase(String text, boolean cap) {
    StringBuffer buf = new StringBuffer(text);
    for (int i = 0; i < buf.length(); i++) {
        if (buf.charAt(i) == '-' && buf.length() > (i + 1)) {
            buf.deleteCharAt(i);/*from w w  w .  j  a v a  2  s  .c  om*/
            if (buf.charAt(i) != '?' && buf.charAt(i) != '%') {
                buf.setCharAt(i, Character.toUpperCase(buf.charAt(i)));
            } else if (buf.charAt(i) == '?') {
                buf.setCharAt(i, 'Q');
            } else if (buf.charAt(i) == '%') {
                buf.setCharAt(i, 'P');
            }
        } else if (buf.charAt(i) == '?') {
            buf.setCharAt(i, 'Q');
        } else if (buf.charAt(i) == '%') {
            buf.setCharAt(i, 'p');
        }
    }
    if (cap)
        buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));
    return buf.toString();
}

From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java

private void writeFractional(StringBuffer result, StringBuffer output) {
    int digit;//from   w  w  w .  ja  v a2 s  .  c  om
    int strip;
    ListIterator<Special> it;
    if (fractionalSpecials.size() > 0) {
        //20100914, henrichen@zkoss.org: respect given Locale
        final char dot = Formatters.getDecimalSeparator(locale);
        output.setCharAt(decimalPoint.pos, dot);

        digit = result.indexOf("" + dot) + 1;
        if (exponent != null)
            strip = result.indexOf("e") - 1;
        else
            strip = result.length() - 1;
        while (strip > digit && result.charAt(strip) == '0')
            strip--;
        it = fractionalSpecials.listIterator();
        while (it.hasNext()) {
            Special s = it.next();
            char resultCh = result.charAt(digit);
            if (resultCh != '0' || s.ch == '0' || digit < strip)
                output.setCharAt(s.pos, resultCh);
            else if (s.ch == '?') {
                // This is when we're in trailing zeros, and the format is '?'.  We still strip out remaining '#'s later
                output.setCharAt(s.pos, ' ');
            }
            digit++;
        }
    }
}

From source file:com.wabacus.config.component.application.report.ReportDataSetValueBean.java

public void setDependsConditionExpression(String dependsConditionExpression) {
    if (this.mDependParents == null || this.mDependParents.size() == 0) {
        this.dependsConditionExpression = null;
    } else if (dependsConditionExpression != null && !dependsConditionExpression.trim().equals("")) {
        this.dependsConditionExpression = dependsConditionExpression.trim();
    } else {//?
        DependingColumnBean dcbeanTmp;/*from  w  w w  .  j  ava2 s.  c  o m*/
        StringBuffer expressionBuf = new StringBuffer();
        if (this.provider instanceof SQLReportDataSetValueProvider) {
            for (Entry<String, DependingColumnBean> entryTmp : this.mDependParents.entrySet()) {
                dcbeanTmp = entryTmp.getValue();
                expressionBuf.append(dcbeanTmp.getColumn()).append(" in (");
                expressionBuf.append("#").append(dcbeanTmp.getParentValueid()).append(".")
                        .append(dcbeanTmp.getParentColumn()).append("#) and ");
            }
            this.dependsConditionExpression = expressionBuf.toString().trim();
            if (this.dependsConditionExpression.endsWith(" and")) {
                this.dependsConditionExpression = this.dependsConditionExpression.substring(0,
                        this.dependsConditionExpression.length() - 4);
            }
        } else {
            for (Entry<String, DependingColumnBean> entryTmp : this.mDependParents.entrySet()) {
                dcbeanTmp = entryTmp.getValue();
                expressionBuf.append(dcbeanTmp.getColumn()).append("=");
                expressionBuf.append("#").append(dcbeanTmp.getParentValueid()).append(".")
                        .append(dcbeanTmp.getParentColumn()).append("#;");
            }
            if (expressionBuf.charAt(expressionBuf.length() - 1) == ';')
                expressionBuf.deleteCharAt(expressionBuf.length() - 1);
            this.dependsConditionExpression = expressionBuf.toString().trim();
        }
    }
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoImportWizard.java

public String getJavaName(String name) {
    StringBuffer buf = new StringBuffer();

    buf.append(name.trim());//ww w.  ja va2s .com

    for (int i = 0; i < buf.length(); i++) {
        if (Character.isLetterOrDigit(buf.charAt(i))) {
            continue;
        } else if (buf.charAt(i) == '_') {
            continue;
        } else if (buf.charAt(i) == '?') {
            buf.setCharAt(i, 'Q');
        } else if (buf.charAt(i) == '%') {
            buf.setCharAt(i, 'p');
        } else if (buf.charAt(i) == '!') {
            buf.setCharAt(i, 'X');
        } else if (Character.isWhitespace(buf.charAt(i)) || buf.charAt(i) == '-') {
            buf.deleteCharAt(i);
            if (i < buf.length() && Character.isLetterOrDigit(buf.charAt(i))) {
                if (buf.charAt(i) != '?' && buf.charAt(i) != '%' && buf.charAt(i) != '!') {
                    buf.setCharAt(i, Character.toUpperCase(buf.charAt(i)));
                } else if (buf.charAt(i) == '_') {
                    continue;
                } else if (buf.charAt(i) == '?') {
                    buf.setCharAt(i, 'Q');
                } else if (buf.charAt(i) == '%') {
                    buf.setCharAt(i, 'P');
                } else if (buf.charAt(i) == '!') {
                    buf.setCharAt(i, 'X');
                }
            }
        } else {
            buf.setCharAt(i, 'Q');
        }
    }
    if (Character.isDigit(buf.charAt(0))) {
        buf.insert(0, '_');
    }
    return buf.toString();
}

From source file:architecture.common.util.TextUtils.java

private final static void linkEmail(StringBuffer str) {
    int lastEndIndex = -1; // Store the index position of the end char of
    // last email address found...

    main: while (true) {
        // get index of '@'...
        int atIndex = str.indexOf("@", lastEndIndex + 1);

        if (atIndex == -1) {
            break;
        } else {// ww w.ja va 2s  .  c  o m
            // Get the whole email address...
            // Get the part before '@' by moving backwards and taking each
            // character
            // until we encounter an invalid URL char...
            String partBeforeAt = "";
            int linkStartIndex = atIndex;
            boolean reachedStart = false;

            while (!reachedStart) {
                linkStartIndex--;

                if (linkStartIndex < 0) {
                    reachedStart = true;
                } else {
                    char c = str.charAt(linkStartIndex);

                    // if we find these chars in an email, then it's part of
                    // a url, so lets leave it alone
                    // Are there any other chars we should abort email
                    // checking for??
                    if ((c == '?') || (c == '&') || (c == '=') || (c == '/') || (c == '%')) {
                        lastEndIndex = atIndex + 1;

                        continue main;
                    }

                    if (isValidEmailChar(c)) {
                        partBeforeAt = c + partBeforeAt;
                    } else {
                        reachedStart = true;
                    }
                }
            }

            // Increment linkStartIndex back by 1 to reflect the real
            // starting index of the
            // email address...
            linkStartIndex++;

            // Get the part after '@' by doing pretty much the same except
            // moving
            // forward instead of backwards.
            String partAfterAt = "";
            int linkEndIndex = atIndex;
            boolean reachedEnd = false;

            while (!reachedEnd) {
                linkEndIndex++;

                if (linkEndIndex == str.length()) {
                    reachedEnd = true;
                } else {
                    char c = str.charAt(linkEndIndex);

                    if (isValidEmailChar(c)) {
                        partAfterAt += c;
                    } else {
                        reachedEnd = true;
                    }
                }
            }

            // Decrement linkEndIndex back by 1 to reflect the real ending
            // index of the
            // email address...
            linkEndIndex--;

            // Reassemble the whole email address...
            String emailStr = partBeforeAt + '@' + partAfterAt;

            // If the last chars of emailStr is a '.', ':', '-', '/' or '~'
            // then we exclude those chars.
            // The '.' at the end could be just a fullstop to a sentence and
            // we don't want
            // that to be part of an email address (which would then be
            // invalid).
            // Pretty much the same for the other symbols - we don't want
            // them at the end of any email
            // address cos' this would stuff the address up.
            while (true) {
                char lastChar = emailStr.charAt(emailStr.length() - 1);

                if ((lastChar == '.') || (lastChar == ':') || (lastChar == '-') || (lastChar == '/')
                        || (lastChar == '~')) {
                    emailStr = emailStr.substring(0, emailStr.length() - 1);
                    linkEndIndex--;
                } else {
                    break;
                }
            }

            // Verify if email is valid...
            if (verifyEmail(emailStr)) {
                // Construct the hyperlink for the email address...
                String emailLink = "<a href='mailto:" + emailStr + "'>" + emailStr + "</a>";

                // Take the part of the str before the email address, the
                // part after, and add
                // the emailLink between those two parts, so that in effect
                // the original email
                // address is replaced by a hyperlink to it...
                str.replace(linkStartIndex, linkEndIndex + 1, emailLink);

                // Set lastEndIndex to reflect the position of the end of
                // emailLink
                // within the whole string...
                lastEndIndex = (linkStartIndex - 1) + emailLink.length();
            } else {
                // lastEndIndex is different from the one above cos' there's
                // no
                // <a href...> tags added...
                lastEndIndex = (linkStartIndex - 1) + emailStr.length();
            }
        }
    }
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from  w  ww  .java 2s . co  m
 * @param text
 * @param searchWord
 * @return
 */
public static String highlightText(String text, String searchWord) {
    StringBuffer returnText = new StringBuffer(text);
    Integer indexWord = new Integer(0);
    List<String> exactWords = new ArrayList<String>();
    String toSearch = searchWord;
    //MD: This code is to identify the words between double quotes
    while (toSearch.contains("\"")) {
        //First double quote
        int from = toSearch.indexOf('\"');
        //Second double quote
        int to = toSearch.indexOf('\"', from + 1);
        //If there is the second double quote or not
        if (to != -1) {
            //Add the exact words to the list and remove them from the string
            exactWords.add(toSearch.substring(from + 1, to).toLowerCase());
            toSearch = toSearch.substring(0, from) + toSearch.substring(to + 1, toSearch.length());
        } else {
            toSearch = toSearch.replace("\"", " ");
        }
    }
    String[] words = StringUtils.split(searchWord.toLowerCase(), " ");
    if (exactWords.size() == 0) {
        for (String currentWord : words) {
            indexWord = returnText.toString().toLowerCase().indexOf(currentWord);
            while (indexWord != -1) {
                while (indexWord >= 0 && returnText.charAt(indexWord) != ' ') {
                    indexWord--;
                }
                Integer beginWord = indexWord + 1;
                returnText.insert(beginWord, "<span class='highlighted'>");
                Integer endWord = beginWord + 26;
                while (endWord < returnText.length() && returnText.charAt(endWord) != ' ') {
                    endWord++;
                }
                returnText.insert(endWord, "</span>");
                Integer nextWord = returnText.substring(endWord).toLowerCase().indexOf(currentWord);
                if (nextWord != -1) {
                    indexWord = endWord + nextWord;
                } else {
                    indexWord = nextWord;
                }
            }
        }
    } else {
        for (String currentWord : exactWords) {
            indexWord = returnText.toString().toLowerCase().indexOf(currentWord);
            while (indexWord != -1) {
                Integer beginWord = indexWord;
                returnText.insert(beginWord, "<span class='highlighted'>");
                Integer endWord = beginWord + 26 + currentWord.length();
                returnText.insert(endWord, "</span>");
                Integer nextWord = returnText.substring(endWord).toLowerCase().indexOf(currentWord);
                if (nextWord != -1) {
                    indexWord = endWord + nextWord;
                } else {
                    indexWord = nextWord;
                }
            }
        }
    }
    return returnText.toString();
}

From source file:org.apache.axis.wsdl.toJava.JavaGeneratorFactory.java

/** Refactored to call recursively for JAX-RPC 1.1 spec 4.2.5. */
protected int javifyTypeEntryName(SymbolTable symbolTable, TypeEntry entry, HashMap anonQNames, int uniqueNum) {
    TypeEntry tEntry = entry;/* ww w. j  a va2  s  . c o m*/
    String dims = tEntry.getDimensions();
    TypeEntry refType = tEntry.getRefType();
    while (refType != null) {
        tEntry = refType;
        dims += tEntry.getDimensions();
        refType = tEntry.getRefType();
    }

    TypeEntry te = tEntry;
    while (te != null) {
        TypeEntry base = SchemaUtils.getBaseType(te, symbolTable);
        if (base == null)
            break;

        uniqueNum = javifyTypeEntryName(symbolTable, base, anonQNames, uniqueNum);

        if (Utils.getEnumerationBaseAndValues(te.getNode(), symbolTable) == null
                && SchemaUtils.getComplexElementExtensionBase(te.getNode(), symbolTable) == null
                && te.getContainedAttributes() == null) {
            if (!SchemaUtils.isSimpleTypeWithUnion(te.getNode())) {
                if (base.isSimpleType()) {
                    // Case 1:
                    // <simpleType name="mySimpleStringType">
                    //   <restriction base="xs:string">
                    //   </restriction>
                    // </simpleType>
                    te.setSimpleType(true);
                    te.setName(base.getName());
                    te.setRefType(base);
                }

                if (base.isBaseType()) {
                    // Case 2:
                    // <simpleType name="FooString">
                    //   <restriction base="foo:mySimpleStringType">
                    //   </restriction>
                    // </simpleType>
                    te.setBaseType(true);
                    te.setName(base.getName());
                    te.setRefType(base);
                }
            }
        }

        if (!te.isSimpleType())
            break;

        te = base;
    }

    // Need to javify the ref'd TypeEntry if it was not
    // already processed
    if (tEntry.getName() == null) {
        boolean processed = false; // true if the java name is already determined
        // Get the QName of the ref'd TypeEntry, which
        // is will be used to javify the name
        QName typeQName = tEntry.getQName();

        // In case of <xsd:list itemType="...">,
        // set typeQName to the value of the itemType attribute.
        QName itemType = SchemaUtils.getListItemType(tEntry.getNode());
        if (itemType != null) {
            // Get the typeEntry so we know the absolute base type
            TypeEntry itemEntry = symbolTable.getTypeEntry(itemType, false);
            // TODO - If the itemEntry is not found, we need to throw
            // an exception.  "Item is referenced, but not defined"
            javifyTypeEntryName(symbolTable, itemEntry, anonQNames, uniqueNum);
            // Grab the referenced type, If it's there.
            TypeEntry refedEntry = itemEntry.getRefType();
            QName baseName = refedEntry == null ? itemEntry.getQName() : refedEntry.getQName();
            typeQName = new QName(baseName.getNamespaceURI(), baseName.getLocalPart() + "[]");
        }

        if (emitter.isDeploy()) {
            Class class1 = (Class) emitter.getQName2ClassMap().get(typeQName);
            if (class1 != null && !class1.isArray()) {
                tEntry.setName(getJavaClassName(class1));
                processed = true;
            }
        }

        if (!processed) {
            if ((typeQName.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) < 0)) {
                // Normal Case: The ref'd type is not anonymous
                // Simply construct the java name from
                // the qName
                tEntry.setName(emitter.getJavaName(typeQName));
            } else {
                // This is an anonymous type name.
                // Axis uses '>' as a nesting token to generate
                // unique qnames for anonymous types.
                // Only consider the localName after the last '>'
                // when generating the java name
                // String localName = typeQName.getLocalPart();
                // localName =
                // localName.substring(
                // localName.lastIndexOf(
                // SymbolTable.ANON_TOKEN)+1);
                // typeQName = new QName(typeQName.getNamespaceURI(),
                // localName);
                String localName = typeQName.getLocalPart();

                // Check to see if this is an anonymous type,
                // if it is, replace Axis' ANON_TOKEN with
                // an underscore to make sure we don't run
                // into name collisions with similarly named
                // non-anonymous types
                StringBuffer sb = new StringBuffer(localName);
                int aidx;

                while ((aidx = sb.toString().indexOf(SymbolTable.ANON_TOKEN)) > -1) {
                    sb.replace(aidx, aidx + SymbolTable.ANON_TOKEN.length(), "");
                    char c = sb.charAt(aidx);
                    if (Character.isLetter(c) && Character.isLowerCase(c)) {
                        sb.setCharAt(aidx, Character.toUpperCase(c));
                    }
                }

                localName = sb.toString();
                typeQName = new QName(typeQName.getNamespaceURI(), localName);

                if (emitter.isTypeCollisionProtection() && !emitter.getNamespaceExcludes()
                        .contains(new NamespaceSelector(typeQName.getNamespaceURI()))) {
                    // If there is already an existing type,
                    // there will be a collision.
                    // If there is an existing anon type,
                    // there will be a  collision.
                    // In both cases, mangle the name.
                    if (symbolTable.getType(typeQName) != null || anonQNames.get(typeQName) != null) {
                        localName += "Type" + uniqueNum++;
                        typeQName = new QName(typeQName.getNamespaceURI(), localName);
                    }

                    anonQNames.put(typeQName, typeQName);
                }

                // Now set the name with the constructed qname
                tEntry.setName(emitter.getJavaName(typeQName));
            }
        } // if (!processed)

        Vector elements = tEntry.getContainedElements();
        if (elements != null) {
            for (int i = 0; i < elements.size(); i++) {
                ElementDecl elem = (ElementDecl) elements.get(i);
                String varName = emitter.getJavaVariableName(typeQName, elem.getQName(), true);
                elem.setName(varName);
            }
        }

        Vector attributes = tEntry.getContainedAttributes();
        if (attributes != null) {
            for (int i = 0; i < attributes.size(); i++) {
                ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
                String varName = emitter.getJavaVariableName(typeQName, attr.getQName(), false);
                attr.setName(varName);
            }
        }
    }

    // Set the entry with the same name as the ref'd entry
    // but add the appropriate amount of dimensions
    entry.setName(tEntry.getName() + dims);

    return uniqueNum;
}

From source file:architecture.common.util.TextUtils.java

/**
 * Extract a number from a String./*  ww  w  . jav a 2  s . com*/
 *
 * <h5>Example</h5>
 *
 * <pre>
 *   " 12345"                 -&gt;     "12345"
 *   "hello123bye"            -&gt;     "123"
 *   "a2b4c6 8 "              -&gt;     "2468"
 *   " -22"                   -&gt;     "-22"
 *   "5.512"                  -&gt;     "5.512"
 *   "1.2.3.4"                -&gt;     "1.234"
 *   ".2"                     -&gt;     "0.2"
 *   "-555.7"                 -&gt;     "-555.7"
 *   "-..6"                   -&gt;     "-0.6"
 *   "abc- dx.97 9"           -&gt;     "-0.979"
 *   "\ufffd1,000,000.00 per year" -&gt;     "1000000.00"
 *   ""                       -&gt;     "0"
 *   "asdsf"                  -&gt;     "0"
 *   "123."                   -&gt;     "123"
 *   null                     -&gt;     "0"
 * </pre>
 *
 * @param in
 *            Original String containing number to be extracted.
 * @return String stripped of all non-numeric chars.
 *
 * @see #parseInt(String)
 * @see #parseLong(String)
 */
public final static String extractNumber(String in) {
    if (in == null) {
        return "0";
    }

    StringBuffer result = new StringBuffer();
    boolean seenDot = false;
    boolean seenMinus = false;
    boolean seenNumber = false;

    for (int i = 0; i < in.length(); i++) {
        char c = in.charAt(i);

        if (c == '.') {
            // insert dot if not yet encountered
            if (!seenDot) {
                seenDot = true;

                if (!seenNumber) {
                    result.append('0'); // padding zero if no number yet
                }

                result.append('.');
            }
        } else if (c == '-') {
            // insert minus sign if not yet encountered
            if (!seenMinus) {
                seenMinus = true;
                result.append('-');
            }
        } else if ((c == '0') || ((c >= '1') && (c <= '9'))) {
            // add number
            seenNumber = true;
            result.append(c);
        }
    }

    // remove trailing .
    int length = result.length();

    if ((length > 0) && (result.charAt(length - 1) == '.')) {
        result.deleteCharAt(length - 1);
    }

    return (result.length() == 0) ? "0" : result.toString(); // if nothing
    // left, return
    // 0
}

From source file:com.wabacus.system.assistant.TagAssistant.java

public String getDataImportDisplayValue(String ref, String asyn, String popupparams, String initsize,
        String label, String interceptor, HttpServletRequest request) {
    if (ref == null || ref.trim().equals("")) {
        throw new WabacusRuntimeException("<wx:dataimport/>ref");
    }//from  w  ww.j  ava  2 s. c om
    StringBuffer refBuf = new StringBuffer();
    List<String> lst = Tools.parseStringToList(ref, ";", false);
    for (String strTmp : lst) {
        if (strTmp.equals(""))
            continue;
        //                throw new JspException("<dataimport/>ref??");
        //jsp${expression}????ref?key
        Object obj = Config.getInstance().getResources().get(null, strTmp, true);
        if (!(obj instanceof AbsDataImportConfigBean)) {
            throw new WabacusConfigLoadingException("<dataimport/>ref?"
                    + strTmp + "????");
        }
        refBuf.append(strTmp).append(";");
    }
    if (refBuf.length() == 0) {
        throw new WabacusRuntimeException("<wx:dataimport/>ref");
    }
    if (refBuf.charAt(refBuf.length() - 1) == ';') {
        refBuf.deleteCharAt(refBuf.length() - 1);
    }
    popupparams = WabacusAssistant.getInstance().addDefaultPopupParams(popupparams, initsize, "300", "160",
            null);
    String token = "?";
    if (Config.showreport_url.indexOf("?") > 0)
        token = "&";
    String url = Config.showreport_url + token + "DATAIMPORT_REF=" + refBuf.toString()
            + "&ACTIONTYPE=ShowUploadFilePage&FILEUPLOADTYPE=" + Consts_Private.FILEUPLOADTYPE_DATAIMPORTTAG;
    if (interceptor != null && !interceptor.trim().equals("")) {
        url = url + "&INTERCEPTOR=" + interceptor;
    }
    if (asyn != null && !asyn.trim().equals("")) {
        url = url + "&ASYN=" + asyn;
    }
    String clickevent = "wx_winpage('" + url + "'," + popupparams + ")";
    StringBuffer labelBuf = new StringBuffer();
    if (label != null && !label.trim().equals("")) {
        labelBuf.append("<a onmouseover=\"this.style.cursor='pointer';\" onclick=\"" + clickevent + "\">");
        labelBuf.append(label);
        labelBuf.append("</a>");
    } else {
        label = Config.getInstance().getResources().getString(null, Consts.DATAIMPORT_LABEL, true).trim();
        labelBuf.append("<input type=\"button\" class=\"cls-button2\" onClick=\"" + clickevent + "\"");
        labelBuf.append(" value=\"" + label + "\">");
    }
    StringBuffer resultBuf = new StringBuffer();
    resultBuf.append(addPopupIncludeJsCss(request));
    resultBuf.append(labelBuf.toString());
    return resultBuf.toString();
}