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

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

Introduction

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

Prototype

public static String trimToNull(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

Usage

From source file:com.opengamma.web.portfolio.WebPortfoliosResource.java

private FlexiBean createSearchResultData(PagingRequest pr, PortfolioSearchSortOrder sort, String name,
        List<String> portfolioIdStrs, List<String> nodeIdStrs, Boolean includeHidden) {
    FlexiBean out = createRootData();//  w ww .  j  av a 2  s. com

    PortfolioSearchRequest searchRequest = new PortfolioSearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setSortOrder(sort);
    searchRequest.setName(StringUtils.trimToNull(name));
    searchRequest.setDepth(1); // see PLAT-1733, also, depth is set to 1 for knowing # of childNodes for UI tree
    searchRequest.setIncludePositions(true); // initially false because of PLAT-2012, now true for portfolio tree
    if (BooleanUtils.isTrue(includeHidden)) {
        searchRequest.setVisibility(DocumentVisibility.HIDDEN);
    }
    for (String portfolioIdStr : portfolioIdStrs) {
        searchRequest.addPortfolioObjectId(ObjectId.parse(portfolioIdStr));
    }
    for (String nodeIdStr : nodeIdStrs) {
        searchRequest.addNodeObjectId(ObjectId.parse(nodeIdStr));
    }
    out.put("searchRequest", searchRequest);

    if (data().getUriInfo().getQueryParameters().size() > 0) {
        PortfolioSearchResult searchResult = data().getPortfolioMaster().search(searchRequest);
        out.put("searchResult", searchResult);
        out.put("paging", new WebPaging(searchResult.getPaging(), data().getUriInfo()));
    }
    return out;
}

From source file:mitm.application.djigzo.james.mailets.DKIMVerify.java

@Override
protected void initMailet() throws MessagingException {
    dkimHeader = getInitParameter(Parameter.DKIM_HEADER.name, DKIMCommon.DEFAULT_DKIM_HEADER);

    resultMailAttribute = StringUtils.trimToNull(getInitParameter(Parameter.RESULT_MAIL_ATTRIBUTE.name));

    if (resultMailAttribute == null) {
        throw new MessagingException("resultAttribute is missing.");
    }//from  w w w.j a  v  a  2s.  c om

    loadPublicKey();
}

From source file:net.leegorous.jsc.JSC.java

public String process(String cp, String path, String outputType, String output) {
    if (OUTPUT_FILE.equals(outputType) && output == null) {
        throw new IllegalArgumentException("property 'output' could not be null when output to 'file'");
    }// ww w . ja va  2 s . c o  m

    path = StringUtils.trimToNull(path);
    if (path == null)
        return null;

    JsContextManager mgr = getJsContextMgr();
    String root = getRealPath("/");
    log.debug(root);
    addClasspath(mgr, root, cp);

    JsContext ctx = mgr.createContext();

    List li = normalizePath(path);
    for (Iterator it = li.iterator(); it.hasNext();) {
        String item = (String) it.next();
        try {
            ctx.buildHierarchy(item);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    List list = null;
    try {
        JsNode node = ctx.getHierarchy();
        list = node.serialize();
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }

    for (Iterator it = list.iterator(); it.hasNext();) {
        ((JsNode) it.next()).getFile().setWebRoot(root);
    }

    OutputBuilder builder = null;
    if (OUTPUT_ARRAY.equals(outputType)) {
        builder = new ArrayFormBuilder();
    } else if (OUTPUT_FILE.equals(outputType)) {
        builder = new FileFormBuilder(output, pathResolver);
    } else {
        builder = new TagsFormBuilder();
    }
    return builder.build(list);
}

From source file:com.opengamma.web.portfolio.WebPortfolioNodeResource.java

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)// w w  w. j a  v  a  2  s  . c o  m
public Response putHTML(@FormParam("name") String name) {
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }
    name = StringUtils.trimToNull(name);
    if (name == null) {
        FlexiBean out = createRootData();
        out.put("err_nameMissing", true);
        String html = getFreemarker().build(HTML_DIR + "portfolionode-update.ftl", out);
        return Response.ok(html).build();
    }
    URI uri = updatePortfolioNode(name, doc);
    return Response.seeOther(uri).build();
}

From source file:com.opengamma.web.config.WebConfigResource.java

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)/*from w  w w.j  av  a  2s. c  o  m*/
public Response putJSON(@FormParam("name") String name, @FormParam("configJSON") String json,
        @FormParam("configXML") String xml) {
    if (data().getConfig().isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }

    name = StringUtils.trimToNull(name);
    json = StringUtils.trimToNull(json);
    xml = StringUtils.trimToNull(xml);
    // JSON allows a null config to just change the name
    if (name == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Object configValue = null;
    if (json != null) {
        configValue = parseJSON(json);
    } else if (xml != null) {
        Object parsed = parseXML(xml, data().getConfig().getConfig().getType());
        configValue = parsed;
    }
    updateConfig(name, configValue);
    return Response.ok().build();
}

From source file:ips1ap101.lib.core.util.ClassX.java

public String subclassName(Class<?> baseClass, String subclassType) {
    Bitacora.trace(ClassX.class, "subclassName", baseClass, subclassType);
    if (baseClass == null) {
        throw new IllegalArgumentException();
    }/*from ww  w . jav  a  2  s. co  m*/
    String sp, ss;
    String st = StringUtils.trimToNull(subclassType);
    if (st == null) {
        sp = PACKAGE;
        ss = SUFFIX;
    } else {
        sp = st + "_" + PACKAGE;
        ss = st + "_" + SUFFIX;
    }
    sp = CoreBundle.getString(SIMPLE, sp);
    ss = CoreBundle.getString(SIMPLE, ss);
    return baseClass.getPackage().getName() + "." + sp + "." + baseClass.getSimpleName() + ss;
}

From source file:com.opengamma.master.region.impl.UnLocodeRegionFileReader.java

private Set<ManageableRegion> parseLocodes(Reader in, Set<String> required) {
    Set<ManageableRegion> regions = new HashSet<ManageableRegion>(1024, 0.75f);
    String name = null;//from w  w w. j  a  va2s  .  c o  m
    try {
        @SuppressWarnings("resource")
        CSVReader reader = new CSVReader(in);
        final int typeIdx = 0;
        final int countryIsoIdx = 1;
        final int unlocodePartIdx = 2;
        final int nameColumnIdx = 4;
        final int fullNameColumnIdx = 3;

        String[] row = null;
        while ((row = reader.readNext()) != null) {
            if (row.length < 9) {
                continue;
            }
            name = StringUtils.trimToNull(row[nameColumnIdx]);
            String type = StringUtils.trimToNull(row[typeIdx]);
            String fullName = StringUtils.trimToNull(row[fullNameColumnIdx]);
            fullName = Objects.firstNonNull(fullName, name);
            String countryISO = StringUtils.trimToNull(row[countryIsoIdx]);
            String unlocodePart = StringUtils.trimToNull(row[unlocodePartIdx]);
            String unlocode = countryISO + unlocodePart;
            if (StringUtils.isEmpty(name) || StringUtils.isEmpty(fullName) || StringUtils.isEmpty(countryISO)
                    || StringUtils.isEmpty(unlocodePart) || unlocode.length() != 5 || countryISO.equals("XZ")
                    || "=".equals(type) || required.remove(unlocode) == false) {
                continue;
            }

            ManageableRegion region = createRegion(name, fullName, countryISO);
            region.addExternalId(ExternalSchemes.unLocode20102RegionId(unlocode));
            regions.add(region);
        }
    } catch (Exception ex) {
        String detail = (name != null ? " while processing " + name : "");
        throw new OpenGammaRuntimeException("Unable to read UN/LOCODEs" + detail, ex);
    }
    if (required.size() > 0) {
        throw new OpenGammaRuntimeException("Requested UN/LOCODEs could not be found: " + required);
    }
    return regions;
}

From source file:com.ms.commons.test.classloader.util.SimpleAntxLoader.java

protected List<String> getSvnUrlList(Properties p) {
    List<String> svnUrlList = new ArrayList<String>();
    String mark = p.getProperty(ANTX_PROPERTIES);
    if (StringUtils.trimToNull(mark) == null) {
        mark = ANTX_PROPERTIES_DEFAULT;/*from  w  w  w . j  a  v a 2 s .  co  m*/
    }
    if (StringUtils.isNotBlank(mark)) {
        String plusMark = ANTX_PROPERTIES + "." + StringUtils.trim(mark);

        for (Object key : p.keySet()) {
            String k = (key == null) ? "" : key.toString();
            if (k.startsWith(plusMark)) {
                String svnUrl = StringUtils.trimToNull(p.getProperty(k));
                svnUrlList.add(svnUrl);
            }
        }
    }
    if (!svnUrlList.isEmpty()) {
        System.err.println("Load svn urls: " + svnUrlList);
    }
    return svnUrlList;
}

From source file:com.manydesigns.elements.fields.search.DateSearchField.java

@Override
public void readFromRequest(HttpServletRequest req) {
    minStringValue = StringUtils.trimToNull(req.getParameter(minInputName));
    try {// w  w w. jav a2  s.c o m
        DateTime dateTime = dateTimeFormatter.parseDateTime(minStringValue);
        minValue = new Date(dateTime.getMillis());
    } catch (Throwable e) {
        minValue = null;
    }

    maxStringValue = StringUtils.trimToNull(req.getParameter(maxInputName));
    try {
        DateTime dateTime = dateTimeFormatter.parseDateTime(maxStringValue);
        maxValue = new Date(dateTime.getMillis());
    } catch (Throwable e) {
        maxValue = null;
    }

    searchNullValue = (NULL_VALUE.equals(minStringValue) || NULL_VALUE.equals(maxStringValue));
}

From source file:com.haulmont.cuba.web.app.folders.AppFolderEditWindow.java

@Override
protected void commit() {
    AppFolder folder = (AppFolder) AppFolderEditWindow.this.folder;
    if (StringUtils.trimToNull(nameField.getValue()) == null) {
        String msg = messages.getMessage(messagesPack, "folders.folderEditWindow.emptyName");
        App.getInstance().getWindowManager().showNotification(msg, Frame.NotificationType.TRAY);
        return;//from   w ww .  ja  va 2 s  . c o  m
    }
    folder.setName(nameField.getValue());
    folder.setTabName(tabNameField.getValue());

    if (sortOrderField.getValue() == null || "".equals(sortOrderField.getValue())) {
        folder.setSortOrder(null);
    } else {
        Object value = sortOrderField.getValue();
        int sortOrder;
        try {
            sortOrder = Integer.parseInt((String) value);
        } catch (NumberFormatException e) {
            String msg = messages.getMessage(messagesPack, "folders.folderEditWindow.invalidSortOrder");
            App.getInstance().getWindowManager().showNotification(msg, Frame.NotificationType.TRAY);
            return;
        }
        folder.setSortOrder(sortOrder);
    }

    Object parent = parentSelect.getValue();
    if (parent instanceof Folder) {
        folder.setParent((Folder) parent);
    } else {
        folder.setParent(null);
    }

    if (visibilityScriptField != null) {
        String scriptText = visibilityScriptField.getValue();
        folder.setVisibilityScript(scriptText);
    }
    if (quantityScriptField != null) {
        String scriptText = quantityScriptField.getValue();
        folder.setQuantityScript(scriptText);
    }
    folder.setApplyDefault(Boolean.valueOf(applyDefaultCb.getValue().toString()));

    AppFolderEditWindow.this.commitHandler.run();

    close();
}