List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:com.nridge.core.ds.rdbms.SQLSequence.java
/** * Returns a schema name for sequence objects based on the DB name * assigned to the bag and the data field. * * @param aBag Field bag with DB name assigned. * @param aFieldName Name of field to base sequence on. * * @return Schema name of the index object. * * @throws NSException Catch-all exception for any SQL related issue. *///from w w w . ja v a 2s .co m public String schemaName(DataBag aBag, String aFieldName) throws NSException { String dbName = aBag.getName(); if (StringUtils.isEmpty(dbName)) throw new NSException("The name for the data bag is undefined."); String sequenceName; if (mSQLConnection.isAutoNamingEnabled()) { if (StringUtils.startsWith(dbName, NS_SEQUENCE_PREFIX)) { if (StringUtils.contains(dbName, aFieldName)) sequenceName = dbName; else sequenceName = String.format("%s_%s_%s", NS_SEQUENCE_PREFIX, dbName, aFieldName); } else sequenceName = String.format("%s_%s_%s", NS_SEQUENCE_PREFIX, dbName, aFieldName); } else sequenceName = String.format("%s_%s", dbName, aFieldName); return sequenceName; }
From source file:io.wcm.devops.conga.plugins.sling.fileheader.OsgiConfigFileHeader.java
@Override public FileHeaderContext extract(FileContext file) { try {/*from w ww . ja v a 2s. com*/ String content = FileUtils.readFileToString(file.getFile(), file.getCharset()); String[] contentLines = StringUtils.split(content, "\n"); if (contentLines.length > 0 && StringUtils.startsWith(contentLines[0], getCommentLinePrefix())) { String fullComment = StringUtils .trim(StringUtils.substringAfter(contentLines[0], getCommentBlockStart())); List<String> lines = ImmutableList.of(fullComment); return new FileHeaderContext().commentLines(lines); } } catch (IOException ex) { throw new GeneratorException("Unable parse add file header from " + file.getCanonicalPath(), ex); } return null; }
From source file:de.micromata.genome.util.runtime.jndi.SimpleJndiContext.java
@Override public Object lookup(String lookupName) throws NameNotFoundException { try {//from w w w .j av a 2 s. c o m return super.lookup(lookupName); } catch (NameNotFoundException ex) { String prefix = "java:comp/env/"; if (StringUtils.startsWith(lookupName, prefix) == false) { return super.lookup(prefix + lookupName); } throw ex; } }
From source file:de.micromata.genome.gwiki.launcher.GWikiJettyServer.java
@Override protected ServletContextHandler createContextHandler(JettyConfigModel config) { contextPath = config.getContextpath(); String contextFile = "res:/StandaloneGWikiContext.xml"; if (LocalSettings.get().getBooleanValue("gwiki.useContextXml", false) == true) { contextFile = LocalSettings.get().get("gwiki.contextfile", contextFile); }/* w w w. j a va2 s.c o m*/ GWikiBootstrapConfigLoader cfgLoader; if (StringUtils.startsWith(contextFile, "res:") == true) { String fileName = contextFile.substring("res:".length()); GWikiCpContextBootstrapConfigLoader cploader = new GWikiCpContextBootstrapConfigLoader(); cploader.setFileName(fileName); cfgLoader = cploader; } else { GwikiFileContextBootstrapConfigLoader fcfgLoader = new GwikiFileContextBootstrapConfigLoader(); if (StringUtils.isNotBlank(contextFile) == true) { fcfgLoader.setFileName(contextFile); } else { contextFile = "."; } cfgLoader = fcfgLoader; } wikibootcfg = cfgLoader.loadConfig(null); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); wikiServlet = new GWikiServlet(); ServletHolder wikiServletHolder = new ServletHolder(wikiServlet); wikiServlet.setDAOContext(wikibootcfg); wikiServlet.setContextPath(config.getContextpath()); wikiServlet.setServletPath(""); wikiServletHolder.setInitParameter("servletPath", ""); wikiServletHolder.setInitParameter("contextPath", config.getContextpath()); context.addServlet(wikiServletHolder, "/*"); GWikiLogHtmlWindowServlet logHtmlServlet = new GWikiLogHtmlWindowServlet(); // logHtmlServlet.init(); ServletHolder logHtmlServletHolder = new ServletHolder(logHtmlServlet); context.addServlet(logHtmlServletHolder, "/loghtml"); context.setContextPath(config.getContextpath()); return context; }
From source file:com.glaf.core.web.springmvc.MxSystemPropertyController.java
@RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); String category = request.getParameter("category"); if (StringUtils.isNotEmpty(category)) { List<SystemProperty> rows = systemPropertyService.getSystemProperties(category); if (rows != null && !rows.isEmpty()) { for (SystemProperty p : rows) { if (StringUtils.equals(p.getInputType(), "combobox")) { if (StringUtils.isNotEmpty(p.getInitValue()) && StringUtils.startsWith(p.getInitValue(), "[") && StringUtils.endsWith(p.getInitValue(), "]")) { try { JSONArray array = JSON.parseArray(p.getInitValue()); p.setArray(array); StringBuffer buffer = new StringBuffer(); for (int i = 0, len = array.size(); i < len; i++) { JSONObject json = array.getJSONObject(i); buffer.append("<option value=\"").append(json.getString("value")).append("\">") .append(json.getString("name")).append("</option>") .append(FileUtils.newline); }//w w w.j av a2 s . c om p.setSelectedScript(buffer.toString()); } catch (Exception ex) { ex.printStackTrace(); logger.error("parse json error :" + p.getInitValue(), ex); } } } } } request.setAttribute("rows", rows); } String jx_view = request.getParameter("jx_view"); if (StringUtils.isNotEmpty(jx_view)) { return new ModelAndView(jx_view, modelMap); } String x_view = ViewProperties.getString("sys_property.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/sys/property/edit"); }
From source file:io.wcm.handler.link.type.InternalCrossScopeLinkType.java
@Override public boolean accepts(String linkRef) { // accept as internal link if the ref starts with "/content/" return StringUtils.startsWith(linkRef, "/content/") && !MediaLinkType.isDefaultMediaContentPath(linkRef); }
From source file:jobhunter.models.SubscriptionItem.java
public String getWorkingLink() { if (StringUtils.startsWith(this.link, "http")) return this.link; if (StringUtils.startsWith(this.link, "//")) return this.host + StringUtils.removeStart(this.link, "//"); if (StringUtils.startsWith(this.link, "/")) return this.host + StringUtils.removeStart(this.link, "/"); return this.link; }
From source file:io.wcm.handler.mediasource.dam.markup.DamVideoMediaMarkupBuilderTest.java
@Test public void testBuild() throws Exception { HtmlElement<?> element = underTest.build(video); assertTrue(element instanceof Video); Video videoElement = (Video) element; assertEquals(VIDEO_2COL.getWidth(), videoElement.getWidth()); assertEquals(VIDEO_2COL.getHeight(), videoElement.getHeight()); List<Element> sources = videoElement.getChildren("source"); assertEquals(2, sources.size());//from w ww . j a v a 2 s . c o m Source source1 = (Source) sources.get(0); assertTrue(StringUtils.startsWith(source1.getType(), "video/mp4")); assertEquals(MEDIAITEM_VIDEO + "/_jcr_content/renditions/cq5dam.video.hq.m4v", source1.getSrc()); Source source2 = (Source) sources.get(1); assertTrue(StringUtils.startsWith(source2.getType(), "video/ogg")); assertEquals(MEDIAITEM_VIDEO + "/_jcr_content/renditions/cq5dam.video.firefoxhq.ogg", source2.getSrc()); Element flashObject = videoElement.getChild("object"); assertNotNull(flashObject); assertEquals(ContentType.SWF, flashObject.getAttributeValue("type")); }
From source file:io.wcm.handler.mediasource.dam.DamMediaSource.java
@Override public boolean accepts(String mediaRef) { return StringUtils.startsWith(mediaRef, "/content/dam/"); }
From source file:com.adguard.filter.rules.FilterRule.java
/** * Creates filter rule.//w w w .j a v a 2s .c o m * If this rule text is not valid - returns null. * * @param ruleText Rule text * @return Filter rule of the proper type */ public static FilterRule createRule(String ruleText) { ruleText = StringUtils.trim(ruleText); if (StringUtils.isBlank(ruleText) || StringUtils.length(ruleText) < MIN_RULE_LENGTH || StringUtils.startsWith(ruleText, COMMENT) || StringUtils.startsWith(ruleText, META_START) || StringUtils.contains(ruleText, MASK_OBSOLETE_SCRIPT_INJECTION) || StringUtils.contains(ruleText, MASK_OBSOLETE_STYLE_INJECTION)) { return null; } try { if (StringUtils.startsWith(ruleText, MASK_WHITE_LIST)) { return new UrlFilterRule(ruleText); } if (StringUtils.contains(ruleText, MASK_CONTENT_RULE)) { return new ContentFilterRule(ruleText); } if (StringUtils.contains(ruleText, MASK_CSS_RULE) || StringUtils.contains(ruleText, MASK_CSS_EXCEPTION_RULE) || StringUtils.contains(ruleText, MASK_CSS_INJECT_RULE) || StringUtils.contains(ruleText, MASK_CSS_INJECT_EXCEPTION_RULE)) { return new CssFilterRule(ruleText); } if (StringUtils.contains(ruleText, MASK_SCRIPT_RULE)) { return new ScriptFilterRule(ruleText); } return new UrlFilterRule(ruleText); } catch (Exception ex) { LoggerFactory.getLogger(FilterRule.class).warn("Error creating filter rule {}:\r\n{}", ruleText, ex); return null; } }