List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix)
Case insensitive check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:com.appchina.ios.mgnt.controller.AppController.java
@RequestMapping("/detail") public String detail(Integer id, Integer rootId, Model model) { ApiRespWrapper<Application> dataResp = null; if (id == null) { dataResp = this.backendApiService.getApplicationByRootId(rootId.intValue()); } else {/* w ww . j av a 2s . c o m*/ dataResp = this.backendApiService.getApplication(id.intValue()); } Application data = dataResp.getData(); rootId = data.getRootId(); ApiRespWrapper<RootApplication> rootApplicationResp = this.backendApiService.getRootApplication(rootId); if (rootApplicationResp != null && rootApplicationResp.getData() != null) { model.addAttribute("rootApplication", rootApplicationResp.getData()); } List<ApplicationItunesImgRes> appRes = null; List<Category> cates = null; Category parentCate = null; if (data != null) { id = data.getId(); ApiRespWrapper<ListWrapResp<ApplicationItunesImgRes>> appResResp = this.backendApiService .getApplicationResource(id); appRes = appResResp == null || appResResp.getData() == null ? null : appResResp.getData().getResultList(); ApiRespWrapper<ListWrapResp<Category>> cateResp = this.backendApiService .getRootApplicationCategory(rootId); cates = cateResp.getData().getResultList(); if (!CollectionUtils.emptyOrNull(cates) && cates.get(0).getParent() != null) { ApiRespWrapper<Category> parentCateResp = this.backendApiService .getCategory(cates.get(0).getParent().intValue()); parentCate = parentCateResp.getData(); } } model.addAttribute("data", data); model.addAttribute("appRes", appRes); for (ApplicationItunesImgRes applicationItunesImgRes : appRes) { if (applicationItunesImgRes.getType() == ApplicationItunesImgRes.TYPE_ICON) { List<List<ImgRes>> icons = ApplicationItunesImgResUtils .formatResourceToListImgList(applicationItunesImgRes); model.addAttribute("icons", icons); } else if (applicationItunesImgRes.getType() == ApplicationItunesImgRes.TYPE_SCREEN) { if (StringUtils.startsWithIgnoreCase(applicationItunesImgRes.getDevice(), "iphone")) { List<List<ImgRes>> iphones = ApplicationItunesImgResUtils .formatResourceToListImgList(applicationItunesImgRes); model.addAttribute("iphones", iphones); } else if (StringUtils.startsWithIgnoreCase(applicationItunesImgRes.getDevice(), "ipad")) { List<List<ImgRes>> ipads = ApplicationItunesImgResUtils .formatResourceToListImgList(applicationItunesImgRes); model.addAttribute("ipads", ipads); } } } model.addAttribute("cates", cates); model.addAttribute("parentCate", parentCate); model.addAttribute("id", id); return "app/detail.ftl"; }
From source file:com.glaf.core.web.springmvc.MxSystemDbTableController.java
@ResponseBody @RequestMapping("/save") public byte[] save(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); String tableName = request.getParameter("tableName_enc"); if (StringUtils.isNotEmpty(tableName)) { tableName = RequestUtils.decodeString(tableName); } else {/*from w ww.ja va2s . c o m*/ tableName = request.getParameter("tableName"); } Collection<String> rejects = new java.util.ArrayList<String>(); rejects.add("FILEATT"); rejects.add("ATTACHMENT"); rejects.add("CMS_PUBLICINFO"); rejects.add("SYS_LOB"); rejects.add("SYS_MAIL_FILE"); rejects.add("SYS_DBID"); rejects.add("SYS_PROPERTY"); if (conf.get("table.rejects") != null) { String str = conf.get("table.rejects"); List<String> list = StringTools.split(str); for (String t : list) { rejects.add(t.toUpperCase()); } } String businessKey = request.getParameter("businessKey"); String primaryKey = null; ColumnDefinition idColumn = null; List<ColumnDefinition> columns = null; try { /** * ?????? */ if (StringUtils.isNotEmpty(tableName) && !rejects.contains(tableName.toUpperCase()) && !StringUtils.startsWithIgnoreCase(tableName, "user") && !StringUtils.startsWithIgnoreCase(tableName, "net") && !StringUtils.startsWithIgnoreCase(tableName, "sys") && !StringUtils.startsWithIgnoreCase(tableName, "jbpm") && !StringUtils.startsWithIgnoreCase(tableName, "act")) { columns = DBUtils.getColumnDefinitions(tableName); modelMap.put("tableName", tableName); modelMap.put("tableName_enc", RequestUtils.encodeString(tableName)); List<String> pks = DBUtils.getPrimaryKeys(tableName); if (pks != null && !pks.isEmpty()) { if (pks.size() == 1) { primaryKey = pks.get(0); } } if (primaryKey != null) { for (ColumnDefinition column : columns) { if (StringUtils.equalsIgnoreCase(primaryKey, column.getColumnName())) { idColumn = column; break; } } } if (idColumn != null) { TableModel tableModel = new TableModel(); tableModel.setTableName(tableName); ColumnModel idCol = new ColumnModel(); idCol.setColumnName(idColumn.getColumnName()); idCol.setJavaType(idColumn.getJavaType()); if ("Integer".equals(idColumn.getJavaType())) { idCol.setValue(Integer.parseInt(businessKey)); } else if ("Long".equals(idColumn.getJavaType())) { idCol.setValue(Long.parseLong(businessKey)); } else { idCol.setValue(businessKey); } tableModel.setIdColumn(idCol); for (ColumnDefinition column : columns) { String value = request.getParameter(column.getColumnName()); ColumnModel col = new ColumnModel(); col.setColumnName(column.getColumnName()); col.setJavaType(column.getJavaType()); if (value != null && value.trim().length() > 0 && !value.equals("null")) { if ("Integer".equals(column.getJavaType())) { col.setValue(Integer.parseInt(value)); tableModel.addColumn(col); } else if ("Long".equals(column.getJavaType())) { col.setValue(Long.parseLong(value)); tableModel.addColumn(col); } else if ("Double".equals(column.getJavaType())) { col.setValue(Double.parseDouble(value)); tableModel.addColumn(col); } else if ("Date".equals(column.getJavaType())) { col.setValue(DateUtils.toDate(value)); tableModel.addColumn(col); } else if ("String".equals(column.getJavaType())) { col.setValue(value); tableModel.addColumn(col); } } } tableDataService.updateTableData(tableModel); return ResponseUtils.responseJsonResult(true); } } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } return ResponseUtils.responseJsonResult(false); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPage.java
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * <p>// ww w .j av a 2 s . c om * Execute the specified JavaScript if a JavaScript engine was successfully * instantiated. If this JavaScript causes the current page to be reloaded * (through location="" or form.submit()) then return the new page. Otherwise * return the current page. * </p> * <p><b>Please note:</b> Although this method is public, it is not intended for * general execution of JavaScript. Users of HtmlUnit should interact with the pages * as a user would by clicking on buttons or links and having the JavaScript event * handlers execute as needed.. * </p> * * @param sourceCode the JavaScript code to execute * @param sourceName the name for this chunk of code (will be displayed in error messages) * @param startLine the line at which the script source starts * @return a ScriptResult which will contain both the current page (which may be different than * the previous page and a JavaScript result object. */ public ScriptResult executeJavaScriptIfPossible(String sourceCode, final String sourceName, final int startLine) { if (!getWebClient().getOptions().isJavaScriptEnabled()) { return new ScriptResult(null, this); } if (StringUtils.startsWithIgnoreCase(sourceCode, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { sourceCode = sourceCode.substring(JavaScriptURLConnection.JAVASCRIPT_PREFIX.length()); } final Object result = getWebClient().getJavaScriptEngine().execute(this, sourceCode, sourceName, startLine); return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage()); }
From source file:com.glaf.base.modules.branch.springmvc.BranchUserController.java
/** * //from w ww. j a v a 2 s . co m * * @param request * @param modelMap * @return */ @RequestMapping(params = "method=showRole") public ModelAndView showRole(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); long id = ParamUtil.getIntParameter(request, "user_id", 0); SysUser bean = sysUserService.findById(id); SysUser user = sysUserService.findByAccountWithAll(bean.getAccount()); List<SysDeptRole> deptRoles = sysDeptRoleService.getRoleList(user.getDepartment().getId()); List<SysRole> roles = sysRoleService.getSysRoleList(); if (roles != null && !roles.isEmpty()) { for (SysRole role : roles) { if (StringUtils.isNotEmpty(role.getCode()) && (StringUtils.startsWithIgnoreCase(role.getCode(), SysConstants.BRANCH_PREFIX) || StringUtils.equals(role.getIsUseBranch(), "Y"))) { if (sysDeptRoleService.find(user.getDepartment().getId(), role.getId()) == null) { SysDeptRole dr = new SysDeptRole(); dr.setDeptId(user.getDepartment().getId()); dr.setRole(role); dr.setSysRoleId(role.getId()); dr.setCreateBy(RequestUtils.getActorId(request)); sysDeptRoleService.create(dr); deptRoles.add(dr); } } } } request.setAttribute("user", user); request.setAttribute("list", deptRoles); String x_view = ViewProperties.getString("branch.user.showRole"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } // ? return new ModelAndView("/modules/branch/user/user_role", modelMap); }
From source file:com.nridge.core.base.field.data.DataTable.java
/** * Returns one or more field rows that match the search criteria of the * parameters provided in a case insensitive manner. Each row of the * table will be examined to determine if a cell identified by name * evaluates true when the operator and value are applied to it. * <p>/*from w ww.j a v a 2s. co m*/ * <b>Note:</b> This method supports text based logical operators only. * You should use other <code>findValue()</code> methods for different * data types. * </p> * * @param aName Column name. * @param anOperator Logical operator. * @param aValue Comparison value. * * @return Array list of matching field rows or <i>null</i> if none evaluate true. */ public ArrayList<FieldRow> findValueInsensitive(String aName, Field.Operator anOperator, String aValue) { FieldRow fieldRow; String valueString; Matcher regexMatcher = null; Pattern regexPattern = null; ArrayList<FieldRow> matchingRows = new ArrayList<FieldRow>(); int rowCount = rowCount(); int colOffset = offsetByName(aName); if ((aValue != null) && (colOffset != -1) && (rowCount > 0)) { for (int row = 0; row < rowCount; row++) { fieldRow = getRow(row); valueString = fieldRow.getValue(colOffset); switch (anOperator) { case EQUAL: if (StringUtils.equalsIgnoreCase(valueString, aValue)) matchingRows.add(fieldRow); break; case NOT_EQUAL: if (!StringUtils.equalsIgnoreCase(valueString, aValue)) matchingRows.add(fieldRow); break; case CONTAINS: if (StringUtils.containsIgnoreCase(valueString, aValue)) matchingRows.add(fieldRow); break; case STARTS_WITH: if (StringUtils.startsWithIgnoreCase(valueString, aValue)) matchingRows.add(fieldRow); break; case ENDS_WITH: if (StringUtils.endsWithIgnoreCase(valueString, aValue)) matchingRows.add(fieldRow); break; case EMPTY: if (StringUtils.isEmpty(valueString)) matchingRows.add(fieldRow); break; case REGEX: // http://www.regular-expressions.info/java.html if (regexPattern == null) regexPattern = Pattern.compile(aValue, Pattern.CASE_INSENSITIVE); if (regexMatcher == null) regexMatcher = regexPattern.matcher(valueString); else regexMatcher.reset(valueString); if (regexMatcher.find()) matchingRows.add(fieldRow); break; } } } return matchingRows; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
@Override public boolean visit(org.eclipse.jdt.core.dom.NumberLiteral node) { String token = node.getToken(); if (token.contains(".") || !StringUtils.startsWithIgnoreCase(token, "0x") && (StringUtils.endsWithIgnoreCase(token, "F") || StringUtils.endsWithIgnoreCase(token, "D"))) { token = StringUtils.removeEndIgnoreCase(token, "F"); token = StringUtils.removeEndIgnoreCase(token, "D"); if (!token.contains(".")) { token += ".0"; }/* w ww. jav a 2 s . co m*/ return done(new DoubleLiteral(token(TokenType.DOUBLE, token), 0)); } else { token = StringUtils.removeEndIgnoreCase(token, "L"); return done(new IntegerLiteral(token(TokenType.INT, token), BigInteger.valueOf(0))); } }
From source file:nl.mvdr.umvc3replayanalyser.model.predicate.GamertagPrefixPlayerPredicate.java
/** {@inheritDoc} */ @Override public boolean apply(Player player) { return StringUtils.startsWithIgnoreCase(player.getGamertag(), prefix); }
From source file:nz.net.orcon.kanban.tools.ComplexDateConverter.java
protected boolean containsToday(String formula) { return StringUtils.startsWithIgnoreCase(formula, TODAY); }
From source file:org.apache.hadoop.gateway.filter.RequestUpdateHandler.java
@Override public void doHandle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final String newTarget = redirectContext + target; RequestUpdateHandler.ForwardedRequest newRequest = new RequestUpdateHandler.ForwardedRequest(request, redirectContext, newTarget); // if the request already has the /{gatewaypath}/{topology} part then skip if (!StringUtils.startsWithIgnoreCase(target, redirectContext)) { baseRequest.setPathInfo(redirectContext + baseRequest.getPathInfo()); baseRequest.setUri(new HttpURI(redirectContext + baseRequest.getUri().toString())); LOG.topologyPortMappingUpdateRequest(target, newTarget); nextHandle(newTarget, baseRequest, newRequest, response); } else {/* w w w. ja v a 2s.com*/ nextHandle(target, baseRequest, newRequest, response); } }
From source file:org.apache.nifi.web.ContentViewerController.java
/** * Gets the content and defers to registered viewers to generate the markup. * * @param request servlet request//w w w. j a v a2 s . c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // specify the charset in a response header response.addHeader("Content-Type", "text/html; charset=UTF-8"); // get the content final ServletContext servletContext = request.getServletContext(); final ContentAccess contentAccess = (ContentAccess) servletContext.getAttribute("nifi-content-access"); final ContentRequestContext contentRequest; try { contentRequest = getContentRequest(request); } catch (final Exception e) { request.setAttribute("title", "Error"); request.setAttribute("messages", "Unable to interpret content request."); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } if (contentRequest.getDataUri() == null) { request.setAttribute("title", "Error"); request.setAttribute("messages", "The data reference must be specified."); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } // get the content final DownloadableContent downloadableContent; try { downloadableContent = contentAccess.getContent(contentRequest); } catch (final ResourceNotFoundException rnfe) { request.setAttribute("title", "Error"); request.setAttribute("messages", "Unable to find the specified content"); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } catch (final AccessDeniedException ade) { request.setAttribute("title", "Access Denied"); request.setAttribute("messages", "Unable to approve access to the specified content: " + ade.getMessage()); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } catch (final Exception e) { request.setAttribute("title", "Error"); request.setAttribute("messages", "An unexpected error has occurred: " + e.getMessage()); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } // determine how we want to view the data String mode = request.getParameter("mode"); // if the name isn't set, use original if (mode == null) { mode = DisplayMode.Original.name(); } // determine the display mode final DisplayMode displayMode; try { displayMode = DisplayMode.valueOf(mode); } catch (final IllegalArgumentException iae) { request.setAttribute("title", "Error"); request.setAttribute("messages", "Invalid display mode: " + mode); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } // buffer the content to support resetting in case we need to detect the content type or char encoding try (final BufferedInputStream bis = new BufferedInputStream(downloadableContent.getContent());) { final String mimeType; final String normalizedMimeType; // when standalone and we don't know the type is null as we were able to directly access the content bypassing the rest endpoint, // when clustered and we don't know the type set to octet stream since the content was retrieved from the node's rest endpoint if (downloadableContent.getType() == null || StringUtils .startsWithIgnoreCase(downloadableContent.getType(), MediaType.OCTET_STREAM.toString())) { // attempt to detect the content stream if we don't know what it is () final DefaultDetector detector = new DefaultDetector(); // create the stream for tika to process, buffered to support reseting final TikaInputStream tikaStream = TikaInputStream.get(bis); // provide a hint based on the filename final Metadata metadata = new Metadata(); metadata.set(Metadata.RESOURCE_NAME_KEY, downloadableContent.getFilename()); // Get mime type final MediaType mediatype = detector.detect(tikaStream, metadata); mimeType = mediatype.toString(); } else { mimeType = downloadableContent.getType(); } // Extract only mime type and subtype from content type (anything after the first ; are parameters) // Lowercase so subsequent code does not need to implement case insensitivity normalizedMimeType = mimeType.split(";", 2)[0].toLowerCase(); // add attributes needed for the header request.setAttribute("filename", downloadableContent.getFilename()); request.setAttribute("contentType", mimeType); // generate the header request.getRequestDispatcher("/WEB-INF/jsp/header.jsp").include(request, response); // remove the attributes needed for the header request.removeAttribute("filename"); request.removeAttribute("contentType"); // generate the markup for the content based on the display mode if (DisplayMode.Hex.equals(displayMode)) { final byte[] buffer = new byte[BUFFER_LENGTH]; final int read = StreamUtils.fillBuffer(bis, buffer, false); // trim the byte array if necessary byte[] bytes = buffer; if (read != buffer.length) { bytes = new byte[read]; System.arraycopy(buffer, 0, bytes, 0, read); } // convert bytes into the base 64 bytes final String base64 = Base64.encodeBase64String(bytes); // defer to the jsp request.setAttribute("content", base64); request.getRequestDispatcher("/WEB-INF/jsp/hexview.jsp").include(request, response); } else { // lookup a viewer for the content final String contentViewerUri = servletContext.getInitParameter(normalizedMimeType); // handle no viewer for content type if (contentViewerUri == null) { request.getRequestDispatcher("/WEB-INF/jsp/no-viewer.jsp").include(request, response); } else { // create a request attribute for accessing the content request.setAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE, new ViewableContent() { @Override public InputStream getContentStream() { return bis; } @Override public String getContent() throws IOException { // detect the charset final CharsetDetector detector = new CharsetDetector(); detector.setText(bis); detector.enableInputFilter(true); final CharsetMatch match = detector.detect(); // ensure we were able to detect the charset if (match == null) { throw new IOException("Unable to detect character encoding."); } // convert the stream using the detected charset return IOUtils.toString(bis, match.getName()); } @Override public ViewableContent.DisplayMode getDisplayMode() { return displayMode; } @Override public String getFileName() { return downloadableContent.getFilename(); } @Override public String getContentType() { return normalizedMimeType; } @Override public String getRawContentType() { return mimeType; } }); try { // generate the content final ServletContext viewerContext = servletContext.getContext(contentViewerUri); viewerContext.getRequestDispatcher("/view-content").include(request, response); } catch (final Exception e) { String message = e.getMessage() != null ? e.getMessage() : e.toString(); message = "Unable to generate view of data: " + message; // log the error logger.error(message); if (logger.isDebugEnabled()) { logger.error(StringUtils.EMPTY, e); } // populate the request attributes request.setAttribute("title", "Error"); request.setAttribute("messages", message); // forward to the error page final ServletContext viewerContext = servletContext.getContext("/nifi"); viewerContext.getRequestDispatcher("/message").forward(request, response); return; } // remove the request attribute request.removeAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE); } } // generate footer request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp").include(request, response); } }