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

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

Introduction

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

Prototype

public static String strip(String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

Usage

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Covert OSGi Property storing Root content paths:Error page paths into a SortMap
 *
 * @param paths//w ww  . j  ava 2 s  .  co  m
 * @return
 */
private SortedMap<String, String> configurePathMap(String[] paths) {
    SortedMap<String, String> sortedMap = new TreeMap<String, String>(new StringLengthComparator());

    for (String path : paths) {
        if (StringUtils.isBlank(path)) {
            continue;
        }

        final SimpleEntry tmp = toSimpleEntry(path, ":");

        if (tmp == null) {
            continue;
        }

        String key = StringUtils.strip((String) tmp.getKey());
        String val = StringUtils.strip((String) tmp.getValue());

        // Only accept absolute paths
        if (StringUtils.isBlank(key) || !StringUtils.startsWith(key, "/")) {
            continue;
        }

        // Validate page name value
        if (StringUtils.isBlank(val)) {
            val = key + "/" + DEFAULT_ERROR_PAGE_NAME;
        } else if (StringUtils.equals(val, ".")) {
            val = key;
        } else if (!StringUtils.startsWith(val, "/")) {
            val = key + "/" + val;
        }

        sortedMap.put(key, val);
    }

    return sortedMap;
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.por.PORFileReader.java

private void decodeNumberOfVariables(BufferedReader reader) throws IOException {
    if (reader == null) {
        throw new IllegalArgumentException("decodeNumberOfVariables: reader == null!");
    }/*from w  w w . ja va  2 s .  c  o m*/

    String temp = null;
    char[] tmp = new char[1];
    StringBuilder sb = new StringBuilder();

    while (reader.read(tmp) > 0) {
        temp = Character.toString(tmp[0]);
        if (temp.equals("/")) {
            break;
        } else {
            sb.append(temp);
        }
    }

    String rawNumberOfVariables = sb.toString();
    int rawLength = rawNumberOfVariables.length();

    String numberOfVariables = StringUtils.stripStart((StringUtils.strip(rawNumberOfVariables)), "0");

    if ((numberOfVariables.equals("")) && (numberOfVariables.length() == rawLength)) {
        numberOfVariables = "0";
    }

    varQnty = Integer.valueOf(numberOfVariables, 30);
    dataTable.setVarQuantity(Long.valueOf(numberOfVariables, 30));
}

From source file:com.circle.utils.XMLSerializer.java

private JSON processArrayElement(Element element, String defaultType) {
    JSONArray jsonArray = new JSONArray();
    // process children (including text)
    int childCount = element.getChildCount();
    for (int i = 0; i < childCount; i++) {
        Node child = element.getChild(i);
        if (child instanceof Text) {
            Text text = (Text) child;
            if (StringUtils.isNotBlank(StringUtils.strip(text.getValue()))) {
                jsonArray.element(text.getValue());
            }/*from   w ww  .  ja  v  a  2  s. co  m*/
        } else if (child instanceof Element) {
            setValue(jsonArray, (Element) child, defaultType);
        }
    }
    return jsonArray;
}

From source file:com.neusoft.mid.clwapi.service.statistics.StatisticsServiceImpl.java

/**
 * ??.//w  w w.j  ava 2  s  .c  o  m
 * 
 * @param token
 *            ?.
 * @param month
 *            ,?yyyymm
 * @param rsType
 *            ?,01- ;02- ?;03- 
 * 
 * @return ??.
 */
@Override
public Response getEntiReportDetail(String token, String month, String rsType) {
    month = StringUtils.strip(month);
    rsType = StringUtils.strip(rsType);
    String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
    String orgID = context.getHttpHeaders().getHeaderString(UserInfoKey.ORGANIZATION_ID);
    logger.info("?-?ID:" + epid + ",ID" + orgID + ","
            + month + "," + rsType);

    Date reportMonth;
    try {
        reportMonth = TimeUtil.parseStringToDate(month, HttpConstant.MONTH_FORMAT);
    } catch (ParseException e) {
        logger.error("?-yyyyMM?" + e.getMessage());
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    if (reportMonth.after(TimeUtil.getLastMonthD())) {
        logger.info("?-??" + month + "?");
        throw new ApplicationException(ErrorConstant.ERROR10004, Response.Status.BAD_REQUEST);
    }

    if (!HttpConstant.REPORT_QY_D_SPEED.equals(rsType) && !HttpConstant.REPORT_QY_D_BAD.equals(rsType)
            && !HttpConstant.REPORT_QY_D_OIL.equals(rsType)) {
        logger.info("?-?" + rsType + "?[01,02,03]");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    if (CheckRequestParam.isEmpty(epid) || CheckRequestParam.isEmpty(orgID)) {
        logger.info("?--?IDID");
        throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
    }

    List<EpCarDtl> infos = stMapper.getCarMonthDtl(month, epid, rsType, orgID);
    if (CheckRequestParam.isEmpty(infos)) {
        logger.info("?-?ID:" + epid + "ID:" + orgID + "" + month
                + "" + rsType + "?");
        return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                .header("Pragma", "no-cache").build();
    }

    EpDtlResp result = new EpDtlResp();
    result.setDetailInfo(infos);
    return Response.ok(JacksonUtils.toJsonRuntimeException(result))
            .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build();
}

From source file:net.sf.json.xml.XMLSerializer.java

private JSON processArrayElement(Element element, String defaultType) {
    JSONArray jsonArray = new JSONArray();
    // process children (including text)
    int childCount = element.getChildCount();
    for (int i = 0; i < childCount; i++) {
        Node child = element.getChild(i);
        if (child instanceof Text) {
            Text text = (Text) child;
            if (StringUtils.isNotBlank(StringUtils.strip(text.getValue()))) {
                jsonArray.element(text.getValue());
            }/*  w  w w.  ja  v  a  2  s . co  m*/
        } else if (child instanceof Element) {
            setValue(jsonArray, (Element) child, defaultType);
        }
    }
    if (keepArrayName) {
        boolean isSameElementNameInArray = true;
        String arrayName = null;
        for (int i = 0; i < element.getChildElements().size(); i++) {
            final String arrayElement = element.getChildElements().get(i).getQualifiedName();
            if (arrayName == null) {
                arrayName = arrayElement;
            } else if (!arrayName.equals(arrayElement)) {
                isSameElementNameInArray = false;
            }
        }
        if (isSameElementNameInArray) {
            JSONObject result = new JSONObject();
            result.put(arrayName, jsonArray);
            return result;
        }
    }
    return jsonArray;
}

From source file:com.circle.utils.XMLSerializer.java

private JSON processObjectElement(Element element, String defaultType) {
    if (isNullObject(element)) {
        return JSONNull.getInstance();
    }/*from   w  w w .j  ava2 s .c  o  m*/
    JSONObject jsonObject = new JSONObject();

    if (!skipNamespaces) {
        for (int j = 0; j < element.getNamespaceDeclarationCount(); j++) {
            String prefix = element.getNamespacePrefix(j);
            String uri = element.getNamespaceURI(prefix);
            if (StringUtils.isBlank(uri)) {
                continue;
            }
            if (!StringUtils.isBlank(prefix)) {
                prefix = ":" + prefix;
            }
            setOrAccumulate(jsonObject, "@xmlns" + prefix, trimSpaceFromValue(uri));
        }
    }

    // process attributes first
    int attrCount = element.getAttributeCount();
    for (int i = 0; i < attrCount; i++) {
        Attribute attr = element.getAttribute(i);
        String attrname = attr.getQualifiedName();
        if (isTypeHintsEnabled() && (addJsonPrefix("class").compareToIgnoreCase(attrname) == 0
                || addJsonPrefix("type").compareToIgnoreCase(attrname) == 0)) {
            continue;
        }
        String attrvalue = attr.getValue();
        setOrAccumulate(jsonObject, "@" + removeNamespacePrefix(attrname), trimSpaceFromValue(attrvalue));
    }

    // process children (including text)
    int childCount = element.getChildCount();
    for (int i = 0; i < childCount; i++) {
        Node child = element.getChild(i);
        if (child instanceof Text) {
            Text text = (Text) child;
            if (StringUtils.isNotBlank(StringUtils.strip(text.getValue()))) {
                setOrAccumulate(jsonObject, "#text", trimSpaceFromValue(text.getValue()));
            }
        } else if (child instanceof Element) {
            setValue(jsonObject, (Element) child, defaultType);
        }
    }

    return jsonObject;
}

From source file:com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Convert OSGi Property storing Root content paths:Error page paths into a SortMap.
 *
 * @param paths/*from   w  w  w  .  j av a  2s  .c om*/
 * @return
 */
private SortedMap<String, String> configurePathMap(String[] paths) {
    SortedMap<String, String> sortedMap = new TreeMap<String, String>(new StringLengthComparator());

    for (String path : paths) {
        if (StringUtils.isBlank(path)) {
            continue;
        }

        final SimpleEntry<String, String> tmp = toSimpleEntry(path, ":");

        if (tmp == null) {
            continue;
        }

        String key = StringUtils.strip(tmp.getKey());
        String val = StringUtils.strip(tmp.getValue());

        // Only accept absolute paths
        if (StringUtils.isBlank(key) || !StringUtils.startsWith(key, "/")) {
            continue;
        }

        // Validate page name value
        if (StringUtils.isBlank(val)) {
            val = key + "/" + DEFAULT_ERROR_PAGE_NAME;
        } else if (StringUtils.equals(val, ".")) {
            val = key;
        } else if (!StringUtils.startsWith(val, "/")) {
            val = key + "/" + val;
        }

        sortedMap.put(key, val);
    }

    return sortedMap;
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRJobRequest.java

public List<List<String>> getValueRange(String tkn) {

    dbgLog.fine("received token=" + tkn);
    String step0 = StringUtils.strip(tkn);
    dbgLog.fine("step0=" + step0);

    // string into tokens
    String[] step1raw = step0.split(",");

    dbgLog.fine("step1raw=" + StringUtils.join(step1raw, ","));

    // remove meaningless commas if exist

    List<String> step1 = new ArrayList<String>();

    for (String el : step1raw) {
        if (!el.equals("")) {
            step1.add(el);//  www.  java 2 s .  c  o m
        }
    }

    dbgLog.fine("step1=" + StringUtils.join(step1, ","));

    List<List<String>> rangeData = new ArrayList<List<String>>();

    // for each token, check the range operator

    for (int i = 0; i < step1.size(); i++) {
        LinkedList<String> tmp = new LinkedList<String>(
                Arrays.asList(String2StringArray(String.valueOf(step1.get(i)))));

        Map<String, String> token = new HashMap<String, String>();
        boolean rangeMode = false;

        // .get(i) below CAN'T possibly be right (??) -- replacing
        // it with .get(0). -- L.A., v3.6
        //if ((!tmp.get(i).equals("[")) && (!tmp.get(i).equals("("))){
        if ((!tmp.get(0).equals("[")) && (!tmp.get(0).equals("("))) {
            // no LHS range operator
            // assume [
            token.put("start", "3");
        } else if (tmp.get(0).equals("[")) {
            rangeMode = true;
            token.put("start", "3");
            tmp.removeFirst();
        } else if (tmp.get(0).equals("(")) {
            rangeMode = true;
            token.put("start", "5");
            tmp.removeFirst();
        }

        if ((!tmp.getLast().equals("]")) && (!tmp.getLast().equals(")"))) {
            // no RHS range operator
            // assume ]
            token.put("end", "4");
        } else if (tmp.getLast().equals("]")) {
            rangeMode = true;
            tmp.removeLast();
            token.put("end", "4");
        } else if (tmp.getLast().equals(")")) {
            rangeMode = true;
            tmp.removeLast();
            token.put("end", "6");
        }

        // I'm now enforcing the following rules:
        // the "rangeMode" above - a range must have at least one range
        // operator, a square bracket or parenthesis, on one end, at
        // least; i.e., either on the left, or on the right. 
        // If there are no range operators, even if there are dashes
        // inside the token, they are not going to be interpreted as 
        // range definitions.  
        // still TODO: (possibly?) add more validation; figure out how 
        // to encode *date* ranges ("-" is not optimal, since dates already
        // contain dashes... although, since dates are (supposed to be) 
        // normalized it should still be possible to parse it unambiguously)
        //          -- L.A., v3.6

        if (rangeMode) {
            // after these steps, the string does not have range operators;
            // i.e., '-9--3', '--9', '-9-','-9', '-1-1', '1', '3-4', '6-'

            if ((tmp.get(0).equals("!")) && (tmp.get(1).equals("="))) {
                // != negation string is found
                token.put("start", "2");
                token.put("end", "");
                token.put("v1", StringUtils.join(tmp.subList(2, tmp.size()), ""));
                token.put("v2", "");
                dbgLog.fine("value=" + StringUtils.join(tmp.subList(2, tmp.size()), ","));

            } else if ((tmp.get(0).equals("-")) && (tmp.get(1).equals("-"))) {
                // type 2: --9
                token.put("v1", "");
                tmp.removeFirst();
                token.put("v2", StringUtils.join(tmp, ""));
            } else if ((tmp.get(0).equals("-")) && (tmp.getLast().equals("-"))) {
                // type 3: -9-
                token.put("v2", "");
                tmp.removeLast();
                token.put("v1", StringUtils.join(tmp, ""));
            } else if ((!tmp.get(0).equals("-")) && (tmp.getLast().equals("-"))) {
                // type 8: 6-
                token.put("v2", "");
                tmp.removeLast();
                token.put("v1", StringUtils.join(tmp, ""));
            } else {
                int count = 0;
                List<Integer> index = new ArrayList<Integer>();
                for (int j = 0; j < tmp.size(); j++) {
                    if (tmp.get(j).equals("-")) {
                        count++;
                        index.add(j);
                    }
                }

                if (count >= 2) {
                    // range type
                    // divide the second hyphen
                    // types 1 and 5: -9--3, -1-1
                    // token.put("v1", StringUtils.join(tmp[0..($index[1]-1)],"" ));
                    token.put("v2", StringUtils.join(tmp.subList((index.get(1) + 1), tmp.size()), ""));

                } else if (count == 1) {
                    if (tmp.get(0).equals("-")) {
                        // point negative type
                        // type 4: -9 or -inf,9
                        // do nothing
                        if ((token.get("start").equals("5"))
                                && ((token.get("end").equals("6")) || (token.get("end").equals("4")))) {
                            token.put("v1", "");
                            tmp.removeFirst();
                            token.put("v2", StringUtils.join(tmp, ""));
                        } else {
                            token.put("v1", StringUtils.join(tmp, ""));
                            token.put("v2", StringUtils.join(tmp, ""));
                        }
                    } else {
                        // type 7: 3-4
                        // both positive value and range type
                        String[] vset = (StringUtils.join(tmp, "")).split("-");
                        token.put("v1", vset[0]);
                        token.put("v2", vset[1]);
                    }

                } else {
                    // type 6: 1
                    token.put("v1", StringUtils.join(tmp, ""));
                    token.put("v2", StringUtils.join(tmp, ""));
                }
            }
        } else {
            // assume that this is NOT a range; treat the entire sequence 
            // of symbols as a single token:
            // type 6: 1
            token.put("v1", StringUtils.join(tmp, ""));
            token.put("v2", StringUtils.join(tmp, ""));
        }

        dbgLog.fine(i + "-th result=" + token.get("start") + "|" + token.get("v1") + "|" + token.get("end")
                + "|" + token.get("v2"));

        List<String> rangeSet = new ArrayList<String>();
        rangeSet.add(token.get("start"));
        rangeSet.add(token.get("v1"));
        rangeSet.add(token.get("end"));
        rangeSet.add(token.get("v2"));
        rangeData.add(rangeSet);

    }

    dbgLog.fine("rangeData:\n" + rangeData);
    return rangeData;
}

From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java

@Override
public String getFirstNameFree() {
    String base = UIRegistry.getResourceString("REP_NewReportName");
    int count = 0;
    javax.swing.JInternalFrame[] frames = getJMDIDesktopPane().getAllFrames();
    for (int f = 0; f < frames.length; f++) {
        if (frames[f] instanceof JReportFrame) {
            JReportFrame jrf = (JReportFrame) frames[f];
            String repName = jrf.getReport().getName();
            if (repName.equals(base)) {
                if (count == 0) {
                    count++;//from   ww w.ja  v  a2s  .  co  m
                }
            } else if (repName.startsWith(base)) {
                String end = repName.substring(base.length());
                try {
                    int endInt = Integer.valueOf(StringUtils.strip(end));
                    if (endInt > count) {
                        count = endInt;
                    }
                } catch (NumberFormatException ex) {
                    //skip it
                }
            }
        }
    }
    return base + (count > 0 ? " " + ++count : "");
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImpl.java

/**
 * Returns the Parent name by passing a hierarchical name, or null if not found.
 * //from  w w  w .jav  a 2s .  co m
 * @param nameHierarchy
 * @param nameNonHierarchy
 *          If passed (not null), checks that this is the name contained in the other parameter, returning null on mismatch.
 */
String getParentNameFromHierarchicalName(String nameHierarchy, String nameNonHierarchy,
        String cellCoordinates) {
    if (nameHierarchy == null) {
        return null;
    }

    // If there is at least one :, there is a parent
    final String hierarchySeparator = Constants.HIERARCHYSEP.trim();

    if (nameHierarchy.contains(hierarchySeparator)) {
        // Only verify the name if this parameter was passed
        if (nameNonHierarchy != null) {
            String nameNonHierarchyFound = StringUtils.substringAfterLast(nameHierarchy, hierarchySeparator);
            nameNonHierarchyFound = StringUtils.strip(nameNonHierarchyFound);

            // Check if the Name part of the Hierarchy is the one we expected
            if (!nameNonHierarchyFound.equalsIgnoreCase(nameNonHierarchy)) {
                getProcessingLog().warn(
                        "Hierarchical Name \"{0}\" in cell [{1}] does not contain the name of the BuildingBlock it belongs to ({2}). Not setting parent!",
                        nameHierarchy, cellCoordinates, nameNonHierarchy);
                return null;
            }
        }
        String allBeforeName = StringUtils.substringBeforeLast(nameHierarchy, hierarchySeparator);
        allBeforeName = StringUtils.strip(allBeforeName);

        // Strip grandparents+ if necessary
        if (allBeforeName.contains(hierarchySeparator)) {
            return StringUtils.substringAfterLast(allBeforeName, Constants.HIERARCHYSEP).trim();
        }
        return allBeforeName;
    }
    return null;
}