List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter.java
private void handleSpaceWhenStartElement() { // Use case: <tag1>something <tag2>... // Use case: <tag1>something <!--... if (this.spaceCount > 0) { if (!this.isInCData && !this.isInPreserveElement) { // The first space is a normal space super.printXML(" "); for (int i = 0; i < this.spaceCount - 1; i++) { printEntity(" "); }//w w w . j a va 2s.co m } else { super.printXML(StringUtils.repeat(' ', this.spaceCount)); } } this.spaceCount = 0; this.elementEnded = false; this.hasTextBeenPrinted = false; }
From source file:org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter.java
private void handleSpaceWhenEndlement() { // Use case: <tag1>something </tag1>... // All spaces are spaces since otherwise they'll be all stripped by browsers if (!this.isInCData && !this.isInPreserveElement) { for (int i = 0; i < this.spaceCount; i++) { printEntity(" "); }//from w w w . j a v a2 s . c o m } else { super.printXML(StringUtils.repeat(' ', this.spaceCount)); } this.spaceCount = 0; this.elementEnded = false; this.hasTextBeenPrinted = false; }
From source file:org.xwiki.skinx.internal.AbstractSxExportURLFactoryActionHandler.java
private URL processSx(List<String> spaceNames, String name, String queryString, XWikiContext context, FilesystemExportContext exportContext) throws Exception { SxSource sxSource = null;// w w w . ja v a 2 s. c o m // Check if we have the JAR_RESOURCE_REQUEST_PARAMETER parameter in the query string List<NameValuePair> params = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8); for (NameValuePair param : params) { if (param.getName().equals(JAR_RESOURCE_REQUEST_PARAMETER)) { sxSource = new SxResourceSource(param.getValue()); break; } } if (sxSource == null) { sxSource = new SxDocumentSource(context, getExtensionType()); } String content = getContent(sxSource, exportContext); // Write the content to file // We need a unique name for that SSX content String targetPath = String.format("%s/%s/%s", getSxPrefix(), StringUtils.join(spaceNames, '/'), name); File targetDirectory = new File(exportContext.getExportDir(), targetPath); if (!targetDirectory.exists()) { targetDirectory.mkdirs(); } File targetLocation = File.createTempFile(getSxPrefix(), "." + getFileSuffix(), targetDirectory); FileUtils.writeStringToFile(targetLocation, content); // Rewrite the URL StringBuilder path = new StringBuilder("file://"); // Adjust based on current document's location. We need to account for the fact that the current document // is stored in subdirectories inside the top level "pages" directory. Since the SX files are also in top // subdirectories, we need to compute the path to them. path.append(StringUtils.repeat("../", exportContext.getDocParentLevel())); path.append(getSxPrefix()); path.append(URL_PATH_SEPARATOR); for (String spaceName : spaceNames) { path.append(encodeURLPart(spaceName)); path.append(URL_PATH_SEPARATOR); } path.append(encodeURLPart(name)); path.append(URL_PATH_SEPARATOR); path.append(encodeURLPart(targetLocation.getName())); return new URL(path.toString()); }
From source file:org.xwiki.test.ui.XWikiWebDriver.java
/** * Compared to using clear() + sendKeys(), this method ensures that an "input" event is triggered on the JavaScript * side for an empty ("") value. Without this, the clear() method triggers just a "change" event. * * @param textInputElement an element accepting text input * @param newTextValue the new text value to set * @see <a href="https://code.google.com/p/selenium/issues/detail?id=214">Issue 214</a> * @since 7.2M3/* ww w.j a v a2 s .c o m*/ */ public void setTextInputValue(WebElement textInputElement, String newTextValue) { if (StringUtils.isEmpty(newTextValue)) { // Workaround for the fact that clear() fires the "change" event but not the "input" event and javascript // listening to the "input" event will not be executed otherwise. // Note 1: We're not using CTRL+A and the Delete because the key combination to select the full input // depends on the OS (on Mac it's META+A for example). // Note 2: Sending the END key didn't always work when I tested it on Mac (for some unknown reason) textInputElement.click(); textInputElement.sendKeys(StringUtils.repeat(Keys.ARROW_RIGHT.toString(), textInputElement.getAttribute("value").length())); textInputElement.sendKeys(StringUtils.repeat(Keys.BACK_SPACE.toString(), textInputElement.getAttribute("value").length())); } else { textInputElement.clear(); textInputElement.sendKeys(newTextValue); } }
From source file:org.yamj.common.model.YamjInfo.java
/** * Output the header information to the log file * *///from w w w .j ava 2s . c o m public void printHeader(Logger log) { if (StringUtils.isNotBlank(projectName)) { // just print out if project name has been set log.info("{} {}", projectName, projectVersion); log.info("{} {}", StringUtils.repeat("~", projectName.length()), StringUtils.repeat("~", projectVersion.length())); log.info("{}", moduleName); log.info(""); log.info(" Revision: {}", buildRevision); log.info("Build Time: {}", getBuildDate()); log.info(" Java: {}", javaVersion); log.info(""); } }
From source file:org.yamj.filescanner.ScannerManagementImpl.java
/** * Start the scanner and process the command line properties. * * @param parser//www . j a va 2 s . c o m * @return */ @Override public ExitType runScanner(CmdLineParser parser) { checkGitHubStatus(); libraryCollection.setDefaultClient(DEFAULT_CLIENT); libraryCollection.setDefaultPlayerPath(DEFAULT_PLAYER_PATH); pingCore.check(0, 0); // Do a quick check of the status of the connection String directoryProperty = parser.getParsedOptionValue("d"); boolean watchEnabled = parseWatchStatus(parser.getParsedOptionValue("w")); String libraryFilename = parser.getParsedOptionValue("l"); if (StringUtils.isNotBlank(libraryFilename)) { List<String> libraryList = Arrays.asList(libraryFilename.split(DEFAULT_SPLIT)); libraryCollection.processLibraryList(libraryList, watchEnabled); } if (StringUtils.isNotBlank(directoryProperty)) { LOG.info("Adding directory from command line: {}", directoryProperty); libraryCollection.addLibraryDirectory(directoryProperty, watchEnabled); } LOG.info("Found {} libraries to process.", libraryCollection.size()); if (libraryCollection.size() == 0) { return ExitType.NO_DIRECTORY; } // String saveFilename="myLibrary.xml"; // LOG.info("Saving library to: {}",saveFilename); // libraryCollection.saveLibraryFile(saveFilename); // Send all libraries to be scanned ExitType status = ExitType.SUCCESS; for (Library library : libraryCollection.getLibraries()) { library.getStatistics().setTime(TimeType.START); status = scan(library); library.getStatistics().setTime(TimeType.END); library.setScanningComplete(Boolean.TRUE); LOG.info("Scanning completed."); } // Wait for the libraries to be sent boolean allDone; do { allDone = Boolean.TRUE; for (Library library : libraryCollection.getLibraries()) { LOG.info("Library '{}' sending status: {}", library.getImportDTO().getBaseDirectory(), library.isSendingComplete() ? "Done" : "Not Done"); allDone = allDone && library.isSendingComplete(); } if (!allDone) { try { LOG.info("Waiting for library sending to complete..."); TimeUnit.SECONDS.sleep(10); } catch (InterruptedException ex) { LOG.trace("Interrupted whilst waiting for threads to complete."); } } } while (!allDone); LOG.info(StringUtils.repeat("*", 50)); LOG.info("Completed initial sending of all libraries ({} total).", libraryCollection.size()); LOG.info(""); LOG.info("Library statistics:"); for (Library library : libraryCollection.getLibraries()) { LOG.info("Description: '{}'", library.getDescription()); LOG.info("{}", library.getStatistics().generateStatistics(Boolean.TRUE)); } if (watchEnabled) { Watcher wd = new Watcher(); Boolean directoriesToWatch = Boolean.TRUE; for (Library library : libraryCollection.getLibraries()) { String dirToWatch = library.getImportDTO().getBaseDirectory(); if (library.isWatch()) { LOG.info("Watching directory '{}' for changes...", dirToWatch); wd.addDirectory(dirToWatch); directoriesToWatch = Boolean.TRUE; } else { LOG.info("Watching skipped for directory '{}'", dirToWatch); } } if (directoriesToWatch) { wd.processEvents(); LOG.info("Watching directory '{}' completed", directoryProperty); } else { LOG.info("No directories marked for watching."); } } else { LOG.info("Watching not enabled."); } LOG.info("Exiting with status {}", status); return status; }
From source file:petascope.wcps2.translator.IParseTreeNode.java
/** * Creates an string representation of the tree * * @param currentLevel the current level of the tree * @return//from www . j av a2 s . c om */ private String toIndentedString(int currentLevel) { String spacer = StringUtils.repeat("\t", currentLevel); StringBuilder retString = new StringBuilder().append(this.getClass().getSimpleName()) .append(this.nodeInformation()); if (!children.isEmpty()) retString.append("{\n").append(""); List<String> childStrings = new ArrayList<String>(); for (IParseTreeNode child : children) { childStrings.add(spacer + child.toIndentedString(currentLevel + 1)); } retString.append(StringUtils.join(childStrings, ",\n ")); if (!children.isEmpty()) retString.append("\n").append(spacer.substring(1)).append("}"); return retString.toString(); }
From source file:reconf.server.domain.security.Client.java
public Client(Client request) { this.username = request.getUsername(); this.password = StringUtils.repeat("*", StringUtils.length(request.getPassword())); }
From source file:risk_mgnt_manager.CSVLoader.java
/** * Parse CSV file using OpenCSV library and load in * given database table. // ww w . j a va2 s .c om * @param csvFile Input CSV file * @param table Database table name to import data * @param col_Names * @param id * @param header */ public void loadCSV(String csvFile, String table, String col_Names, int id, boolean header) throws Exception { CSVReader csvReader = null; if (null == this.connection) { throw new Exception("Not a valid connection."); } try { csvReader = new CSVReader(new FileReader(csvFile), this.seprator); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error occured while executing file. " + e.getMessage()); } String[] headerRow; if (header == true) { headerRow = csvReader.readNext(); } else { headerRow = col_Names.split(","); } if (null == headerRow) { throw new FileNotFoundException( "No columns defined in given CSV file." + "Please check the CSV file format."); } String questionmarks = StringUtils.repeat("?,", headerRow.length); questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1); String query = SQL_INSERT.replaceFirst(TABLE_REGEX, table); //System.out.println(header); //query = query.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, ",")); query = query.replaceFirst(KEYS_REGEX, col_Names); query = query.replaceFirst(VALUES_REGEX, questionmarks); System.out.println("Query: " + query); String[] nextLine; Connection con = null; PreparedStatement ps = null; try { con = this.connection; con.setAutoCommit(false); ps = con.prepareStatement(query); if (id == 1) { //delete data from table before loading csv con.createStatement().execute("DELETE FROM " + table); } final int batchSize = 4096; int count = 0; Date date = null; while ((nextLine = csvReader.readNext()) != null) { if (null != nextLine) { int index = 1; for (String string : nextLine) { //date = DateUtill.convertToDate(string); if (null != date) { ps.setDate(index++, new java.sql.Date(date.getTime())); } else { ps.setString(index++, string); } } ps.addBatch(); } if (++count % batchSize == 0) { ps.executeBatch(); } } ps.executeBatch(); // insert remaining records con.commit(); } catch (Exception e) { con.rollback(); e.printStackTrace(); throw new Exception("Error occured while loading data from file to database." + e.getMessage()); } finally { if (null != ps) ps.close(); if (null != con) con.close(); csvReader.close(); } }
From source file:risk_mgnt_manager.StressCSVLoader.java
/** * Parse CSV file using OpenCSV library and load in * given database table. /*from w w w . ja va 2 s. c o m*/ * @param csvFile Input CSV file * @param tableName Database table name to import data * @throws Exception */ public void loadCSV(String csvFile, String tableName, String filename) throws Exception { CSVReader csvReader = null; if (null == this.connection) { throw new Exception("Not a valid connection."); } try { csvReader = new CSVReader(new FileReader(csvFile), this.seprator); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error occured while executing file. " + e.getMessage()); } String[] headerRow = csvReader.readNext(); if (null == headerRow) { throw new FileNotFoundException( "No columns defined in given CSV file." + "Please check the CSV file format."); } String questionmarks = StringUtils.repeat("?,", headerRow.length); questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1); String col_Names = "Point_in_Time, Portfolio, Fut_Variation, Opt_Variation, Total_Variation, Percent_of_Ledger_Balance, Ledger_Balance"; String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName); //query = query.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, ",")); query = query.replaceFirst(KEYS_REGEX, col_Names); query = query.replaceFirst(VALUES_REGEX, questionmarks); String update = "UPDATE mgex_riskmgnt." + tableName + " SET Imported_File_Name = '" + filename + "' Where " + "Imported_File_Name IS NULL"; System.out.println("Query: " + query); System.out.println("Update: " + update); String[] nextLine; Connection con = null; Connection con2 = null; PreparedStatement ps = null; PreparedStatement ps2 = null; try { con = this.connection; con.setAutoCommit(false); ps = con.prepareStatement(query); con2 = this.connection; con2.setAutoCommit(false); ps2 = con2.prepareStatement(update); final int batchSize = 1000; int count = 0; Date date = null; while ((nextLine = csvReader.readNext()) != null) { if (null != nextLine) { int index = 1; for (String string : nextLine) { //date = DateUtill.convertToDate(string); if (null != date) { ps.setDate(index++, new java.sql.Date(date.getTime())); } else { ps.setString(index++, string); } } ps.addBatch(); } if (++count % batchSize == 0) { ps.executeBatch(); } } ps.executeBatch(); // insert remaining records ps2.executeUpdate(); con.commit(); con2.commit(); } catch (Exception e) { con.rollback(); con2.rollback(); e.printStackTrace(); throw new Exception("Error occured while loading data from file to database." + e.getMessage()); } finally { if (null != ps) ps.close(); ps2.close(); if (null != con) con.close(); con2.close(); csvReader.close(); } }