List of usage examples for org.springframework.util StringUtils trimLeadingWhitespace
public static String trimLeadingWhitespace(String str)
From source file:com.asual.summer.core.faces.FacesResponseWriter.java
private void printTextIfNecessary(boolean end) throws IOException { String textStr = textWriter.toString(); if (StringUtils.hasText(textStr)) { String name = nodeDepth[depth]; textStr = textStr.replaceAll("\t", INDENT); if (ComponentUtils.isStyleOrScript(name)) { textStr = Pattern.compile("^\\s{" + calculateIndent(textStr) + "}", Pattern.MULTILINE) .matcher(textStr).replaceAll(getIndent(depth)).trim(); }//w ww . ja va2 s . c o m if (block.contains(name) && !pre.contains(name)) { Matcher m = Pattern.compile("^( *\\n)+.*", Pattern.DOTALL).matcher(textStr); if (m.matches()) { textStr = m.replaceFirst("$1") + getIndent(depth) + StringUtils.trimLeadingWhitespace(textStr); } else if (start) { textStr = "\n" + getIndent(depth) + StringUtils.trimLeadingWhitespace(textStr); } m = Pattern.compile(".*(\\n)+ *$", Pattern.DOTALL).matcher(textStr); if (m.matches()) { textStr = StringUtils.trimTrailingWhitespace(textStr) + m.replaceFirst("$1") + getIndent(depth); } } if (end) { textStr = StringUtils.trimTrailingWhitespace(textStr); } writer.write(textStr); textWriter.getBuffer().setLength(0); start = false; nodeDepth[depth + 1] = null; for (int i = 0; i < depth + 1; i++) { nodeDepthContent[i] = true; } } }
From source file:com.asual.summer.core.faces.FacesResponseWriter.java
private int calculateIndent(String textStr) { int indent = 1000; String[] lines = textStr.split("\n|\r\n"); for (String line : lines) { if (StringUtils.hasText(line)) { indent = Math.min(indent, line.length() - StringUtils.trimLeadingWhitespace(line).length()); }//from www. j a v a 2 s.co m } return indent; }
From source file:org.kuali.kfs.sys.batch.AbstractFlatFilePropertySpecificationBase.java
/** * Sets the property on the business object * @param value the substring of the parsed line to set * @param businessObject the business object to set the parsed line on * @param lineNumber the parsed line number *//*from ww w . j av a 2s . c o m*/ @Override public void setProperty(String value, Object businessObject, int lineNumber) { if (leftTrim) { value = StringUtils.trimLeadingWhitespace(value); } if (rightTrim) { value = StringUtils.trimTrailingWhitespace(value); } try { PropertyUtils.setProperty(businessObject, propertyName, getFormattedObject(value, businessObject)); } catch (Exception e) { throw new RuntimeException("Exception occurred on line " + lineNumber + " while setting value " + value + " for property " + propertyName + ".", e); } }
From source file:org.romaframework.core.config.ComponentManager.java
protected void setupComponents() { String componentName;/* w w w.j a va 2s . c om*/ for (Iterator<String> it = componentClassNames.iterator(); it.hasNext();) { componentName = it.next(); if (componentName == null || componentName.length() == 0) continue; componentName = componentName.replace('\t', ' '); componentName = componentName.replace('\n', ' '); componentName = componentName.trim(); componentName = StringUtils.trimLeadingWhitespace(componentName); try { addComponent(componentName); } catch (Exception e) { log.error("[ComponentManager.setupComponents] Error" + e); } } componentClassNames = null; }