List of usage examples for org.apache.commons.lang BooleanUtils toBoolean
public static boolean toBoolean(String str)
Converts a String to a boolean (optimised for performance).
'true'
, 'on'
or 'yes'
(case insensitive) will return true
.
From source file:org.diffkit.common.DKRuntime.java
public Boolean getIsTest() { if (_isTest != null) return _isTest; _isTest = BooleanUtils.toBoolean(System.getProperty(IS_TEST_PROPERTY)); return _isTest; }
From source file:org.displaytag.tags.el.ExpressionEvaluator.java
/** * Evaluate expression in attrValueas as a boolean. * @param attrName attribute name/*from w ww .j a va2s .c o m*/ * @param attrValue attribute value * @return evaluate expression of attrValue, false if attrValue is null. * @throws JspException exception thrown by ExpressionEvaluatorManager */ public boolean evalBoolean(String attrName, String attrValue) throws JspException { return BooleanUtils.toBoolean((Boolean) eval(attrName, attrValue, Boolean.class)); }
From source file:org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration.java
public boolean getUnconfirmedAllowed(String product) { ProductEntry entry = products.get(product); if (entry != null) { return BooleanUtils.toBoolean(entry.getUnconfirmedAllowed()); } else {// ww w . ja v a 2 s .c o m return false; } }
From source file:org.eclipse.skalli.nexus.internal.NexusResponseParser.java
static boolean getNodeTextContentAsBoolean(Element rootElement, String nodeName) throws NexusClientException { return BooleanUtils.toBoolean(getNodeTextContent(rootElement, nodeName)); }
From source file:org.eclipse.skalli.services.user.UserServices.java
private static UserService getActiveUserService() { UserService userService = null;/*from www. j a va 2s . c om*/ // retrieve params from configuration properties; // use "local" userstore as fallback in case no explicit property/configuration is available String type = BundleProperties.getProperty(USERSTORE_TYPE_PROPERTY, LOCAL_USERSTORE); boolean useLocalFallback = BooleanUtils .toBoolean(BundleProperties.getProperty(USERSTORE_USE_LOCAL_FALLBACK_PROPERTY)); // if there is a configuration via REST API available, override the properties UserStoreConfig userStoreConfig = Configurations.getConfiguration(UserStoreConfig.class); if (userStoreConfig != null) { type = userStoreConfig.getType(); useLocalFallback = userStoreConfig.isUseLocalFallback(); } // first: lookup the preferred user store if (StringUtils.isNotBlank(type)) { userService = byType.get(type); } // second: if the preferred user store is not available, but fallback // to the local store is allowed, use the local store if (userService == null && useLocalFallback) { LOG.info(MessageFormat .format("Preferred user service ''{0}'' not found, falling back to local user store", type)); userService = byType.get(LOCAL_USERSTORE); } return userService; }
From source file:org.eclipse.skalli.view.internal.filter.LoginFilter.java
@Override public void init(FilterConfig config) throws ServletException { this.rejectAnonymousUsers = BooleanUtils.toBoolean(config.getInitParameter("rejectAnonymousUsers")); //$NON-NLS-1$ }
From source file:org.eclipse.skalli.view.internal.filter.ProjectDetailsFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String userId = (String) request.getAttribute(Consts.ATTRIBUTE_USERID); Project project = (Project) request.getAttribute(Consts.ATTRIBUTE_PROJECT); boolean isProjectAdmin = BooleanUtils .toBoolean((Boolean) request.getAttribute(Consts.ATTRIBUTE_PROJECTADMIN)); boolean isProjectAdminInParentChain = BooleanUtils .toBoolean((Boolean) request.getAttribute(Consts.ATTRIBUTE_PARENTPROJECTADMIN)); String action = request.getParameter(Consts.PARAM_ACTION); String windowName = StringUtils.strip(httpRequest.getPathInfo(), "/"); //$NON-NLS-1$ if (project != null) { if (!project.isDeleted()) { windowName = project.getProjectId(); } else {/*from ww w.j av a 2 s . c o m*/ windowName = project.getUuid().toString(); } ProjectTemplateService templateService = Services.getRequiredService(ProjectTemplateService.class); ProjectTemplate projectTemplate = templateService .getProjectTemplateById(project.getProjectTemplateId()); request.setAttribute(Consts.ATTRIBUTE_PROJECTTEMPLATE, projectTemplate); request.setAttribute(Consts.ATTRIBUTE_NATURE, projectTemplate.getProjectNature().toString()); if (userId != null) { FavoritesService favoritesService = Services.getService(FavoritesService.class); Favorites favorites = null; if (favoritesService == null) { favorites = new Favorites(userId); } else { favorites = favoritesService.getFavorites(userId); } request.setAttribute(Consts.ATTRIBUTE_FAVORITES, favorites.asMap()); boolean showIssues = isProjectAdmin || isProjectAdminInParentChain; request.setAttribute(Consts.ATTRIBUTE_SHOW_ISSUES, isProjectAdmin); if (showIssues) { IssuesService issuesService = Services.getService(IssuesService.class); if (issuesService != null) { if (Consts.PARAM_VALUE_VALIDATE.equals(action)) { ValidationService validationService = Services.getService(ValidationService.class); if (validationService != null) { validationService.validate(Project.class, project.getUuid(), Severity.INFO, userId); } } Issues issues = issuesService.getByUUID(project.getUuid()); if (issues != null && issues.hasIssues()) { request.setAttribute(Consts.ATTRIBUTE_ISSUES, issues); request.setAttribute(Consts.ATTRIBUTE_MAX_SEVERITY, issues.getIssues().first().getSeverity().name()); } } } request.setAttribute(Consts.ATTRIBUTE_PROJECTCONTEXTLINKS, getOrderedVisibleProjectContextLinks(project, userId)); } String pathInfo = httpRequest.getPathInfo(); if (pathInfo != null) { int infoBoxIndex = pathInfo.indexOf(Consts.URL_INFOBOXES); if (infoBoxIndex > 0) { if (StringUtils.isNotBlank(action)) { String infoBoxShortName = pathInfo.substring(infoBoxIndex + Consts.URL_INFOBOXES.length()); if (infoBoxShortName.startsWith(FilterUtil.PATH_SEPARATOR)) { infoBoxShortName = infoBoxShortName.substring(1); } filterInfobox(project, infoBoxShortName, action, userId); } } } } request.setAttribute(Consts.ATTRIBUTE_WINDOWNAME, windowName); request.setAttribute(Consts.ATTRIBUTE_EDITMODE, false); String appUri = Consts.URL_VAADIN_PROJECTS + windowName; if (StringUtils.isNotBlank(action)) { if (action.equals(Consts.PARAM_VALUE_EDIT)) { request.setAttribute(Consts.ATTRIBUTE_EDITMODE, true); appUri = appUri + "/edit"; //$NON-NLS-1$ } } request.setAttribute(Consts.ATTRIBUTE_APP_URI, appUri); // proceed along the chain chain.doFilter(request, response); }
From source file:org.eclipse.skalli.view.internal.filter.ProjectPermitsFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; // retrieve userId and project instance from previous filters in chain String userId = (String) request.getAttribute(Consts.ATTRIBUTE_USERID); Project project = (Project) request.getAttribute(Consts.ATTRIBUTE_PROJECT); boolean isAnonymousUser = BooleanUtils .toBoolean((Boolean) request.getAttribute(Consts.ATTRIBUTE_ANONYMOUS_USER)); boolean isProjectAdmin = BooleanUtils .toBoolean((Boolean) request.getAttribute(Consts.ATTRIBUTE_PROJECTADMIN)); String servletPath = httpRequest.getServletPath(); String pathInfo = httpRequest.getPathInfo(); if (servletPath.startsWith(Consts.URL_PROJECTS)) { // handle access to project detail page if (project != null && !Permits.hasProjectPermit(Permit.ALLOW, Permit.ACTION_GET, project)) { AccessControlException e = new AccessControlException(MessageFormat.format( "User ''{0}'' is not authorized to view project ''{1}''", userId, project.getProjectId())); FilterUtil.handleACException(httpRequest, response, e); return; }/*from w ww.j a v a 2 s .c om*/ // handle URL starting with /projects String actionValue = request.getParameter(Consts.PARAM_ACTION); if (project != null && Consts.PARAM_VALUE_EDIT.equals(actionValue)) { // handle /projects/{projectId}?action=edit if (!isProjectAdmin) { AccessControlException e = new AccessControlException( MessageFormat.format("User ''{0}'' is not authorized to edit project ''{1}''", userId, project.getProjectId())); FilterUtil.handleACException(httpRequest, response, e); return; } } else if (project == null && StringUtils.isNotBlank(pathInfo)) { // handle /projects/{projectId} with unknown projectId => project creation dialog if (isAnonymousUser) { AccessControlException e = new AccessControlException( "Anonymous users are not authorized to create new projects"); FilterUtil.handleACException(httpRequest, response, e); return; } } } else { // handle all other URLs not starting with /projects if (isAnonymousUser) { AccessControlException e = new AccessControlException( "Anonymous users are not authorized to view this page"); FilterUtil.handleACException(request, response, e); return; } if (StringUtils.isNotBlank(pathInfo)) { if (project == null) { FilterException e = new FilterException(MessageFormat .format("No project instance available although servlet path is {0}.", servletPath)); FilterUtil.handleException(request, response, e); return; } else if (!isProjectAdmin) { AccessControlException e = new AccessControlException( "User is not authorized to view this page"); FilterUtil.handleACException(request, response, e); return; } } } // proceed along the chain chain.doFilter(request, response); }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.CommonRpcParser.java
/** * Converts the object to a boolean.//from ww w.j a v a 2 s .c o m */ protected Boolean toBoolean(Object object) { if (object == null || object instanceof Boolean) { return (Boolean) object; } return BooleanUtils.toBoolean(ObjectUtils.toString(object)); }
From source file:org.eclipse.smarthome.ui.internal.chart.ChartServlet.java
@SuppressWarnings({ "null" }) @Override/*from w w w .j a va2s .c om*/ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { logger.debug("Received incoming chart request: {}", req); int width = defaultWidth; String w = req.getParameter("w"); if (w != null) { try { width = Integer.parseInt(w); } catch (NumberFormatException e) { logger.debug("Ignoring invalid value '{}' for HTTP request parameter 'w'", w); } } int height = defaultHeight; String h = req.getParameter("h"); if (h != null) { try { Double d = Double.parseDouble(h) * scale; height = d.intValue(); } catch (NumberFormatException e) { logger.debug("Ignoring invalid value '{}' for HTTP request parameter 'h'", h); } } // To avoid ambiguity you are not allowed to specify period, begin and end time at the same time. if (req.getParameter("period") != null && req.getParameter("begin") != null && req.getParameter("end") != null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Do not specify the three parameters period, begin and end at the same time."); return; } // Read out the parameter period, begin and end and save them. Date timeBegin = null; Date timeEnd = null; Long period = PERIODS.get(req.getParameter("period")); if (period == null) { // use a day as the default period period = PERIODS.get("D"); } if (req.getParameter("begin") != null) { try { timeBegin = new SimpleDateFormat(DATE_FORMAT).parse(req.getParameter("begin")); } catch (ParseException e) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Begin and end must have this format: " + DATE_FORMAT + "."); return; } } if (req.getParameter("end") != null) { try { timeEnd = new SimpleDateFormat(DATE_FORMAT).parse(req.getParameter("end")); } catch (ParseException e) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Begin and end must have this format: " + DATE_FORMAT + "."); return; } } // Set begin and end time and check legality. if (timeBegin == null && timeEnd == null) { timeEnd = new Date(); timeBegin = new Date(timeEnd.getTime() - period); logger.debug("No begin or end is specified, use now as end and now-period as begin."); } else if (timeEnd == null) { timeEnd = new Date(timeBegin.getTime() + period); logger.debug("No end is specified, use begin + period as end."); } else if (timeBegin == null) { timeBegin = new Date(timeEnd.getTime() - period); logger.debug("No begin is specified, use end-period as begin"); } else if (timeEnd.before(timeBegin)) { throw new ServletException("The end is before the begin."); } // If a persistence service is specified, find the provider String serviceName = req.getParameter("service"); ChartProvider provider = getChartProviders().get(providerName); if (provider == null) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get chart provider."); return; } // Read out the parameter 'dpi' Integer dpi = null; if (req.getParameter("dpi") != null) { try { dpi = Integer.valueOf(req.getParameter("dpi")); } catch (NumberFormatException e) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "dpi parameter is invalid"); return; } if (dpi <= 0) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "dpi parameter is <= 0"); return; } } // Read out parameter 'legend' Boolean legend = null; if (req.getParameter("legend") != null) { legend = BooleanUtils.toBoolean(req.getParameter("legend")); } if (maxWidth > 0 && width > maxWidth) { height = Math.round((float) height / (float) width * maxWidth); if (dpi != null) { dpi = Math.round((float) dpi / (float) width * maxWidth); } width = maxWidth; } // Set the content type to that provided by the chart provider res.setContentType("image/" + provider.getChartType()); logger.debug("chart building with width {} height {} dpi {}", width, height, dpi); try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(res.getOutputStream())) { BufferedImage chart = provider.createChart(serviceName, req.getParameter("theme"), timeBegin, timeEnd, height, width, req.getParameter("items"), req.getParameter("groups"), dpi, legend); ImageIO.write(chart, provider.getChartType().toString(), imageOutputStream); logger.debug("Chart successfully generated and written to the response."); } catch (ItemNotFoundException e) { logger.debug("{}", e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } catch (IllegalArgumentException e) { logger.warn("Illegal argument in chart: {}", e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument in chart: " + e.getMessage()); } catch (IIOException | EOFException e) { // this can happen if the request is terminated while the image is streamed, see // https://github.com/openhab/openhab-distro/issues/684 logger.debug("Failed writing image to response stream", e); } catch (RuntimeException e) { if (logger.isDebugEnabled()) { // we also attach the stack trace logger.warn("Chart generation failed: {}", e.getMessage(), e); } else { logger.warn("Chart generation failed: {}", e.getMessage()); } res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }