List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:com.google.gdt.eclipse.designer.model.property.css.ContextDescription.java
/** * Add new {@link CssRuleNode} with given class name. * //w ww .j a v a 2s.c o m * @return the name of style, which should be used to reference this rule. */ public String addNewStyle(String styleName) throws Exception { String newSelector = "." + StringUtils.removeStart(styleName, "."); // may be already has rule with such selection for (CssRuleNode existingRule : getRules()) { if (existingRule.getSelector().getValue().equals(newSelector)) { return getStyleName(existingRule); } } // OK, add new rule CssRuleNode newRule = CssFactory.newRule(newSelector); m_context.getCssDocument().addRule(newRule); return getStyleName(newRule); }
From source file:info.magnolia.cms.beans.config.URI2RepositoryMapping.java
/** * Create a node handle based on an uri. */// ww w . j ava2 s . c o m public String getHandle(String uri) { String handle; handle = StringUtils.removeStart(uri, this.URIPrefix); if (StringUtils.isNotEmpty(this.handlePrefix)) { StringUtils.removeStart(handle, "/"); handle = this.handlePrefix + "/" + handle; } //remove extension (ignore . anywhere else in the uri) String fileName = StringUtils.substringAfterLast(handle, "/"); String extension = StringUtils.substringAfterLast(fileName, "."); handle = StringUtils.removeEnd(handle, "." + extension); handle = cleanHandle(handle); try { final Session session = MgnlContext.getJCRSession(this.repository); if (!session.itemExists(handle)) { String maybeHandle = (this.handlePrefix.endsWith("/") ? "/" : "") + StringUtils.removeStart(handle, this.handlePrefix); // prefix might have been prepended incorrectly. Second part of the condition is there to match links to binary nodes if (session.itemExists(maybeHandle) || (maybeHandle.lastIndexOf("/") > 0 && session.itemExists(StringUtils.substringBeforeLast(maybeHandle, "/")))) { return maybeHandle; } } } catch (RepositoryException e) { //Log the exception and return handle log.debug(e.getMessage(), e); } return handle; }
From source file:com.adobe.acs.commons.contentfinder.querybuilder.impl.viewhandler.GQLToQueryBuilderConverter.java
@SuppressWarnings("squid:S3776") public static Map<String, String> addOrder(final SlingHttpServletRequest request, Map<String, String> map, final String queryString) { if (has(request, CF_ORDER)) { int count = 1; for (String value : getAll(request, CF_ORDER)) { value = StringUtils.trim(value); final String orderGroupId = String.valueOf(GROUP_ORDERBY_USERDEFINED + count) + SUFFIX_ORDERBY; boolean sortAsc = false; if (StringUtils.startsWith(value, "-")) { value = StringUtils.removeStart(value, "-"); } else if (StringUtils.startsWith(value, "+")) { sortAsc = true;// ww w .ja v a 2 s. c o m value = StringUtils.removeStart(value, "+"); } map.put(orderGroupId, StringUtils.trim(value)); map.put(orderGroupId + ".sort", sortAsc ? Predicate.SORT_ASCENDING : Predicate.SORT_DESCENDING); count++; } } else { final boolean isPage = isPage(request); final boolean isAsset = isAsset(request); final String prefix = getPropertyPrefix(request); if (StringUtils.isNotBlank(queryString)) { map.put(GROUP_ORDERBY_SCORE + SUFFIX_ORDERBY, AT + JcrConstants.JCR_SCORE); map.put(GROUP_ORDERBY_SCORE + SUFFIX_ORDERBY_SORT, Predicate.SORT_DESCENDING); } String modifiedOrderProperty = AT + JcrConstants.JCR_LASTMODIFIED; if (isPage) { modifiedOrderProperty = AT + prefix + NameConstants.PN_PAGE_LAST_MOD; } else if (isAsset) { modifiedOrderProperty = AT + prefix + JcrConstants.JCR_LASTMODIFIED; } map.put(GROUP_ORDERBY_MODIFIED + SUFFIX_ORDERBY, modifiedOrderProperty); map.put(GROUP_ORDERBY_MODIFIED + SUFFIX_ORDERBY_SORT, Predicate.SORT_DESCENDING); } return map; }
From source file:com.hangum.tadpole.rdb.core.editors.main.utils.SQLTextUtil.java
/** * ?? ? .//from w ww. j ava2 s . c o m * @param strWord * @return */ public static String removeSpecialChar(String strWord) { if (strWord == null) return ""; strWord = strWord.replace(";", ""); strWord = StringUtils.removeStart(strWord, ","); strWord = StringUtils.removeEnd(strWord, ","); strWord = StringUtils.removeStart(strWord, "("); strWord = StringUtils.removeEnd(strWord, ")"); return strWord; }
From source file:com.adobe.acs.commons.workflow.bulk.execution.impl.servlets.StartServlet.java
@Override @SuppressWarnings("squid:S1192") protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); try {/* w w w . j a v a2s. co m*/ final JSONObject params = new JSONObject(request.getParameter("params")); final ModifiableValueMap properties = request.getResource().adaptTo(ModifiableValueMap.class); properties.put("runnerType", params.getString("runnerType")); properties.put("queryType", params.getString("queryType")); properties.put("queryStatement", params.getString("queryStatement")); properties.put("relativePath", StringUtils.removeStart(params.optString("relativePath", ""), "/")); properties.put("workflowModel", params.getString("workflowModelId")); properties.put("interval", params.optInt("interval", 10)); properties.put("timeout", params.optInt("timeout", 30)); properties.put("throttle", params.optInt("throttle", 10)); properties.put("retryCount", params.optInt("retryCount", 0)); properties.put("batchSize", params.optInt("batchSize", 10)); String userEventData = params.optString("userEventData", null); if (userEventData != null && !userEventData.isEmpty()) { properties.put("userEventData", userEventData); } properties.put("purgeWorkflow", params.optBoolean("purgeWorkflow", false)); properties.put("autoThrottle", params.optBoolean("autoThrottle", true)); if (AEMWorkflowRunnerImpl.class.getName().equals(properties.get("runnerType", String.class)) && isTransient(request.getResourceResolver(), properties.get("workflowModel", String.class))) { properties.put("runnerType", AEMTransientWorkflowRunnerImpl.class.getName()); } // If FAM retires are enabled, then force BatchSize to be 1 if (FastActionManagerRunnerImpl.class.getName().equals(properties.get("runnerType", "")) && properties.get("retryCount", 0) > 0) { properties.put("batchSize", 1); } request.getResourceResolver().commit(); Config config = request.getResource().adaptTo(Config.class); bulkWorkflowEngine.initialize(config); bulkWorkflowEngine.start(config); response.sendRedirect( request.getResourceResolver().map(request, request.getResource().getPath()) + ".status.json"); } catch (JSONException e) { log.error("Could not parse HTTP Request params: {}", e); JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not initialize Bulk Workflow due to invalid parameters." + " Please review the form and try again.", e.getMessage()); } catch (RepositoryException e) { log.error("Could not initialize Bulk Workflow: {}", e); JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not initialize Bulk Workflow.", e.getMessage()); } catch (IllegalArgumentException e) { log.warn("Could not initialize Bulk Workflow due to invalid arguments: {}", e); JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not initialize Bulk Workflow due to invalid arguments.", e.getMessage()); } catch (Exception e) { log.error("Could not initialize Bulk Workflow due to unexpected error: {}", e); JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not start Bulk Workflow.", e.getMessage()); } }
From source file:elaborate.jaxrs.JAXUtils.java
/** * Returns the path of the annotated element, * or an empty string if no annotation is present. *///from ww w. j a v a 2s. c om static String pathValueOf(AnnotatedElement element) { Path annotation = element.getAnnotation(Path.class); String value = (annotation != null) ? annotation.value() : ""; return StringUtils.removeStart(value, "/"); }
From source file:info.magnolia.content2bean.impl.DescriptorFileBasedTypeMapping.java
protected void processFile(String fileName) { Properties props = new Properties(); InputStream stream = null;/*from w ww . j av a 2 s . c o m*/ try { stream = ClasspathResourcesUtil.getStream(fileName); props.load(stream); } catch (IOException e) { log.error("can't read collection to bean information " + fileName, e); } IOUtils.closeQuietly(stream); String className = StringUtils.replaceChars(fileName, File.separatorChar, '.'); className = StringUtils.removeStart(className, "."); className = StringUtils.removeEnd(className, ".content2bean"); try { Class<?> typeClass = Classes.getClassFactory().forName(className); TypeDescriptor typeDescriptor = processProperties(typeClass, props); addTypeDescriptor(typeClass, typeDescriptor); } catch (Exception e) { log.error("can't instantiate type descriptor for " + className, e); } }
From source file:com.github.rnewson.couchdb.lucene.couchdb.View.java
private String trim(final String fun) { String result = fun; result = StringUtils.trim(result);/*from ww w .j av a 2 s .c o m*/ result = StringUtils.removeStart(result, "\""); result = StringUtils.removeEnd(result, "\""); return result; }
From source file:com.antsdb.saltedfish.sql.mysql.InstructionGenerator.java
@SuppressWarnings("unchecked") static public Generator<ParseTree> getGenerator(ParseTree ctx) throws OrcaException { Class<?> klass = ctx.getClass(); Generator<ParseTree> generator = _generatorByName.get(klass); if (generator == null) { String key = StringUtils.removeStart(klass.getSimpleName(), "MysqlParser$"); key = StringUtils.removeEnd(key, "Context"); key += "Generator"; try {// ww w .ja v a2 s . c om key = InstructionGenerator.class.getPackage().getName() + "." + key; Class<?> generatorClass = Class.forName(key); generator = (Generator<ParseTree>) generatorClass.newInstance(); _generatorByName.put(klass, generator); } catch (Exception x) { throw new OrcaException("instruction geneartor is not found: " + key, x); } } return generator; }
From source file:co.marcin.novaguilds.command.admin.config.CommandAdminConfigGet.java
@Override public void execute(CommandSender sender, String[] args) throws Exception { if (args.length == 0) { command.getUsageMessage().send(sender); return;/* w w w . java 2s .co m*/ } String path = args[0]; String value = ""; Map<VarKey, String> vars = new HashMap<>(); FileConfiguration config = plugin.getConfigManager().getConfig(); if (!config.contains(path)) { Message.CHAT_INVALIDPARAM.send(sender); return; } if (config.isConfigurationSection(path)) { int depth = 1; String lastSection = null; vars.put(VarKey.DEPTH, ""); vars.put(VarKey.KEY, path); Message.CHAT_ADMIN_CONFIG_GET_LIST_SECTION.vars(vars).send(sender); for (String string : config.getConfigurationSection(path).getKeys(true)) { String[] prefixSplit = StringUtils.split(string, "."); String prefix = StringUtils.contains(string, ".") ? StringUtils.removeEnd(string, "." + prefixSplit[prefixSplit.length - 1]) : string; if (lastSection != null && !prefix.startsWith(lastSection)) { depth--; lastSection = null; } String space = ""; for (int i = 0; i < depth; i++) { space += " "; } vars.put(VarKey.DEPTH, space); if (config.isConfigurationSection(path + "." + string)) { depth++; lastSection = string; vars.put(VarKey.KEY, prefixSplit[prefixSplit.length - 1]); Message.CHAT_ADMIN_CONFIG_GET_LIST_SECTION.vars(vars).send(sender); } else { //key vars.put(VarKey.KEY, StringUtils.removeStart(string, prefix + ".")); Message.CHAT_ADMIN_CONFIG_GET_LIST_KEY.vars(vars).send(sender); } } } else { if (config.isList(path)) { value = StringUtils.join(config.getStringList(path), " "); } else { value = config.getString(path); } } vars.put(VarKey.KEY, path); vars.put(VarKey.VALUE, value); if (!value.isEmpty()) { Message.CHAT_ADMIN_CONFIG_GET_SINGLE.vars(vars).send(sender); } }