List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR
String LINE_SEPARATOR
To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.
Click Source Link
The line.separator
System Property.
From source file:com.admc.jcreole.JCreole.java
/** * Run this method with no parameters to see syntax requirements and the * available parameters.//w w w.j a va 2 s . co m * * N.b. do not call this method from a persistent program, because it * may call System.exit! * <p> * Any long-running program should use the lower-level methods in this * class instead (or directly use CreoleParser and CreoleScanner * instances). * </p> <p> * This method executes with all JCreole privileges. * </p> <p> * This method sets up the following htmlExpander mappings (therefore you * can reference these in both Creole and boilerplate text).<p> * <ul> * <li>sys|*: mappings for Java system properties * <li>isoDateTime * <li>isoDate * <li>pageTitle: Value derived from the specified Creole file name. * </ul> * * @throws IOException for any I/O problem that makes it impossible to * satisfy the request. * @throws CreoleParseException * if can not generate output, or if the run generates 0 output. * If the problem is due to input formatting, in most cases you * will get a CreoleParseException, which is a RuntimException, and * CreoleParseException has getters for locations in the source * data (though they will be offset for \r's in the provided * Creole source, if any). */ public static void main(String[] sa) throws IOException { String bpResPath = null; String bpFsPath = null; String outPath = null; String inPath = null; boolean debugs = false; boolean troubleshoot = false; boolean noBp = false; int param = -1; try { while (++param < sa.length) { if (sa[param].equals("-d")) { debugs = true; continue; } if (sa[param].equals("-t")) { troubleshoot = true; continue; } if (sa[param].equals("-r") && param + 1 < sa.length) { if (bpFsPath != null || bpResPath != null || noBp) throw new IllegalArgumentException(); bpResPath = sa[++param]; continue; } if (sa[param].equals("-f") && param + 1 < sa.length) { if (bpResPath != null || bpFsPath != null || noBp) throw new IllegalArgumentException(); bpFsPath = sa[++param]; continue; } if (sa[param].equals("-")) { if (noBp || bpFsPath != null || bpResPath != null) throw new IllegalArgumentException(); noBp = true; continue; } if (sa[param].equals("-o") && param + 1 < sa.length) { if (outPath != null) throw new IllegalArgumentException(); outPath = sa[++param]; continue; } if (inPath != null) throw new IllegalArgumentException(); inPath = sa[param]; } if (inPath == null) throw new IllegalArgumentException(); } catch (IllegalArgumentException iae) { System.err.println(SYNTAX_MSG); System.exit(1); } if (!noBp && bpResPath == null && bpFsPath == null) bpResPath = DEFAULT_BP_RES_PATH; String rawBoilerPlate = null; if (bpResPath != null) { if (bpResPath.length() > 0 && bpResPath.charAt(0) == '/') // Classloader lookups are ALWAYS relative to CLASSPATH roots, // and will abort if you specify a beginning "/". bpResPath = bpResPath.substring(1); InputStream iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(bpResPath); if (iStream == null) throw new IOException("Boilerplate inaccessible: " + bpResPath); rawBoilerPlate = IOUtil.toString(iStream); } else if (bpFsPath != null) { rawBoilerPlate = IOUtil.toString(new File(bpFsPath)); } String creoleResPath = (inPath.length() > 0 && inPath.charAt(0) == '/') ? inPath.substring(1) : inPath; // Classloader lookups are ALWAYS relative to CLASSPATH roots, // and will abort if you specify a beginning "/". InputStream creoleStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(creoleResPath); File inFile = (creoleStream == null) ? new File(inPath) : null; JCreole jCreole = (rawBoilerPlate == null) ? (new JCreole()) : (new JCreole(rawBoilerPlate)); if (debugs) { jCreole.setInterWikiMapper(new InterWikiMapper() { // This InterWikiMapper is just for prototyping. // Use wiki name of "nil" to force lookup failure for path. // Use wiki page of "nil" to force lookup failure for label. public String toPath(String wikiName, String wikiPage) { if (wikiName != null && wikiName.equals("nil")) return null; return "{WIKI-LINK to: " + wikiName + '|' + wikiPage + '}'; } public String toLabel(String wikiName, String wikiPage) { if (wikiPage == null) throw new RuntimeException("Null page name sent to InterWikiMapper"); if (wikiPage.equals("nil")) return null; return "{LABEL for: " + wikiName + '|' + wikiPage + '}'; } }); Expander creoleExpander = new Expander(Expander.PairedDelims.RECTANGULAR); creoleExpander.put("testMacro", "\n\n<<prettyPrint>>\n{{{\n" + "!/bin/bash -p\n\ncp /etc/inittab /tmp\n}}}\n"); jCreole.setCreoleExpander(creoleExpander); } jCreole.setPrivileges(EnumSet.allOf(JCreolePrivilege.class)); Expander exp = jCreole.getHtmlExpander(); Date now = new Date(); exp.putAll("sys", System.getProperties(), false); exp.put("isoDateTime", isoDateTimeFormatter.format(now), false); exp.put("isoDate", isoDateFormatter.format(now), false); exp.put("pageTitle", (inFile == null) ? creoleResPath.replaceFirst("[.][^.]*$", "").replaceFirst(".*[/\\\\.]", "") : inFile.getName().replaceFirst("[.][^.]*$", "")); if (troubleshoot) { // We don't write any HMTL output here. // Goal is just to output diagnostics. StringBuilder builder = (creoleStream == null) ? IOUtil.toStringBuilder(inFile) : IOUtil.toStringBuilder(creoleStream); int newlineCount = 0; int lastOffset = -1; int offset = builder.indexOf("\n"); for (; offset >= 0; offset = builder.indexOf("\n", offset + 1)) { lastOffset = offset; newlineCount++; } // Accommodate input files with no terminating newline: if (builder.length() > lastOffset + 1) newlineCount++; System.out.println("Input lines: " + newlineCount); Exception lastException = null; while (true) { try { jCreole.parseCreole(builder); break; } catch (Exception e) { lastException = e; } if (builder.charAt(builder.length() - 1) == '\n') builder.setLength(builder.length() - 1); offset = builder.lastIndexOf("\n"); if (offset < 1) break; newlineCount--; builder.setLength(builder.lastIndexOf("\n")); } System.out.println((lastException == null) ? "Input validates" : String.format("Error around input line %d: %s", newlineCount, lastException.getMessage())); return; } String generatedHtml = (creoleStream == null) ? jCreole.parseCreole(inFile) : jCreole.parseCreole(IOUtil.toStringBuilder(creoleStream)); String html = jCreole.postProcess(generatedHtml, SystemUtils.LINE_SEPARATOR); if (outPath == null) { System.out.print(html); } else { FileUtils.writeStringToFile(new File(outPath), html, "UTF-8"); } }
From source file:au.com.dw.testdatacapturej.builder.MethodBuilder.java
/** * Create the end of the method wrapping code. * /*from www . j av a2 s .co m*/ * e.g. would generate something like: * * return objectClassName; * } * * @param object Object to be logged for code generation * @return */ public String createMethodCompletion(Object object) { StringBuilder builder = new StringBuilder(); // this is a kludge, should really get the field name from the recursive logging if possible // but here we are assuming that the field name will be the class name suffixed by '0' builder.append("\nreturn "); builder.append(WordUtils.uncapitalize(object.getClass().getSimpleName()) + "0;"); builder.append(SystemUtils.LINE_SEPARATOR); // end of method builder.append("}"); builder.append(SystemUtils.LINE_SEPARATOR); builder.append(SystemUtils.LINE_SEPARATOR); return builder.toString(); }
From source file:mitm.common.security.cms.SignerIdentifierImpl.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Issuer: "); sb.append(ObjectUtils.toString(issuer)); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("Serial number: "); sb.append(BigIntegerUtils.hexEncode(serialNumber, "")); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("SubjectKeyIdentifier: "); sb.append(HexUtils.hexEncode(subjectKeyIdentifier)); return sb.toString(); }
From source file:au.com.dw.testdatacapturej.reflection.TestGenNullTest.java
/** * Test for null Collection field.//from w ww . jav a 2 s . c o m */ @Test public void nullCollectionTest() { try { logger.logObject(builder, handler.handle(new NullCollectionHolder())); String result = builder.getLog(); String expected = SystemUtils.LINE_SEPARATOR + "au.com.dw.testdatacapturej.mock.dataholder.NullCollectionHolder nullCollectionHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.NullCollectionHolder();" + SystemUtils.LINE_SEPARATOR + "nullCollectionHolder0.setNullField(null);" + SystemUtils.LINE_SEPARATOR + "nullCollectionHolder0.setImplNullField(null);" + SystemUtils.LINE_SEPARATOR; System.out.println(result); assertEquals(expected, result); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:com.github.restdriver.serverdriver.http.response.DefaultResponse.java
private String createSummaryString(int truncateLength) { StrBuilder httpString = new StrBuilder(); httpString.append(protocolVersion).append(" ").append(statusCode).append(" ").append(statusMessage); httpString.appendNewLine();/*from www . j av a 2s . c om*/ httpString.appendWithSeparators(headers, SystemUtils.LINE_SEPARATOR); if (StringUtils.isNotEmpty(content)) { httpString.appendNewLine(); httpString.appendNewLine(); httpString.append(StringUtils.abbreviate(content, truncateLength)); } return httpString.toString(); }
From source file:au.org.ala.delta.translation.TypeSetterTest.java
public void testLineWrapWithSpaceAtWrapPosition() { char[] input = new char[_lineWidth * 2]; Arrays.fill(input, 'a'); input[_lineWidth - 1] = ' '; _typeSetter.writeJustifiedText(new String(input), -1); _typeSetter.printBufferLine(false);/*w w w .j a va 2 s . co m*/ String[] lines = output().split(SystemUtils.LINE_SEPARATOR); char[] expectedLine1Chars = Arrays.copyOfRange(input, 0, _lineWidth - 1); char[] expectedLine2Chars = Arrays.copyOfRange(input, _lineWidth, input.length); String expectedLine1 = new String(expectedLine1Chars); String expectedLine2 = new String(expectedLine2Chars); assertEquals(expectedLine1, lines[0]); assertEquals(expectedLine2, lines[1]); // Now do it again as two separate writes _typeSetter.writeJustifiedText(expectedLine1, -1); _typeSetter.writeJustifiedText(expectedLine2, -1); _typeSetter.printBufferLine(false); lines = output().split(SystemUtils.LINE_SEPARATOR); assertEquals(expectedLine1, lines[0]); assertEquals(expectedLine2, lines[1]); }
From source file:com.google.gdt.eclipse.designer.smart.actions.ConfigureSmartGwtOperation.java
private void execute0() throws Exception { // ensure jars if (!ProjectUtils.hasType(m_javaProject, "com.smartgwt.client.widgets.BaseWidget")) { if (EnvironmentUtils.isTestingTime()) { ProjectUtils.addExternalJar(m_javaProject, m_libraryLocation + "/smartgwt.jar", null); ProjectUtils.addExternalJar(m_javaProject, m_libraryLocation + "/smartgwt-skins.jar", null); } else {//from ww w . j av a2 s. c om ProjectUtils.addJar(m_javaProject, m_libraryLocation + "/smartgwt.jar", null); ProjectUtils.addJar(m_javaProject, m_libraryLocation + "/smartgwt-skins.jar", null); } } // add elements into module DefaultModuleProvider.modify(m_module, new ModuleModification() { public void modify(ModuleElement moduleElement) throws Exception { moduleElement.addInheritsElement("com.smartgwt.SmartGwt"); } }); // add "script" into HTML { IFile htmlFile = Utils.getHTMLFile(m_module); if (htmlFile != null) { String content = IOUtils2.readString(htmlFile); int scriptIndex = content.indexOf("<script language="); if (scriptIndex != -1) { String prefix = StringUtilities.getLinePrefix(content, scriptIndex); String smartGWTScript = "<script> var isomorphicDir = \"" + m_module.getId() + "/sc/\"; </script>"; content = content.substring(0, scriptIndex) + smartGWTScript + SystemUtils.LINE_SEPARATOR + prefix + content.substring(scriptIndex); IOUtils2.setFileContents(htmlFile, content); } } } }
From source file:com.googlecode.markuputils.MarkupUtils.java
/** * // w ww .j av a2 s .c o m * @deprecated It is useless. */ @Deprecated public static <T extends Appendable & CharSequence> void appendNewLine(T buffer) { Validate.notNull(buffer, "buffer cannot be null"); append(buffer, SystemUtils.LINE_SEPARATOR); }
From source file:mitm.common.security.cms.SignerInfoImpl.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); String digestName = getDigestAlgorithmOID(); Digest digest = Digest.fromOID(digestName); if (digest != null) { digestName = digest.toString();//from ww w . jav a 2 s.c o m } Date signingTime = getSigningTime(); sb.append("CMS Version: "); sb.append(getVersion()); sb.append(SystemUtils.LINE_SEPARATOR); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("*** [SignerId] ***"); sb.append(SystemUtils.LINE_SEPARATOR); try { sb.append(getSignerId()); } catch (IOException e) { sb.append("Error getting signer Id. Message: " + e.getMessage()); } sb.append(SystemUtils.LINE_SEPARATOR); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("Digest: "); sb.append(digestName); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("Encryption alg. OID: "); sb.append(getEncryptionAlgorithmOID()); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("Signing time: "); sb.append(ObjectUtils.toString(signingTime)); sb.append(SystemUtils.LINE_SEPARATOR); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("Signed attributes: "); sb.append(SystemUtils.LINE_SEPARATOR); sb.append(ASN1Utils.dump(getSignedAttributes())); sb.append(SystemUtils.LINE_SEPARATOR); sb.append("Unsigned attributes: "); sb.append(SystemUtils.LINE_SEPARATOR); sb.append(SystemUtils.LINE_SEPARATOR); sb.append(ASN1Utils.dump(getUnsignedAttributes())); return sb.toString(); }
From source file:com.google.gdt.eclipse.designer.gxt.actions.ConfigureExtGwtOperation.java
private void execute0() throws Exception { // ensure jar if (!ProjectUtils.hasType(m_javaProject, "com.extjs.gxt.ui.client.widget.Component")) { String jarPath = getJarPath(m_libraryLocation); if (EnvironmentUtils.isTestingTime()) { ProjectUtils.addExternalJar(m_javaProject, jarPath, null); } else {/* w w w. jav a 2s . c o m*/ ProjectUtils.addJar(m_javaProject, jarPath, null); } } // copy resources { File resourcesSourceDir = new File(new File(m_libraryLocation), "resources"); IFolder webFolder = WebUtils.getWebFolder(m_javaProject); File webDir = webFolder.getLocation().toFile(); File resourceTargetDir = new File(webDir, "ExtGWT"); FileUtils.copyDirectory(resourcesSourceDir, resourceTargetDir); webFolder.refreshLocal(IResource.DEPTH_INFINITE, null); } // add elements into module DefaultModuleProvider.modify(m_module, new ModuleModification() { public void modify(ModuleElement moduleElement) throws Exception { moduleElement.addInheritsElement("com.extjs.gxt.ui.GXT"); } }); // add "stylesheet" into HTML { IFile htmlFile = Utils.getHTMLFile(m_module); if (htmlFile != null) { String content = IOUtils2.readString(htmlFile); int linkIndex = content.indexOf("<link type="); if (linkIndex != -1) { String prefix = StringUtilities.getLinePrefix(content, linkIndex); String GXTStylesheet = "<link type=\"text/css\" rel=\"stylesheet\" href=\"ExtGWT/css/gxt-all.css\">"; content = content.substring(0, linkIndex) + GXTStylesheet + SystemUtils.LINE_SEPARATOR + prefix + content.substring(linkIndex); IOUtils2.setFileContents(htmlFile, content); } } } }