List of usage examples for org.apache.commons.io IOUtils LINE_SEPARATOR
String LINE_SEPARATOR
To view the source code for org.apache.commons.io IOUtils LINE_SEPARATOR.
Click Source Link
From source file:org.fuin.kickstart4j.Config.java
/** * Returns the configuration as XML with all variables replaced with their * values./*from w w w . j a v a 2s. com*/ * * @return XML configuration. */ public final String toStaticXML() { final StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\" encoding=\"" + xmlEncoding + "\"?>" + IOUtils.LINE_SEPARATOR); sb.append("<application>" + IOUtils.LINE_SEPARATOR); sb.append(" " + getTagLine("version", getVersion(), null)); sb.append(" " + getTagLine("title", getTitle(), null)); sb.append(" " + getTagLine("vendor", getVendor(), null)); sb.append(" " + getTagLine("description", getDescription(), null)); sb.append(" " + getTagLine("exitAfterExecute", isExitAfterExecute())); sb.append(" " + getTagLine("destPath", getDestPath(), null)); sb.append(" " + getTagLine("idFilename", getIdFilename(), ".yourapp")); sb.append(" " + getTagLine("silentInstall", isSilentInstall())); sb.append(" " + getTagLine("silentUpdate", isSilentUpdate())); sb.append(" " + getTagLine("locale", locale, Locale.getDefault())); sb.append(" " + getTagLine("lazyLoading", isLazyLoading())); sb.append(" " + getTagLine("showStartFrame", isShowStartFrame())); sb.append(" " + getTagLine("startFrameDelaySeconds", getStartFrameDelaySeconds())); sb.append(" " + getTagLine("logFilename", getLogFilename(), null)); sb.append(" " + getTagLine("javaExe", getJavaExe(), null)); sb.append(" " + getTagLine("javaArgs", getJavaArgs(), "-classpath ${classpath} com.company.product.MainClass")); sb.append(" " + getTagLine("msgFileUrl", msgFileUrl, null)); for (int i = 0; i < mkDirs.size(); i++) { final MkDir mkDir = (MkDir) mkDirs.get(i); sb.append(" " + mkDir.toXML() + IOUtils.LINE_SEPARATOR); } for (int i = 0; i < srcDirs.size(); i++) { final SrcDir srcDir = (SrcDir) srcDirs.get(i); sb.append(" " + srcDir.toXML() + IOUtils.LINE_SEPARATOR); } for (int i = 0; i < srcFiles.size(); i++) { final SrcFile srcFile = (SrcFile) srcFiles.get(i); sb.append(" " + srcFile.toXML() + IOUtils.LINE_SEPARATOR); } sb.append("</application>" + IOUtils.LINE_SEPARATOR); return sb.toString(); }
From source file:org.fuin.kickstart4j.Config.java
/** * Returns the configuration as XML with no variables replaced. * //from w w w.jav a 2 s . c o m * @return XML configuration. */ public final String toVarXML() { final StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\" encoding=\"" + xmlEncoding + "\"?>" + IOUtils.LINE_SEPARATOR); sb.append("<application>" + IOUtils.LINE_SEPARATOR); sb.append(" " + getTagLine("version", version, null)); sb.append(" " + getTagLine("title", title, "Your title")); sb.append(" " + getTagLine("vendor", vendor, null)); sb.append(" " + getTagLine("description", description, null)); sb.append(" " + getTagLine("exitAfterExecute", exitAfterExecute)); sb.append(" " + getTagLine("destPath", destPath, "C:\\Program Files\\yourapp\\")); sb.append(" " + getTagLine("idFilename", idFilename, ".yourapp")); sb.append(" " + getTagLine("silentInstall", silentInstall)); sb.append(" " + getTagLine("silentUpdate", silentUpdate)); sb.append(" " + getTagLine("locale", locale, Locale.getDefault())); sb.append(" " + getTagLine("lazyLoading", lazyLoading)); sb.append(" " + getTagLine("showStartFrame", isShowStartFrame())); sb.append(" " + getTagLine("startFrameDelaySeconds", getStartFrameDelaySeconds())); sb.append(" " + getTagLine("logFilename", logFilename, null)); sb.append(" " + getTagLine("javaExe", javaExe, "jre/bin/java.exe")); sb.append(" " + getTagLine("javaArgs", javaArgs, "-classpath ${classpath} com.company.product.MainClass")); sb.append(" " + getTagLine("msgFileUrl", msgFileUrl, null)); for (int i = 0; i < mkDirs.size(); i++) { final MkDir mkDir = (MkDir) mkDirs.get(i); sb.append(" " + mkDir.toXML() + IOUtils.LINE_SEPARATOR); } for (int i = 0; i < srcDirs.size(); i++) { final SrcDir srcDir = (SrcDir) srcDirs.get(i); sb.append(" " + srcDir.toXML() + IOUtils.LINE_SEPARATOR); } for (int i = 0; i < srcFiles.size(); i++) { final SrcFile srcFile = (SrcFile) srcFiles.get(i); sb.append(" " + srcFile.toXML() + IOUtils.LINE_SEPARATOR); } sb.append("</application>" + IOUtils.LINE_SEPARATOR); return sb.toString(); }
From source file:org.jasig.maven.notice.AbstractNoticeMojo.java
/** * Create the generated part of the NOTICE file based on the resolved license data */// w w w . j a v a2 s .c o m protected String generateNoticeLines(Map<String, String> resolvedLicenses) { final StringBuilder builder = new StringBuilder(); final MessageFormat messageFormat = getNoticeMessageFormat(); for (final Map.Entry<String, String> resolvedEntry : resolvedLicenses.entrySet()) { final String line = messageFormat .format(new Object[] { resolvedEntry.getKey(), resolvedEntry.getValue() }); builder.append(line).append(IOUtils.LINE_SEPARATOR); } return builder.toString(); }
From source file:org.jasig.maven.notice.AbstractNoticeMojo.java
/** * Read the template notice file into a string, converting the line ending to the current OS line endings *///from www . j a v a 2 s . com protected String readNoticeTemplate(ResourceFinder finder) throws MojoFailureException { final URL inputFile = finder.findResource(this.noticeTemplate); final StringBuilder noticeTemplateContents = new StringBuilder(); InputStream inputStream = null; try { inputStream = inputFile.openStream(); for (final LineIterator lineIterator = IOUtils.lineIterator(new BufferedInputStream(inputStream), this.encoding); lineIterator.hasNext();) { final String line = lineIterator.next(); noticeTemplateContents.append(line).append(IOUtils.LINE_SEPARATOR); } } catch (IOException e) { throw new MojoFailureException( "Failed to open NOTICE Template File '" + this.noticeTemplate + "' from: " + inputFile, e); } finally { IOUtils.closeQuietly(inputStream); } return noticeTemplateContents.toString(); }
From source file:org.jasig.maven.notice.CheckNoticeMojoTest.java
public void copyFileWithOppositeLineEnding(File src, File dst) throws IOException { final List<String> lines = FileUtils.readLines(src); if (IOUtils.LINE_SEPARATOR_UNIX.equals(IOUtils.LINE_SEPARATOR)) { FileUtils.writeLines(dst, lines, IOUtils.LINE_SEPARATOR_WINDOWS); } else {/*from w w w . j av a 2 s.c o m*/ FileUtils.writeLines(dst, lines, IOUtils.LINE_SEPARATOR_UNIX); } }
From source file:org.jnap.core.assets.HandlebarsAssetsHandler.java
@Override public void handle() { final Handlebars handlebars = new Handlebars(); try {// www . j a va2s .c o m Resource[] resources = this.resourceResolver.getResources(source); Resource destRes = new ServletContextResource(servletContext, destination); resetResource(destRes); BufferedWriter writer = new BufferedWriter( new FileWriterWithEncoding(destRes.getFile(), this.encoding, true)); writer.write("(function() {"); writer.write(IOUtils.LINE_SEPARATOR); writer.write("var template = Handlebars.template, "); writer.write("templates = Handlebars.templates = Handlebars.templates || {};"); writer.write(IOUtils.LINE_SEPARATOR); final Set<String> templateNames = new TreeSet<String>(); for (Resource resource : resources) { Template template = handlebars .compile(StringUtils.trimToEmpty(IOUtils.toString(resource.getInputStream()))); final String templateName = FilenameUtils.getBaseName(resource.getFilename()); templateNames.add(templateName); writer.write("templates[\"" + templateName + "\"] = "); writer.write("template("); writer.write(template.toJavaScript()); writer.write(");"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write(IOUtils.LINE_SEPARATOR); if (this.bindToBackboneView) { writer.write("$(function() {"); writer.write(IOUtils.LINE_SEPARATOR); for (String templateName : templateNames) { writer.write(format("if (window[\"{0}\"]) {0}.prototype.template " + "= templates[\"{0}\"];", templateName)); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("});"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("})();"); IOUtils.closeQuietly(writer); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.monkeys.gui.matcher.MatcherPanel.java
private void searchAndReplaceSelected(final Pattern search, final String replace) { int count = 0; for (final MatcherContext ctx : this.matchingList.getSelectedValues()) { final String original = ctx.getText(); final String blob = ctx.getText() + IOUtils.LINE_SEPARATOR; String updated = original; int offset = 0; final Matcher matcher = search.matcher(blob); while (matcher.find()) { final int start = matcher.start(); final int end = matcher.end(); if (start <= 0) { updated = replace + updated.substring(end - offset); } else { final String prefix = updated.substring(0, start - offset); final String suffix = end < updated.length() ? updated.substring(end - offset) : ""; updated = prefix + replace + suffix; }/*ww w . ja v a 2 s . c om*/ offset += matcher.group().length() - replace.length(); } if (!updated.equals(original)) { ctx.setText(updated); count++; } } this.modifyPopup.hidePopup(); this.matchingList.repaint(); this.checkForDuplicates(); final String plural = count == 1 ? "item" : "items"; MessageUtils.infoNotification(count + " " + plural + " updated.", 5000); }
From source file:org.normandra.cassandra.CassandraDatabase.java
private void refreshTableGenerator(final String table, final String keyColumn, final String valueColumn) { final List<Statement> statements = new ArrayList<>(); // drop table as required if (DatabaseConstruction.RECREATE.equals(this.constructionMode) && this.hasTable(table)) { final StringBuilder cql = new StringBuilder(); cql.append("DROP TABLE ").append(table).append(";"); statements.add(new SimpleStatement(cql.toString())); }/*from w ww. j a va 2 s. c o m*/ // create table final StringBuilder cql = new StringBuilder(); cql.append("CREATE TABLE IF NOT EXISTS ").append(table).append(" (").append(IOUtils.LINE_SEPARATOR); cql.append(" ").append(keyColumn).append(" text PRIMARY KEY, "); cql.append(" ").append(valueColumn).append(" counter "); cql.append(IOUtils.LINE_SEPARATOR).append(");"); statements.add(new SimpleStatement(cql.toString())); // execute statements for (final Statement statement : statements) { this.ensureSession().execute(statement); } }
From source file:org.normandra.cassandra.CassandraDatabase.java
private void refreshEntityTable(final String tableName, final DatabaseMeta meta) { // drop table as required if (DatabaseConstruction.RECREATE.equals(this.constructionMode) && this.hasTable(tableName)) { final StringBuilder cql = new StringBuilder(); cql.append("DROP TABLE ").append(tableName).append(";"); this.ensureSession().execute(new SimpleStatement(cql.toString())); }/* w ww. j a v a 2s .c om*/ // build columns final Set<ColumnMeta> uniqueSet = new ArraySet<>(); final Collection<ColumnMeta> primaryColumns = new ArrayList<>(); final Collection<ColumnMeta> allColumns = new ArrayList<>(); for (final EntityMeta entity : meta) { if (tableName.equalsIgnoreCase(entity.getTable())) { for (final ColumnMeta column : entity) { if (uniqueSet.add(column)) { allColumns.add(column); if (column.isPrimaryKey()) { primaryColumns.add(column); } } } } } if (DatabaseConstruction.UPDATE.equals(this.constructionMode)) { // ensure we create base database with all keys - then update/add columns in separate comment final Statement statement = defineTable(tableName, primaryColumns); if (statement != null) { this.ensureSession().execute(statement); for (final ColumnMeta column : allColumns) { final String name = column.getName(); if (!column.isPrimaryKey() && !this.hasColumn(tableName, name)) { final String type = CassandraUtils.columnType(column); if (type != null) { final StringBuilder cql = new StringBuilder(); cql.append("ALTER TABLE ").append(tableName).append(IOUtils.LINE_SEPARATOR); cql.append("ADD ").append(name).append(" ").append(type).append(";"); this.ensureSession().execute(new SimpleStatement(cql.toString())); } } } } } else { // create table and column definitions in one command final Statement statement = defineTable(tableName, allColumns); if (statement != null) { this.ensureSession().execute(statement); for (final EntityMeta entity : meta) { if (tableName.equalsIgnoreCase(entity.getTable())) { // cassandra supports index-per-column, so find all the columns we want final List<ColumnMeta> columns = new ArrayList<>(); for (final IndexMeta index : entity.getIndexed()) { for (final ColumnMeta column : index.getColumns()) { if (entity.hasColumn(column)) { columns.add(column); } } } for (final ColumnMeta column : columns) { if (!column.isPrimaryKey()) { final StringBuilder cql = new StringBuilder(); cql.append("CREATE INDEX IF NOT EXISTS ON ").append(tableName).append(" (") .append(column.getName()).append(");"); this.ensureSession().execute(new SimpleStatement(cql.toString())); } } } } } } }
From source file:org.normandra.cassandra.CassandraDatabase.java
private Statement defineTable(final String table, final Collection<ColumnMeta> columns) { // define table final StringBuilder cql = new StringBuilder(); cql.append("CREATE TABLE ").append(table).append(" (").append(IOUtils.LINE_SEPARATOR); // define columns boolean firstColumn = true; for (final ColumnMeta column : columns) { final String name = column.getName(); final String type = CassandraUtils.columnType(column); if (type != null) { if (!firstColumn) { cql.append(",").append(IOUtils.LINE_SEPARATOR); }/* w ww . j a va 2 s .c o m*/ cql.append(name).append(" ").append(type); firstColumn = false; } } final Collection<String> keys = columns.stream().filter(Objects::nonNull).filter(ColumnMeta::isPrimaryKey) .map(ColumnMeta::getName).collect(Collectors.toList()); if (keys.isEmpty()) { // cassandra requires keys return null; } // define primary keys cql.append(",").append(IOUtils.LINE_SEPARATOR); cql.append("PRIMARY KEY ("); cql.append(StringUtils.join(keys, ", ")); cql.append(")").append(IOUtils.LINE_SEPARATOR); cql.append(");"); return new SimpleStatement(cql.toString()); }