List of usage examples for org.apache.commons.lang3 StringUtils defaultString
public static String defaultString(final String str)
Returns either the passed in String, or if the String is null , an empty String ("").
StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"
From source file:de.micromata.genome.tpsb.httpmockup.MockHttpServletRequest.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); String p = joinpath(joinpath(contextPath, servletPath), pathInfo) + StringUtils.defaultString(queryString); sb.append(method).append(" ").append(p).append(" HTTP/1.1\n"); for (Map.Entry<String, Object> me : headers.entrySet()) { sb.append(me.getKey()).append(": ").append(me.getValue()).append("\n"); }/* w w w .j a v a 2s .c o m*/ sb.append("\n"); if (this.requestData != null) { sb.append(new String(this.requestData)); } return sb.toString(); }
From source file:de.gbv.ole.Marc21ToOleBulk.java
/** * Holt den Wert aus dem angegebenen Subfeld, macht trim(), * liefert "" statt null./* w ww .j a v a2s . c om*/ * @param field MARC-Feld, in dem nach dem Subfeld gesucht wird * @param subfieldName Name des gesuchten Subfeldes * @return gesuchter Wert */ final static String optionalSubfield(final DataField field, char subfieldName) { Subfield subfield = field.getSubfield(subfieldName); if (subfield == null) { return ""; } return StringUtils.defaultString(subfield.getData()).trim(); }
From source file:com.pidoco.juri.JURI.java
/** * Doesn't decode the path segments./* ww w. j a v a 2 s.com*/ * @return a new list that the caller may manipulate. Empty string if no path or the root path is set. Returns * empty path segments (//as//df// has three empty * segments). */ public ArrayList<String> getRawPathSegments() { return splitRawPath(StringUtils.defaultString(getRawPath())); }
From source file:com.netsteadfast.greenstep.util.MenuSupportUtils.java
/** * ??/*from w w w . j av a 2 s .c o m*/ * * @param basePath * @param sys * @return * @throws ServiceException * @throws Exception */ public static Map<String, String> getMenuData(String basePath, TbSys sys, String jsessionId, String localeCode) throws ServiceException, Exception { Map<String, String> menuData = new HashMap<String, String>(); List<SysMenuVO> menuList = loadSysMenuData(sys.getSysId()); if (menuList == null || menuList.size() < 1) { return menuData; } StringBuilder htmlSb = new StringBuilder(); StringBuilder jsSb = new StringBuilder(); StringBuilder dlgSb = new StringBuilder(); Map<String, String> jsFunctionMap = new HashMap<String, String>(); /* for (SysMenuVO sysMenu : menuList) { // create combobox menu javascript if (!YesNo.YES.equals(sysMenu.getEnableFlag())) { continue; } if (TYPE_IS_FOLDER.equals(sysMenu.getItemType())) { // ?? continue; } String openTabFn = sysMenu.getProgId() + "_TabShow()"; String refreshTabFn = sysMenu.getProgId() + "_TabRefresh()"; String closeTabFn = sysMenu.getProgId() + "_TabClose()"; String tabId = sysMenu.getProgId() + "_ChildTab"; jsSb.append("function ").append( openTabFn ).append(" { "); jsSb.append(" viewPage.addOrUpdateContentPane( "); jsSb.append(" '").append(Constants.MAIN_TabContainer_ID).append("', "); jsSb.append(" '").append(tabId).append("', "); jsSb.append(" '").append( StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysMenu.getIcon()) ) ).append(StringEscapeUtils.escapeEcmaScript(sysMenu.getName())).append("', "); jsSb.append(" '").append( getUrl(basePath, sys, sysMenu, jsessionId) ).append("', "); jsSb.append(" true, "); jsSb.append(" true"); jsSb.append(" ); "); jsSb.append("} "); jsSb.append("\n"); jsSb.append("function ").append( refreshTabFn ).append(" { "); jsSb.append(" viewPage.refreshContentPane('").append(tabId).append("'); "); jsSb.append("} "); jsSb.append("\n"); jsSb.append("function ").append( closeTabFn ).append(" { "); jsSb.append(" viewPage.closeContentPane('").append(Constants.MAIN_TabContainer_ID).append("', '").append(tabId).append("'); "); jsSb.append("} "); jsSb.append("\n"); jsFunctionMap.put(sysMenu.getProgId(), openTabFn ); } */ Map<String, Object> params = new HashMap<String, Object>(); params.put("progSystem", sys.getSysId()); List<TbSysProg> sysProgList = sysProgService.findListByParams(params); for (int i = 0; sysProgList != null && i < sysProgList.size(); i++) { TbSysProg sysProg = sysProgList.get(i); if (MenuItemType.FOLDER.equals(sysProg.getItemType())) { // ?? continue; } String openTabFn = sysProg.getProgId() + "_TabShow()"; if (YesNo.YES.equals(sysProg.getEditMode())) { openTabFn = sysProg.getProgId() + "_TabShow(oid)"; } String refreshTabFn = sysProg.getProgId() + "_TabRefresh()"; String closeTabFn = sysProg.getProgId() + "_TabClose()"; String tabId = sysProg.getProgId() + "_ChildTab"; boolean iframeMode = false; if (YesNo.YES.equals(sysProg.getIsWindow())) { iframeMode = true; } String progMultiName = getProgramMultiName(sysProg, localeCode); jsSb.append("function ").append(openTabFn).append(" { "); jsSb.append(" viewPage.addOrUpdateContentPane( "); jsSb.append(" '").append(Constants.MAIN_TabContainer_ID).append("', "); jsSb.append(" '").append(tabId).append("', "); //jsSb.append(" '").append( StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysProg.getIcon()) ) ).append(StringEscapeUtils.escapeEcmaScript(sysProg.getName())).append("', "); jsSb.append(" '") .append(StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysProg.getIcon()))) .append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("', "); // ??? if (YesNo.YES.equals(sysProg.getEditMode())) { // Edit ? jsSb.append(" '").append(getUrl(basePath, sys, sysProg, jsessionId)) .append("&fields.oid=' + oid, "); } else { // Query Create ? jsSb.append(" '").append(getUrl(basePath, sys, sysProg, jsessionId)).append("', "); } jsSb.append(" true, "); jsSb.append(" true, "); jsSb.append(" ").append(String.valueOf(iframeMode)).append(" "); jsSb.append(" ); "); jsSb.append("} "); jsSb.append("\n"); jsSb.append("function ").append(refreshTabFn).append(" { "); jsSb.append(" viewPage.refreshContentPane('").append(tabId).append("'); "); jsSb.append("} "); jsSb.append("\n"); jsSb.append("function ").append(closeTabFn).append(" { "); jsSb.append(" viewPage.closeContentPane('").append(Constants.MAIN_TabContainer_ID).append("', '") .append(tabId).append("'); "); jsSb.append("} "); jsSb.append("\n"); //jsSb.append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("['").append( sysProg.getProgId() ).append("'] = '").append( StringEscapeUtils.escapeEcmaScript( sysProg.getName() ) ).append("';"); jsSb.append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("['").append(sysProg.getProgId()) .append("'] = '").append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("';"); // ??? jsSb.append("\n"); jsFunctionMap.put(sysProg.getProgId(), openTabFn); String dlgId = ""; if (YesNo.YES.equals(sysProg.getIsDialog())) { dlgId = sysProg.getProgId() + "_Dlg"; } if (!StringUtils.isBlank(dlgId)) { // dialog dlgSb.append("<div id=\"" + dlgId + "\" data-dojo-type=\"dojox.widget.DialogSimple\" ") .append("data-dojo-props='href:\"").append(getUrl(basePath, sys, sysProg, jsessionId)) .append("\",").append(" style:\"width: ").append(sysProg.getDialogW()) .append("px; height: ").append(sysProg.getDialogH()).append("px\",") //.append(" title:\"").append( IconUtils.getMenuIcon(basePath, sysProg.getIcon()).replaceAll("'", "\\\\\"") ).append( StringEscapeUtils.escapeEcmaScript(sysProg.getName()) ).append("\",") .append(" title:\"") .append(IconUtils.getMenuIcon(basePath, sysProg.getIcon()).replaceAll("'", "\\\\\"")) .append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("\",") // ??? .append(" refreshOnShow:\"true\", executeScripts:\"true\" ").append(" '></div>") .append("\n"); String dlgOpenFn = sysProg.getProgId() + "_DlgShow()"; String dlgHideFn = sysProg.getProgId() + "_DlgHide()"; if (YesNo.YES.equals(sysProg.getEditMode())) { dlgOpenFn = sysProg.getProgId() + "_DlgShow(oid)"; } jsSb.append("function ").append(dlgOpenFn).append(" { "); String dlgUrl = ""; if (YesNo.YES.equals(sysProg.getEditMode())) { // Edit ? dlgUrl = "'" + getUrl(basePath, sys, sysProg, jsessionId) + "&fields.oid=' + oid; "; jsSb.append(" var dlgUrl=").append(dlgUrl); jsSb.append(" dijit.byId('").append(dlgId).append("').set('href', dlgUrl); "); } jsSb.append(" dijit.byId('").append(dlgId).append("').show(); "); jsSb.append("} "); jsSb.append("\n"); jsSb.append("function ").append(dlgHideFn).append(" { "); jsSb.append(" dijit.byId('").append(dlgId).append("').hide(); "); jsSb.append("} "); jsSb.append("\n"); } } // create combobox menu html htmlSb.append("<div data-dojo-type='dijit.PopupMenuItem' >"); //htmlSb.append(" <span>").append( IconUtils.getMenuIcon(basePath, sys.getIcon()) ).append(sys.getName()).append("</span>"); htmlSb.append(" <span>").append(IconUtils.getMenuIcon(basePath, sys.getIcon())) .append(getSystemMultiName(sys, localeCode)).append("</span>"); // List<SysMenuVO> parentSysMenuList = searchFolder(menuList); htmlSb.append("<div dojoType='dijit.Menu' >"); for (SysMenuVO sysMenu : parentSysMenuList) { List<SysMenuVO> itemSysMenuList = searchItem(sysMenu.getOid(), menuList); if (itemSysMenuList == null || itemSysMenuList.size() < 1) { continue; } String multiProgName = getProgramMultiName(sysMenu, localeCode); htmlSb.append("<div data-dojo-type='dijit.PopupMenuItem' >"); //htmlSb.append("<span>").append( IconUtils.getMenuIcon(basePath, sysMenu.getIcon()) ).append(sysMenu.getName()).append("</span>"); htmlSb.append("<span>").append(IconUtils.getMenuIcon(basePath, sysMenu.getIcon())).append(multiProgName) .append("</span>"); // htmlSb.append("<div data-dojo-type='dijit.Menu' >"); for (SysMenuVO itemMenu : itemSysMenuList) { String itemMultiProgName = getProgramMultiName(itemMenu, localeCode); htmlSb.append("<div data-dojo-type='dijit.MenuItem' data-dojo-props='onClick:function(){ ") .append(StringUtils.defaultString(jsFunctionMap.get(itemMenu.getProgId()))).append(" }'>") .append(IconUtils.getMenuIcon(basePath, itemMenu.getIcon())) //.append(itemMenu.getName()) .append(itemMultiProgName) // .append("</div>"); } htmlSb.append("</div>"); htmlSb.append("</div>"); } htmlSb.append("</div>"); htmlSb.append("</div>"); menuData.put(MENU_ITEM_JAVASCRIPT, jsSb.toString()); menuData.put(MENU_ITEM_HTML, htmlSb.toString()); menuData.put(MENU_ITEM_DIALOG, dlgSb.toString()); return menuData; }
From source file:ca.uhn.fhir.rest.server.RestfulServer.java
protected void handleRequest(RequestTypeEnum theRequestType, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException { String fhirServerBase = null; ServletRequestDetails requestDetails = new ServletRequestDetails(); requestDetails.setServer(this); requestDetails.setRequestType(theRequestType); requestDetails.setServletRequest(theRequest); requestDetails.setServletResponse(theResponse); theRequest.setAttribute(SERVLET_CONTEXT_ATTRIBUTE, getServletContext()); try {//w w w .jav a2s. c o m /* *********************************** * Parse out the request parameters * ***********************************/ String requestFullPath = StringUtils.defaultString(theRequest.getRequestURI()); String servletPath = StringUtils.defaultString(theRequest.getServletPath()); StringBuffer requestUrl = theRequest.getRequestURL(); String servletContextPath = IncomingRequestAddressStrategy.determineServletContextPath(theRequest, this); /* * Just for debugging.. */ if (ourLog.isTraceEnabled()) { ourLog.trace("Request FullPath: {}", requestFullPath); ourLog.trace("Servlet Path: {}", servletPath); ourLog.trace("Request Url: {}", requestUrl); ourLog.trace("Context Path: {}", servletContextPath); } String completeUrl; Map<String, String[]> params = null; if (StringUtils.isNotBlank(theRequest.getQueryString())) { completeUrl = requestUrl + "?" + theRequest.getQueryString(); /* * By default, we manually parse the request params (the URL params, or the body for * POST form queries) since Java containers can't be trusted to use UTF-8 encoding * when parsing. Specifically Tomcat 7 and Glassfish 4.0 use 8859-1 for some dumb * reason.... grr..... */ if (isIgnoreServerParsedRequestParameters()) { String contentType = theRequest.getHeader(Constants.HEADER_CONTENT_TYPE); if (theRequestType == RequestTypeEnum.POST && isNotBlank(contentType) && contentType.startsWith(Constants.CT_X_FORM_URLENCODED)) { String requestBody = new String(requestDetails.loadRequestContents(), Constants.CHARSET_UTF8); params = UrlUtil.parseQueryStrings(theRequest.getQueryString(), requestBody); } else if (theRequestType == RequestTypeEnum.GET) { params = UrlUtil.parseQueryString(theRequest.getQueryString()); } } } else { completeUrl = requestUrl.toString(); } if (params == null) { params = new HashMap<String, String[]>(theRequest.getParameterMap()); } requestDetails.setParameters(params); /* ************************* * Notify interceptors about the incoming request * *************************/ for (IServerInterceptor next : myInterceptors) { boolean continueProcessing = next.incomingRequestPreProcessed(theRequest, theResponse); if (!continueProcessing) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; } } String requestPath = getRequestPath(requestFullPath, servletContextPath, servletPath); if (requestPath.length() > 0 && requestPath.charAt(0) == '/') { requestPath = requestPath.substring(1); } fhirServerBase = getServerBaseForRequest(theRequest); IIdType id; populateRequestDetailsFromRequestPath(requestDetails, requestPath); if (theRequestType == RequestTypeEnum.PUT) { String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION); if (contentLocation != null) { id = myFhirContext.getVersion().newIdType(); id.setValue(contentLocation); requestDetails.setId(id); } } String acceptEncoding = theRequest.getHeader(Constants.HEADER_ACCEPT_ENCODING); boolean respondGzip = false; if (acceptEncoding != null) { String[] parts = acceptEncoding.trim().split("\\s*,\\s*"); for (String string : parts) { if (string.equals("gzip")) { respondGzip = true; } } } requestDetails.setRespondGzip(respondGzip); requestDetails.setRequestPath(requestPath); requestDetails.setFhirServerBase(fhirServerBase); requestDetails.setCompleteUrl(completeUrl); // String pagingAction = theRequest.getParameter(Constants.PARAM_PAGINGACTION); // if (getPagingProvider() != null && isNotBlank(pagingAction)) { // requestDetails.setRestOperationType(RestOperationTypeEnum.GET_PAGE); // if (theRequestType != RequestTypeEnum.GET) { // /* // * We reconstruct the link-self URL using the request parameters, and this would break if the parameters came // in using a POST. We could probably work around that but why bother unless // * someone comes up with a reason for needing it. // */ // throw new InvalidRequestException(getFhirContext().getLocalizer().getMessage(RestfulServer.class, // "getPagesNonHttpGet")); // } // handlePagingRequest(requestDetails, theResponse, pagingAction); // return; // } BaseMethodBinding<?> resourceMethod = determineResourceMethod(requestDetails, requestPath); requestDetails.setRestOperationType(resourceMethod.getRestOperationType()); // Handle server interceptors for (IServerInterceptor next : myInterceptors) { boolean continueProcessing = next.incomingRequestPostProcessed(requestDetails, theRequest, theResponse); if (!continueProcessing) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; } } /* * Actualy invoke the server method. This call is to a HAPI method binding, which * is an object that wraps a specific implementing (user-supplied) method, but * handles its input and provides its output back to the client. * * This is basically the end of processing for a successful request, since the * method binding replies to the client and closes the response. */ Closeable outputStreamOrWriter = (Closeable) resourceMethod.invokeServer(this, requestDetails); for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); next.processingCompletedNormally(requestDetails); } if (outputStreamOrWriter != null) { outputStreamOrWriter.close(); } } catch (NotModifiedException e) { for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); if (!next.handleException(requestDetails, e, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; } } writeExceptionToResponse(theResponse, e); } catch (AuthenticationException e) { for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); if (!next.handleException(requestDetails, e, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; } } writeExceptionToResponse(theResponse, e); } catch (Throwable e) { /* * We have caught an exception during request processing. This might be because a handling method threw * something they wanted to throw (e.g. UnprocessableEntityException because the request * had business requirement problems) or it could be due to bugs (e.g. NullPointerException). * * First we let the interceptors have a crack at converting the exception into something HAPI can use * (BaseServerResponseException) */ BaseServerResponseException exception = null; for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); exception = next.preProcessOutgoingException(requestDetails, e, theRequest); if (exception != null) { ourLog.debug("Interceptor {} returned false, not continuing processing"); break; } } /* * If none of the interceptors converted the exception, default behaviour is to keep the exception as-is if it * extends BaseServerResponseException, otherwise wrap it in an * InternalErrorException. */ if (exception == null) { exception = DEFAULT_EXCEPTION_HANDLER.preProcessOutgoingException(requestDetails, e, theRequest); } /* * Next, interceptors get a shot at handling the exception */ for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); if (!next.handleException(requestDetails, exception, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; } } /* * If we're handling an exception, no summary mode should be applied */ requestDetails.getParameters().remove(Constants.PARAM_SUMMARY); requestDetails.getParameters().remove(Constants.PARAM_ELEMENTS); /* * If nobody handles it, default behaviour is to stream back the OperationOutcome to the client. */ DEFAULT_EXCEPTION_HANDLER.handleException(requestDetails, exception, theRequest, theResponse); } }
From source file:com.pidoco.juri.JURI.java
/** * * @param fragment null or "" clears the fragment part *//*ww w . j av a 2s .c om*/ public JURI setFragment(@Nullable String fragment) { startChange(); this.fragment = StringUtils.defaultString(fragment); changed(); return this; }
From source file:com.github.helenusdriver.driver.impl.StatementImpl.java
/** * {@inheritDoc}//from w w w .j a v a2 s .c om * * @author paouelle * * @see java.lang.Object#toString() */ @Override public String toString() { return StringUtils.defaultString(getQueryString()); }
From source file:com.feilong.core.net.ParamUtil.java
/** * ?keysvalue,?(<span style="color:red">?</span>). * //w ww . j a va2 s . co m * <p> * includeKeys?,? () ??<br> * mapvaluenull,{@link StringUtils#EMPTY} * </p> * * <h3>:</h3> * <blockquote> * * <pre class="code"> * Map{@code <String, String>} map = new HashMap{@code <String, String>}(); * map.put("service", "create_salesorder"); * map.put("paymentType", "unionpay_mobile"); * * LOGGER.info(ParamUtil.joinValues(map, "service", "paymentType")); * </pre> * * <b>:</b> * * <pre class="code"> * create_salesorderunionpay_mobile * </pre> * * </blockquote> * * @param <K> * the key type * @param singleValueMap * the map * @param includeKeys * ?key * @return <code>singleValueMap</code> null, {@link NullPointerException}<br> * <code>includeKeys</code> nullempty, {@link StringUtils#EMPTY}<br> * ? <code>includeKeys</code>,? <code>singleValueMap</code>?,?;<br> * ( <code>singleValueMap</code>keynull,{@link StringUtils#defaultString(String)} ?{@link StringUtils#EMPTY})<br> * @see org.apache.commons.lang3.StringUtils#defaultString(String) * @since 1.5.5 */ @SafeVarargs public static <K> String joinValuesOrderByIncludeKeys(Map<K, String> singleValueMap, K... includeKeys) { Validate.notNull(singleValueMap, "singleValueMap can't be null!"); if (isNullOrEmpty(includeKeys)) { return EMPTY; } StringBuilder sb = new StringBuilder(); for (K key : includeKeys) {//?? //?: valuenull,StringBuilder "null" , ? java.lang.AbstractStringBuilder#append(String) sb.append(StringUtils.defaultString(singleValueMap.get(key))); } return sb.toString(); }
From source file:com.pidoco.juri.JURI.java
public static Multimap<String, String> parseQueryParameters(URI uri) { return parseQueryParameters(StringUtils.defaultString(uri.getRawQuery())); }
From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.action.WorkflowPopupActionBean.java
/** * applies change comment to page//from ww w . j a va 2s . c o m */ private void applyComment() { Map<String, GWikiArtefakt<?>> map = new HashMap<String, GWikiArtefakt<?>>(); page.collectParts(map); GWikiArtefakt<?> artefakt = map.get("ChangeComment"); if (artefakt instanceof GWikiChangeCommentArtefakt == false) { return; } GWikiChangeCommentArtefakt commentArtefakt = (GWikiChangeCommentArtefakt) artefakt; String oldText = commentArtefakt.getStorageData(); String ntext; String uname = wikiContext.getWikiWeb().getAuthorization().getCurrentUserName(wikiContext); int prevVersion = page.getElementInfo().getProps().getIntValue(GWikiPropKeys.VERSION, 0); if (StringUtils.isNotBlank(comment) == true) { Date now = new Date(); ntext = "{changecomment:modifiedBy=" + uname + "|modifiedAt=" + GWikiProps.date2string(now) + "|version=" + (prevVersion + 1) + "}\n" + comment + "\n{changecomment}\n" + StringUtils.defaultString(oldText); } else { ntext = oldText; } ntext = StringUtils.trimToNull(ntext); commentArtefakt.setStorageData(ntext); }