List of usage examples for org.apache.commons.lang StringUtils defaultString
public static String defaultString(String str)
Returns either the passed in String, or if the String is null
, an empty String ("").
From source file:org.codice.ddf.security.filter.websso.WebSSOFilter.java
private void handleRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain filterChain, List<AuthenticationHandler> handlers) throws IOException, ServletException { if (handlers.size() == 0) { LOGGER.warn("Handlers not ready. Returning status code 503, Service Unavailable."); returnSimpleResponse(HttpServletResponse.SC_SERVICE_UNAVAILABLE, httpResponse); return;/*from w w w . j a v a 2s. co m*/ } // First pass, see if anyone can come up with proper security token from the get-go HandlerResult result = null; LOGGER.debug("Checking for existing tokens in request."); for (AuthenticationHandler auth : handlers) { result = auth.getNormalizedToken(httpRequest, httpResponse, filterChain, false); if (result.getStatus() != HandlerResult.Status.NO_ACTION) { LOGGER.debug("Handler {} set the result status to {}", auth.getAuthenticationType(), result.getStatus()); break; } } // If we haven't received usable credentials yet, go get some if (result == null || result.getStatus() == HandlerResult.Status.NO_ACTION) { LOGGER.debug("First pass with no tokens found - requesting tokens"); // This pass, tell each handler to do whatever it takes to get a SecurityToken for (AuthenticationHandler auth : handlers) { result = auth.getNormalizedToken(httpRequest, httpResponse, filterChain, true); if (result.getStatus() != HandlerResult.Status.NO_ACTION) { LOGGER.debug("Handler {} set the result status to {}", auth.getAuthenticationType(), result.getStatus()); break; } } } String path = StringUtils.isNotBlank(httpRequest.getContextPath()) ? httpRequest.getContextPath() : httpRequest.getServletPath() + StringUtils.defaultString(httpRequest.getPathInfo()); String ipAddress = httpRequest.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = httpRequest.getRemoteAddr(); } if (result != null) { switch (result.getStatus()) { case REDIRECTED: // handler handled the response - it is redirecting or whatever // necessary to get their tokens LOGGER.debug("Stopping filter chain - handled by plugins"); return; case NO_ACTION: // should never occur - one of the handlers should have returned a token LOGGER.warn( "No handlers were able to determine required credentials, returning bad request to {}. Check policy configuration for path: {}", ipAddress, path); returnSimpleResponse(HttpServletResponse.SC_BAD_REQUEST, httpResponse); return; case COMPLETED: if (result.getToken() == null) { LOGGER.warn( "Completed without credentials for {} - check context policy configuration for path: {}", ipAddress, path); returnSimpleResponse(HttpServletResponse.SC_BAD_REQUEST, httpResponse); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Attaching result handler to the http request - token is instance of {} from classloader {}", result.getToken().getClass().getName(), result.getToken().getClass().getClassLoader()); } httpRequest.setAttribute(DDF_AUTHENTICATION_TOKEN, result); break; default: LOGGER.warn("Unexpected response from handler - ignoring. Remote IP: {}, Path: {}", ipAddress, path); return; } } else { LOGGER.warn( "Expected login credentials from {} - didn't find any. Returning a bad request for path: {}", ipAddress, path); returnSimpleResponse(HttpServletResponse.SC_BAD_REQUEST, httpResponse); return; } // If we got here, we've received our tokens to continue LOGGER.debug("Invoking the rest of the filter chain"); try { filterChain.doFilter(httpRequest, httpResponse); } catch (InvalidSAMLReceivedException e) { // we tried to process an invalid or missing SAML assertion returnSimpleResponse(HttpServletResponse.SC_UNAUTHORIZED, httpResponse); } catch (Exception e) { LOGGER.debug("Exception in filter chain - passing off to handlers. Msg: {}", e.getMessage(), e); // First pass, see if anyone can come up with proper security token // from the git-go result = null; for (AuthenticationHandler auth : handlers) { result = auth.handleError(httpRequest, httpResponse, filterChain); if (result.getStatus() != HandlerResult.Status.NO_ACTION) { LOGGER.debug("Handler {} set the status to {}", auth.getAuthenticationType(), result.getStatus()); break; } } if (result == null || result.getStatus() == HandlerResult.Status.NO_ACTION) { LOGGER.debug("Error during authentication - no error recovery attempted - returning bad request."); httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST); httpResponse.flushBuffer(); } } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.GmdConverter.java
protected void addIdentificationInfo(MetacardImpl metacard, XstreamPathValueTracker pathValueTracker) { pathValueTracker.add(new Path(GmdMetacardType.TITLE_PATH), StringUtils.defaultString(metacard.getTitle())); GregorianCalendar createdCal = new GregorianCalendar(); if (metacard.getCreatedDate() != null) { createdCal.setTime(metacard.getCreatedDate()); }/*from w w w . j av a2s. co m*/ createdCal.setTimeZone(UTC_TIME_ZONE); pathValueTracker.add(new Path(GmdMetacardType.CREATED_DATE_PATH), XSD_FACTORY.newXMLGregorianCalendar(createdCal).toXMLFormat()); pathValueTracker.add(new Path(GmdMetacardType.CREATED_DATE_TYPE_CODE_PATH), GmdMetacardType.METACARD_URI); pathValueTracker.add(new Path(GmdMetacardType.CREATED_DATE_TYPE_CODE_VALUE_PATH), Metacard.CREATED); pathValueTracker.add(new Path(GmdMetacardType.ABSTRACT_PATH), StringUtils.defaultString(metacard.getDescription())); pathValueTracker.add(new Path(GmdMetacardType.POINT_OF_CONTACT_PATH), StringUtils.defaultString(metacard.getPointOfContact())); pathValueTracker.add(new Path(GmdMetacardType.POINT_OF_CONTACT_ROLE_PATH), (String) null); pathValueTracker.add(new Path(GmdMetacardType.LANGUAGE_PATH), StringUtils.defaultIfEmpty(Locale.getDefault().getLanguage(), Locale.ENGLISH.getLanguage())); addExtent(metacard, pathValueTracker); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.transformer.GmdTransformer.java
private void addMetacardCrs(final XstreamPathValueTracker pathValueTracker, MetacardImpl metacard) { StringBuilder crs = new StringBuilder(); crs.append("urn:ogc:def:crs:"); crs.append(StringUtils .defaultString(pathValueTracker.getFirstValue(toPath(GmdMetacardType.CRS_AUTHORITY_PATH)))); crs.append(COLON);//from ww w. jav a 2 s. c o m crs.append(StringUtils .defaultString(pathValueTracker.getFirstValue(toPath(GmdMetacardType.CRS_VERSION_PATH)))); crs.append(COLON); crs.append( StringUtils.defaultString(pathValueTracker.getFirstValue(toPath(GmdMetacardType.CRS_CODE_PATH)))); metacard.setAttribute(GmdMetacardType.GMD_CRS, crs.toString()); }
From source file:org.displaytag.decorator.MultilevelTotalTableDecorator.java
public String finishRow() { String returnValue = ""; if (containsTotaledColumns) { if (innermostGroup > 0 && deepestResetGroup != NO_RESET_GROUP) { StringBuffer out = new StringBuffer(); // Starting with the deepest group, print the current total and reset. Do not reset unaffected groups. for (int i = innermostGroup; i >= deepestResetGroup; i--) { Integer groupNumber = new Integer(i); GroupTotals totals = (GroupTotals) groupNumberToGroupTotal.get(groupNumber); if (totals == null) { logger.warn("There is a gap in the defined groups - no group defined for " + groupNumber); continue; }/*from ww w . j av a 2 s .c o m*/ totals.printTotals(getListIndex(), out); totals.setStartRow(getListIndex() + 1); } returnValue = out.toString(); } else { returnValue = null; } deepestResetGroup = NO_RESET_GROUP; headerRows.clear(); if (isLastRow()) { returnValue = StringUtils.defaultString(returnValue); returnValue += totalAllRows(); } } return returnValue; }
From source file:org.displaytag.tags.ColumnTag.java
/** * setter for the "href" tag attribute./*from w w w . j a v a2 s .c o m*/ * * @param value attribute value */ public void setHref(String value) { // call encodeURL to preserve session id when cookies are disabled String encodedHref = ((HttpServletResponse) this.pageContext.getResponse()) .encodeURL(StringUtils.defaultString(value)); this.href = new Href(encodedHref); if (this.onclick != null) { this.href.setOnclick(this.onclick); } }
From source file:org.displaytag.tags.ColumnTag.java
/** * setter for the "url" tag attribute. This has the same meaning of href, but prepends the context path to the given * URI./*from w ww . j av a 2 s. com*/ * * @param value attribute value */ public void setUrl(String value) { HttpServletRequest req = (HttpServletRequest) this.pageContext.getRequest(); // call encodeURL to preserve session id when cookies are disabled String encodedHref = ((HttpServletResponse) this.pageContext.getResponse()) .encodeURL(StringUtils.defaultString(req.getContextPath() + value)); this.href = new Href(encodedHref); }
From source file:org.displaytag.util.DefaultRequestHelper.java
/** * @see org.displaytag.util.RequestHelper#getParameterMap() */// w w w . ja v a2 s . c o m public Map getParameterMap() { Map map = new HashMap(); // get the parameters names Enumeration parametersName = this.request.getParameterNames(); while (parametersName.hasMoreElements()) { // ... get the value String paramName = (String) parametersName.nextElement(); // put key/value in the map String[] originalValues = this.request.getParameterValues(paramName); String[] values = new String[originalValues.length]; for (int i = 0; i < values.length; i++) { values[i] = CompatibleUrlEncoder.encode(StringUtils.defaultString(originalValues[i]), response.getCharacterEncoding()); } map.put(paramName, values); } // return the Map return map; }
From source file:org.dresdenocl.model.base.AbstractModel.java
/** * <p>/* w ww .j a v a 2 s . c o m*/ * Constructor to be called by subclasses. The <code>displayName</code> is a * name that should be used to identify this model in a graphical user * interface. This may be the file name or another identifier. * </p> * * @param displayName * A name for this {@link IModel}. * @param metamodel * The {@link IMetamodel} for this {@link IModel}. */ protected AbstractModel(String displayName, IMetamodel metamodel) { /* Use an empty string if display name is null. */ this.displayName = StringUtils.defaultString(displayName); if (metamodel == null) { throw new IllegalArgumentException("The metamodel reference must not be null."); //$NON-NLS-1$ } // no else. this.metamodel = metamodel; }
From source file:org.ebayopensource.turmeric.eclipse.core.logging.PluginLogDelegateHandler.java
/** * @param severity The log severity//from w w w . ja v a2 s. com * @param loggerName The name of the logger * @param message The message body * @param throwable The exception instance or null if no exception. */ private static void log(final int severity, final String loggerName, final String message, final Throwable throwable) { if (TurmericCoreActivator.getDefault() == null) //the Activator has not been initialized yet return; if (systemLogger == null) systemLogger = TurmericCoreActivator.getDefault().getLog(); systemLogger.log(new Status(severity, loggerName, 0, StringUtils.defaultString(message), throwable)); }
From source file:org.ebayopensource.turmeric.eclipse.core.model.TemplateModel.java
/** * Gets the documentation. * * @return the documentation */ public String getDocumentation() { return StringUtils.defaultString(documentation); }