Java Code Examples for org.apache.commons.lang.StringUtils#removeStart()
The following examples show how to use
org.apache.commons.lang.StringUtils#removeStart() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionLayoutUtils.java From rice with Educational Community License v2.0 | 6 votes |
public static void prepareSelectFieldForLine(Field selectField, CollectionGroup collectionGroup, String lineBindingPath, Object line) { // if select property name set use as property name for select field String selectPropertyName = collectionGroup.getLineSelectPropertyName(); if (StringUtils.isNotBlank(selectPropertyName)) { // if select property contains form prefix, will bind to form and not each line if (selectPropertyName.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) { selectPropertyName = StringUtils.removeStart(selectPropertyName, UifConstants.NO_BIND_ADJUST_PREFIX); ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName); ((DataBinding) selectField).getBindingInfo().setBindToForm(true); } else { ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName); ((DataBinding) selectField).getBindingInfo().setBindByNamePrefix(lineBindingPath); } } else { // select property name not given, use UifFormBase#selectedCollectionLines String collectionLineKey = KRADUtils.translateToMapSafeKey( collectionGroup.getBindingInfo().getBindingPath()); String selectBindingPath = UifPropertyPaths.SELECTED_COLLECTION_LINES + "['" + collectionLineKey + "']"; ((DataBinding) selectField).getBindingInfo().setBindingName(selectBindingPath); ((DataBinding) selectField).getBindingInfo().setBindToForm(true); } setControlValueToLineIdentifier(selectField, line, lineBindingPath); }
Example 2
Source File: QueryPanel.java From nosql4idea with Apache License 2.0 | 6 votes |
void notifyOnErrorForOperator(JComponent component, Exception ex) { String message; if (ex instanceof JSONParseException) { message = StringUtils.removeStart(ex.getMessage(), "\n"); } else { message = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage()); } NonOpaquePanel nonOpaquePanel = new NonOpaquePanel(); JTextPane textPane = Messages.configureMessagePaneUi(new JTextPane(), message); textPane.setFont(COURIER_FONT); textPane.setBackground(MessageType.ERROR.getPopupBackground()); nonOpaquePanel.add(textPane, BorderLayout.CENTER); nonOpaquePanel.add(new JLabel(MessageType.ERROR.getDefaultIcon()), BorderLayout.WEST); JBPopupFactory.getInstance().createBalloonBuilder(nonOpaquePanel) .setFillColor(MessageType.ERROR.getPopupBackground()) .createBalloon() .show(new RelativePoint(component, new Point(0, 0)), Balloon.Position.above); }
Example 3
Source File: MessageStructureUtils.java From rice with Educational Community License v2.0 | 6 votes |
/** * Process the additional properties beyond index 0 of the tag (that was split into parts). * * <p>This will evaluate and set each of properties on the component passed in. This only allows * setting of properties that can easily be converted to/from/are String type by Spring.</p> * * @param component component to have its properties set * @param tagParts the tag split into parts, index 0 is ignored * @return component with its properties set found in the tag's parts */ private static Component processAdditionalProperties(Component component, String[] tagParts) { String componentString = tagParts[0]; tagParts = (String[]) ArrayUtils.remove(tagParts, 0); for (String part : tagParts) { String[] propertyValue = part.split("="); if (propertyValue.length == 2) { String path = propertyValue[0]; String value = propertyValue[1].trim(); value = StringUtils.removeStart(value, "'"); value = StringUtils.removeEnd(value, "'"); ObjectPropertyUtils.setPropertyValue(component, path, value); } else { throw new RuntimeException( "Invalid Message structure for component defined as " + componentString + " around " + part); } } return component; }
Example 4
Source File: InstructionGenerator.java From antsdb with GNU Lesser General Public License v3.0 | 6 votes |
@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 { 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; }
Example 5
Source File: NamedAsVisitor.java From zstack with Apache License 2.0 | 5 votes |
@Override public String visitNamedAs(ZQLParser.NamedAsContext ctx) { String name = ctx.namedAsValue().getText(); name = StringUtils.removeStart(name, "'"); name = StringUtils.removeStart(name, "\""); name = StringUtils.removeEnd(name, "\""); name = StringUtils.removeEnd(name, "'"); return name; }
Example 6
Source File: ConfigurationProxyUtils.java From staash with Apache License 2.0 | 5 votes |
static String getPropertyName(Method method, Configuration c) { String name = c.value(); if (name.isEmpty()) { name = method.getName(); name = StringUtils.removeStart(name, "is"); name = StringUtils.removeStart(name, "get"); name = name.toLowerCase(); } return name; }
Example 7
Source File: MessageStructureUtils.java From rice with Educational Community License v2.0 | 5 votes |
/** * Inserts &nbsp; into the string passed in, if spaces exist at the beginning and/or end, * so spacing is not lost in html translation. * * @param text string to insert &nbsp; * @return String with &nbsp; inserted, if applicable */ public static String addBlanks(String text) { if (StringUtils.startsWithIgnoreCase(text, " ")) { text = " " + StringUtils.removeStart(text, " "); } if (text.endsWith(" ")) { text = StringUtils.removeEnd(text, " ") + " "; } return text; }
Example 8
Source File: DefaultExpressionEvaluator.java From rice with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object evaluateExpression(Map<String, Object> evaluationParameters, String expressionStr) { Object result = null; // if expression contains placeholders remove before evaluating if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith( expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) { expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX); expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX); } try { Expression expression = retrieveCachedExpression(expressionStr); if (evaluationParameters != null) { evaluationContext.setVariables(evaluationParameters); } result = expression.getValue(evaluationContext); } catch (Exception e) { LOG.error("Exception evaluating expression: " + expressionStr); throw new RuntimeException("Exception evaluating expression: " + expressionStr, e); } return result; }
Example 9
Source File: Session_variable_referenceGenerator.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Instruction gen(GeneratorContext ctx, Session_variable_referenceContext rule) throws OrcaException { String name = rule.SESSION_VARIABLE().getText(); name = StringUtils.removeStart(name, "@@"); return new GetSystemVarible(name); }
Example 10
Source File: MessageStructureUtils.java From rice with Educational Community License v2.0 | 5 votes |
/** * Process a piece of the message that has css content by creating a span with those css classes set * * @param messagePiece String piece with css class content * @param currentMessageComponent the state of the current text based message being built * @param view current View * @return currentMessageComponent with the new textual content generated by this method appended to its * messageText */ private static Message processCssClassContent(String messagePiece, Message currentMessageComponent, View view) { if (!StringUtils.startsWithIgnoreCase(messagePiece, "/")) { messagePiece = StringUtils.remove(messagePiece, "'"); messagePiece = StringUtils.remove(messagePiece, "\""); messagePiece = "<span class='" + StringUtils.removeStart(messagePiece, KRADConstants.MessageParsing.CSS_CLASSES + "=") + "'>"; } else { messagePiece = "</span>"; } return concatenateStringMessageContent(currentMessageComponent, messagePiece, view); }
Example 11
Source File: CommitStatusUpdater.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private static String getBuildBranchOrTag(Run<?, ?> build) { GitLabWebHookCause cause = build.getCause(GitLabWebHookCause.class); if (cause == null) { return null; } if (cause.getData().getActionType() == CauseData.ActionType.TAG_PUSH) { return StringUtils.removeStart(cause.getData().getSourceBranch(), "refs/tags/"); } return cause.getData().getSourceBranch(); }
Example 12
Source File: DataTools.java From util4j with Apache License 2.0 | 5 votes |
/** * 根据字节数组拆分若干个字字节数组 * @param data * @param separator * @return */ public byte[][] getsonArrays(byte[] data,byte[] separator) { if(data==null||data.length<=0||separator==null||separator.length<=0) { System.out.println("data||separator数据无效!"); return null; } String[] dataHexArray=byteArrayToHexArray(data); String dataHexStr=StringUtils.substringBetween(Arrays.toString(dataHexArray), "[", "]").replaceAll("\\s",""); //System.out.println("待拆分字符串:"+dataHexStr); String[] separatorHexhArray=byteArrayToHexArray(separator); String separatorHexStr=StringUtils.substringBetween(Arrays.toString(separatorHexhArray), "[", "]").replaceAll("\\s",""); //System.out.println("字符串拆分符:"+separatorHexStr); //得到拆分后的数组 String[] arrays=StringUtils.splitByWholeSeparator(dataHexStr, separatorHexStr); //System.out.println("拆分后的数组:"+Arrays.toString(arrays)); if(arrays==null||arrays.length<=0) { System.out.println("注意:数组拆分为0"); return null; } byte[][] result=new byte[arrays.length][]; //对子数组进行重组 for(int i=0;i<arrays.length;i++) { String arrayStr=arrays[i]; arrayStr=StringUtils.removeStart(arrayStr, ",");//去掉两端的逗号 arrayStr=StringUtils.removeEnd(arrayStr, ",");//去掉两端的逗号 String[] array=arrayStr.split(",");//根据子字符串中间剩余的逗号重组为hex字符串 result[i]=hexArrayToBtyeArray(array); } return result; }
Example 13
Source File: FileUtils.java From airsonic with GNU General Public License v3.0 | 5 votes |
public static boolean copyJarResourcesRecursively( final File destDir, final JarURLConnection jarConnection ) throws IOException { final JarFile jarFile = jarConnection.getJarFile(); for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) { final JarEntry entry = e.nextElement(); if (entry.getName().startsWith(jarConnection.getEntryName())) { final String filename = StringUtils.removeStart( entry.getName(), // jarConnection.getEntryName()); final File f = new File(destDir, filename); if (!entry.isDirectory()) { final InputStream entryInputStream = jarFile.getInputStream(entry); if (!FileUtils.copyStream(entryInputStream, f)) { return false; } entryInputStream.close(); } else { if (!FileUtils.ensureDirectoryExists(f)) { throw new IOException("Could not create directory: " + f.getAbsolutePath()); } } } } return true; }
Example 14
Source File: SimpleDdlParser.java From binlake with Apache License 2.0 | 4 votes |
private static String removeEscape(String str) { String result = StringUtils.removeEnd(str, "`"); result = StringUtils.removeStart(result, "`"); return result; }
Example 15
Source File: TimeBasedSubDirDatasetsFinder.java From incubator-gobblin with Apache License 2.0 | 4 votes |
protected String getDatasetName(String path, String basePath) { int startPos = path.indexOf(basePath) + basePath.length(); return StringUtils.removeStart(path.substring(startPos), "/"); }
Example 16
Source File: KRADUtils.java From rice with Educational Community License v2.0 | 4 votes |
/** * Attempts to generate a unique view title by combining the View's headerText with the title attribute for the * dataObjectClass found through the DataObjectMetaDataService. If the title attribute cannot be found, just the * headerText is returned. * * @param form the form * @param view the view * @return the headerText with the title attribute in parenthesis or just the headerText if it title attribute * cannot be determined */ public static String generateUniqueViewTitle(UifFormBase form, View view) { String title = view.getHeader().getHeaderText(); String viewLabelPropertyName = ""; Class<?> dataObjectClass; if (StringUtils.isNotBlank(view.getDefaultBindingObjectPath())) { dataObjectClass = ObjectPropertyUtils.getPropertyType(form, view.getDefaultBindingObjectPath()); } else { dataObjectClass = view.getFormClass(); } if (dataObjectClass != null) { viewLabelPropertyName = KRADServiceLocatorWeb.getLegacyDataAdapter().getTitleAttribute(dataObjectClass); } String viewLabelPropertyPath = ""; if (StringUtils.isNotBlank(viewLabelPropertyName)) { // adjust binding prefix if (!viewLabelPropertyName.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) { if (StringUtils.isNotBlank(view.getDefaultBindingObjectPath())) { viewLabelPropertyPath = view.getDefaultBindingObjectPath() + "." + viewLabelPropertyName; } } else { viewLabelPropertyPath = StringUtils.removeStart(viewLabelPropertyName, UifConstants.NO_BIND_ADJUST_PREFIX); } } else { // attempt to get title attribute if (StringUtils.isNotBlank(view.getDefaultBindingObjectPath())) { dataObjectClass = ViewModelUtils.getObjectClassForMetadata(view, form, view.getDefaultBindingObjectPath()); } else { dataObjectClass = view.getFormClass(); } if (dataObjectClass != null) { String titleAttribute = KRADServiceLocatorWeb.getLegacyDataAdapter().getTitleAttribute(dataObjectClass); if (StringUtils.isNotBlank(titleAttribute)) { viewLabelPropertyPath = view.getDefaultBindingObjectPath() + "." + titleAttribute; } } } Object viewLabelPropertyValue = null; if (StringUtils.isNotBlank(viewLabelPropertyPath) && ObjectPropertyUtils.isReadableProperty(form, viewLabelPropertyPath)) { viewLabelPropertyValue = ObjectPropertyUtils.getPropertyValueAsText(form, viewLabelPropertyPath); } if (viewLabelPropertyValue != null && StringUtils.isNotBlank(viewLabelPropertyValue.toString()) && StringUtils .isNotBlank(title)) { return title + " (" + viewLabelPropertyValue.toString() + ")"; } else { return title; } }
Example 17
Source File: LocationInfo.java From otroslogviewer with Apache License 2.0 | 4 votes |
/** * build a LocationInfo instance from one line of a stackTrace * * @param fullInfo one line from a stacktrace) * @return a LocationInfo based on the input (or null if input could not be parsed) */ public static LocationInfo parse(String fullInfo) { if (fullInfo == null) { return null; } fullInfo = removeLambdas(fullInfo); fullInfo = fullInfo.trim(); fullInfo = StringUtils.removeStart(fullInfo, "at "); int lastClosingBrace = fullInfo.indexOf(')'); int lastColon = fullInfo.lastIndexOf(':', lastClosingBrace); int lastOpeningBrace = fullInfo.lastIndexOf('(', lastColon); if (lastOpeningBrace == -1 || lastClosingBrace == -1 || lastColon == -1) { return null; } String packageName; String className; String methodName; String fileName; Optional<Integer> lineNumber; final String lineNumberString = fullInfo.substring(lastColon + 1, lastClosingBrace); lineNumber = Optional.of(Integer.parseInt(lineNumberString)); fileName = fullInfo.substring(lastOpeningBrace + 1, lastColon); // packageName fullInfo = fullInfo.substring(0, lastOpeningBrace); int lastDot = fullInfo.lastIndexOf('.'); if (lastDot == -1) { return null; } else { methodName = fullInfo.substring(lastDot + 1); className = fullInfo.substring(0, lastDot); lastDot = className.lastIndexOf("."); if (lastDot == -1) { packageName = ""; // the default package } else { packageName = className.substring(0, lastDot); } } return new LocationInfo( Optional.of(packageName), Optional.of(className), Optional.of(methodName), Optional.of(fileName), lineNumber, Optional.empty()); }
Example 18
Source File: BindingConfigParser.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * Parses the bindingConfig of an item and returns a AstroBindingConfig. */ public AstroBindingConfig parse(Item item, String bindingConfig) throws BindingConfigParseException { bindingConfig = StringUtils.trimToEmpty(bindingConfig); bindingConfig = StringUtils.removeStart(bindingConfig, "{"); bindingConfig = StringUtils.removeEnd(bindingConfig, "}"); String[] entries = bindingConfig.split("[,]"); AstroBindingConfigHelper helper = new AstroBindingConfigHelper(); for (String entry : entries) { String[] entryParts = StringUtils.trimToEmpty(entry).split("[=]"); if (entryParts.length != 2) { throw new BindingConfigParseException("A bindingConfig must have a key and a value"); } String key = StringUtils.trim(entryParts[0]); String value = StringUtils.trim(entryParts[1]); value = StringUtils.removeStart(value, "\""); value = StringUtils.removeEnd(value, "\""); try { if ("offset".equalsIgnoreCase(key)) { helper.getClass().getDeclaredField(key).set(helper, Integer.valueOf(value.toString())); } else { helper.getClass().getDeclaredField(key).set(helper, value); } } catch (Exception e) { throw new BindingConfigParseException("Could not set value " + value + " for attribute " + key); } } if (helper.isOldStyle()) { logger.warn( "Old Astro binding style for item {}, please see Wiki page for new style: https://github.com/openhab/openhab/wiki/Astro-binding", item.getName()); return getOldAstroBindingConfig(helper); } if (!helper.isValid()) { throw new BindingConfigParseException("Invalid binding: " + bindingConfig); } PlanetName planetName = getPlanetName(helper); if (planetName == null) { throw new BindingConfigParseException("Invalid binding, unknown planet: " + bindingConfig); } AstroBindingConfig astroConfig = new AstroBindingConfig(planetName, helper.type, helper.property, helper.offset); if (!PropertyUtils.hasProperty(context.getPlanet(astroConfig.getPlanetName()), astroConfig.getPlanetProperty())) { throw new BindingConfigParseException("Invalid binding, unknown type or property: " + bindingConfig); } return astroConfig; }
Example 19
Source File: PathUtils.java From incubator-gobblin with Apache License 2.0 | 2 votes |
/** * Removes the leading slash if present. * */ public static Path withoutLeadingSeparator(Path path) { return new Path(StringUtils.removeStart(path.toString(), Path.SEPARATOR)); }
Example 20
Source File: S3InitiateFileUploadOperator.java From attic-apex-malhar with Apache License 2.0 | 2 votes |
/** * Generates the key name from the given file path and output directory path. * @param filePath file path to upload * @return key name for the given file */ private String getKeyName(String filePath) { return outputDirectoryPath + Path.SEPARATOR + StringUtils.removeStart(filePath, Path.SEPARATOR); }