List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size)
Left pad a String with spaces (' ').
From source file:org.beangle.struts2.view.freemarker.BeangleFreemarkerManager.java
/** * Load the multi settings from the /META-INF/freemarker.properties and * /freemarker.properties file on the classpath * //w w w . j av a2s . c o m * @see freemarker.template.Configuration#setSettings for the definition of * valid settings */ @SuppressWarnings("unchecked") @Override protected void loadSettings(ServletContext servletContext) { try { Properties properties = new Properties(); Enumeration<?> em = BeangleFreemarkerManager.class.getClassLoader() .getResources("META-INF/freemarker.properties"); while (em.hasMoreElements()) { properties.putAll(getProperties((URL) em.nextElement())); } em = BeangleFreemarkerManager.class.getClassLoader().getResources("freemarker.properties"); while (em.hasMoreElements()) { properties.putAll(getProperties((URL) em.nextElement())); } StringBuilder sb = new StringBuilder(); @SuppressWarnings("rawtypes") List keys = CollectUtils.newArrayList(properties.keySet()); Collections.sort(keys); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); String value = (String) properties.get(key); if (key == null) { throw new IOException( "init-param without param-name. Maybe the freemarker.properties is not well-formed?"); } if (value == null) { throw new IOException( "init-param without param-value. Maybe the freemarker.properties is not well-formed?"); } addSetting(key, value); sb.append(StringUtils.leftPad(key, 21)).append(" : ").append(value); if (iter.hasNext()) sb.append('\n'); } logger.info("Freemarker properties: ->\n{} ", sb); } catch (IOException e) { logger.error("Error while loading freemarker.properties", e); } catch (TemplateException e) { logger.error("Error while setting freemarker.properties", e); } }
From source file:org.codehaus.mojo.mrm.servlet.FileSystemServlet.java
private void serveDirectoryAsHTML(HttpServletResponse resp, String path, String context, DirectoryEntry dirEntry, Entry[] entries) throws IOException { resp.setContentType("text/html"); PrintWriter w = resp.getWriter(); w.println("<html>"); w.println(" <head>"); w.println(" <title>Index of " + context + path + "</title>"); w.println(" <meta http-equiv=\"Content-Type\" repository=\"text/html; charset=utf-8\"/>"); w.println("</head>"); w.println("<body>"); w.println("<h1>Index of " + context + path + "</h1>"); w.println(" <hr/>"); w.write("<pre>"); if (dirEntry.getParent() != null) { w.println("<a href='../'>../</a>"); }/*from w w w. java2s . co m*/ SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy hh:mm"); if (entries != null) { for (int i = 0; i < entries.length; i++) { final String childName = entries[i].getName(); boolean directory = entries[i] instanceof DirectoryEntry; if (directory) { String dirName = childName + "/"; w.write("<a href=\"./" + Utils.urlEncodePathSegment(childName) + "/\">" + formatName(dirName) + "</a>" + StringUtils.repeat(" ", Math.max(0, NAME_COL_WIDTH - dirName.length()))); } else { w.write("<a href=\"./" + Utils.urlEncodePathSegment(childName) + "\">" + formatName(childName) + "</a>" + StringUtils.repeat(" ", Math.max(0, NAME_COL_WIDTH - childName.length()))); } long timestamp = 0; try { timestamp = entries[i].getLastModified(); } catch (IOException e) { // ignore } w.write(" "); w.write(format.format(timestamp != -1 ? new Date(timestamp) : new Date())); if (directory) { w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH)); } else if (entries[i] instanceof FileEntry) { FileEntry fileEntry = (FileEntry) entries[i]; try { long size = fileEntry.getSize(); if (size >= 0) { w.println(StringUtils.leftPad(Long.toString(size), SIZE_COL_WIDTH)); } else { w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH)); } } catch (IOException e) { w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH)); } } else { w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH)); } } } w.write("</pre>"); w.println(" <hr/>"); w.println("</body>"); w.println("</html>"); return; }
From source file:org.coode.outlinetree.test.TestExistentialModel.java
private OutlineNode findNode(OutlineTreeModel model, OutlineNode start, OWLClass namedClass) { indent++;/* w w w . j a va2s.c om*/ for (int i = 0; i < model.getChildCount(start); i++) { OutlineNode child = model.getChild(start, i); System.out.println(StringUtils.leftPad("+ " + child, indent * 2)); Object obj = child.getUserObject(); if (obj.equals(namedClass)) { return child; } else if (!model.isLeaf(child)) { OutlineNode node = findNode(model, child, namedClass); if (node != null) { return node; } } } indent--; return null; }
From source file:org.dkpro.lab.reporting.FlexTable.java
public StreamWriter getTextWriter() { return new StreamWriter() { @Override/* www . ja v a 2 s . co m*/ public void write(OutputStream aStream) throws Exception { String[] colIds = FlexTable.this.compact ? getCompactColumnIds(false) : getColumnIds(); // Obtain the width of the columns based on their content and headers // col 0 is reserved here for the rowId width int colWidths[] = new int[colIds.length + 1]; for (String rowId : getRowIds()) { colWidths[0] = Math.max(colWidths[0], rowId.length()); } for (int i = 1; i < colWidths.length; i++) { colWidths[i] = Math.max(colWidths[i], colIds[i - 1].length()); for (String rowId : getRowIds()) { colWidths[i] = Math.max(colWidths[i], getValueAsString(rowId, colIds[i - 1]).length()); } } StringBuilder separator = new StringBuilder(); for (int w : colWidths) { if (separator.length() > 0) { separator.append("-+-"); } separator.append(StringUtils.repeat("-", w)); } separator.insert(0, "+-"); separator.append("-+"); PrintWriter writer = new PrintWriter(new OutputStreamWriter(aStream, "UTF-8")); // Render header column writer.println(separator); writer.print("| "); writer.print(StringUtils.repeat(" ", colWidths[0])); for (int i = 0; i < colIds.length; i++) { writer.print(" | "); // Remember: colWidth[0] is the rowId width! writer.print(StringUtils.center(colIds[i], colWidths[i + 1])); } writer.println(" |"); writer.println(separator); // Render body for (String rowId : getRowIds()) { writer.print("| "); writer.print(StringUtils.rightPad(rowId, colWidths[0])); for (int i = 0; i < colIds.length; i++) { writer.print(" | "); // Remember: colWidth[0] is the rowId width! String val = getValueAsString(rowId, colIds[i]); if (isDouble(val)) { writer.print(StringUtils.leftPad(val, colWidths[i + 1])); } else { writer.print(StringUtils.rightPad(val, colWidths[i + 1])); } } writer.println(" |"); } // Closing separator writer.println(separator); writer.flush(); } private boolean isDouble(String val) { try { double d = Double.parseDouble(val); // TODO: A bit of a hack; use Regex instead? } catch (NumberFormatException ex) { return false; } return true; } }; }
From source file:org.eclipse.mylyn.reviews.r4e.upgrade.utils.SimpleFileConverter.java
/** * Method convert./* w w w . ja v a2s. com*/ * @param aFile - File * @throws FileNotFoundException * @throws IOException */ protected void convert(File aFile) throws FileNotFoundException, IOException { Path path = new Path(aFile.getAbsolutePath()); if (!aFile.isDirectory() && path.getFileExtension() == null) { return; } for (String ext : fIgnoreExtensions) { if (StringUtils.equals(ext, path.getFileExtension())) { return; } } if (aFile.exists()) { if (aFile.isDirectory()) { for (File member : aFile.listFiles()) { if (fRecurse || !aFile.isDirectory()) { convert(member); } } //return; } else { if (path.getFileExtension() == null) { return; } if (path.getFileExtension().equals(fExtension)) { log(LINE_FEED + " " + aFile.getAbsolutePath()); fFilesConverted++; BufferedReader br = new BufferedReader(new FileReader(aFile)); StringBuilder fileContents = new StringBuilder(8000); int lineNum = 0; while (br.ready()) { String line = br.readLine(); String convert = convert(line); fileContents.append(convert + LINE_FEED); if (!line.equals(convert)) { String lineNumString = StringUtils.leftPad(lineNum + "", 5); log(" " + lineNumString + ": " + line + LINE_FEED + " " + convert); } lineNum++; } br.close(); BufferedWriter writer = new BufferedWriter(new FileWriter(aFile)); writer.write(fileContents.toString()); writer.close(); } } } fMonitor.worked(1); }
From source file:org.geoserver.wfs.response.dxf.AbstractDXFWriter.java
/** * Writes the simplest dxf object, a group, composed of a numeric code and a value. The value * type can be interpreted looking at the code. * /*from w ww . j av a 2 s . c om*/ * @param code * @param value * @throws IOException */ protected void writeGroup(int code, String value) throws IOException { writer.write(StringUtils.leftPad(code + "", 3) + EOL); writer.write(value + EOL); }
From source file:org.geoserver.wfs.response.dxf.AbstractDXFWriter.java
/** * Writes a group having an integer value. * // w ww . jav a 2 s . com * @param code * @param value * @throws IOException */ protected void writeIntegerGroup(int code, int value) throws IOException { writeGroup(code, StringUtils.leftPad(value + "", 6)); }
From source file:org.geoserver.wfs.response.dxf.AbstractDXFWriter.java
protected void writeFlags(int code, int value) throws IOException { writeGroup(code, StringUtils.leftPad(value + "", 9)); }
From source file:org.jahia.services.content.JCRPublicationService.java
public void print(Version v, int indent) throws RepositoryException { System.out.print(StringUtils.leftPad("", indent) + "---- " + v.getName()); Version[] preds = v.getPredecessors(); System.out.print("("); for (Version pred : preds) { System.out.print(" " + pred.getName()); }/*from w w w. j a v a 2 s. c o m*/ System.out.print(")"); System.out.println(""); Version[] succ = v.getSuccessors(); for (Version version : succ) { print(version, indent + 2); } }
From source file:org.jumpmind.symmetric.util.SnapshotUtil.java
protected static void printDirectoryContents(File dir, StringBuilder output) throws IOException { output.append("\n"); output.append(dir.getCanonicalPath()); output.append("\n"); File[] files = dir.listFiles(); for (File file : files) { output.append(" "); output.append(file.canRead() ? "r" : "-"); output.append(file.canWrite() ? "w" : "-"); output.append(file.canExecute() ? "x" : "-"); output.append(StringUtils.leftPad(file.length() + "", 11)); output.append(" "); output.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(file.lastModified()))); output.append(" "); output.append(file.getName());/*from w w w . ja v a 2 s . co m*/ output.append("\n"); } for (File file : files) { if (file.isDirectory()) { printDirectoryContents(file, output); } } }