List of usage examples for org.apache.commons.lang3 StringUtils split
public static String[] split(final String str)
Splits the provided text into an array, using whitespace as the separator.
From source file:eionet.webq.converter.XmlSchemaExtractor.java
/** * Parse schemaLocation attribute and extract schema URLs without namespace references. * * @param schemaLocation Schema location string containing space delimited namespace + schema URL pairs. * @return Space delimited schema URLs without namespace references. *//*from w w w . ja v a2 s. c o m*/ private String parseSchemaLocation(String schemaLocation) { if (StringUtils.isBlank(schemaLocation)) { return schemaLocation; } StringBuilder sb = new StringBuilder(); String[] split = StringUtils.split(schemaLocation); for (int i = 0; i < split.length; i++) { if (i % 2 != 0) { sb.append(" ").append(split[i]); } } return sb.toString().trim(); }
From source file:com.croer.javaorange.diviner.SimpleOrangeTextPane.java
protected void colorStyledDocument(final DefaultStyledDocument document) { EventQueue.invokeLater(new Runnable() { @Override//from w w w .j a v a2 s. c o m public void run() { String input = ""; try { input = document.getText(0, document.getLength()); } catch (BadLocationException ex) { Logger.getLogger(SimpleOrangeTextPane.class.getName()).log(Level.SEVERE, null, ex); } StringBuilder inputMut = new StringBuilder(input); String[] split = StringUtils.split(inputMut.toString()); int i = 0; for (String string : split) { int start = inputMut.indexOf(string); int end = start + string.length(); inputMut.replace(start, end, StringUtils.repeat(" ", string.length())); document.setCharacterAttributes(start, string.length(), styles[i++ % styles.length], true); } } }); }
From source file:de.vandermeer.skb.mvn.pm.model.Model_ManagedProject.java
/** * Creates a new Managed Project object. * @param mc the model context//from ww w .j a v a 2 s .c o m * @param baseDir project base directory * @param pmDir the project PM directory * @param propertyFile the project property file * @throws NullPointerException if any argument was null * @throws IllegalArgumentException if any sub-method experienced an illegal argument * @throws FileNotFoundException if any file (property file) was not found * @throws IOException if reading the property file caused an IO exception */ Model_ManagedProject(PM_Context mc, File baseDir, File pmDir, File propertyFile) throws FileNotFoundException, IOException { Validate.notNull(mc); Validate.notNull(baseDir); Validate.notNull(pmDir); Validate.notNull(propertyFile); this.mc = mc; this.baseDir = baseDir; this.pmDir = pmDir; this.projectPropertyFile = propertyFile; // this.propertyMap = new HashMap<>(); this.loadProperties(); this.pmId = this.properties.getProperty(ProjectProperties.PM_ID.getPropName()); this.mc.getBuildVersions().put(this.getPmId(), new Ctxt_BuildVersion(this.pmId, this.getMvnGroupId() + " " + this.getMvnArtifactId() + " " + this.getMvnVersion())); this.dependencies = new LinkedHashSet<>(); this.licenses = new LinkedHashSet<>(); if (this.properties.getProperty(ProjectProperties.PM_LICENSES.getPropName()) != null) { for (String l : StringUtils .split(this.properties.getProperty(ProjectProperties.PM_LICENSES.getPropName()))) { try { this.licenses.add(Licenses.valueOf(l)); } catch (Exception ex) { throw new IllegalArgumentException( "project <" + this.pmId + "> requires unknown license <" + l + ">"); } } } //get all other files from the pm directory this.otherProjectFiles = new LinkedHashMap<>(); for (ProjectFiles pf : ProjectFiles.values()) { if (pf != ProjectFiles.MANAGED_PROJECT_PROPERTIES) { File f = new File(this.pmDir + File.separator + pf.getFileName()); if (f.exists() && f.canRead()) { this.otherProjectFiles.put(pf, f); } } } //get all plugin files requires this.plugins = new LinkedHashSet<>(); if (this.properties.getProperty(ProjectProperties.PM_PLUGINS.getPropName()) != null) { for (String fn : StringUtils .split(this.properties.getProperty(ProjectProperties.PM_PLUGINS.getPropName()))) { File f = new File(this.pmDir + File.separator + fn); if (f.exists() && f.canRead()) { this.plugins.add(f); } else { throw new IllegalArgumentException( "project <" + this.pmId + "> required plugin file <" + f + ">"); } } } //get all profiles requires this.profiles = new LinkedHashSet<>(); if (this.properties.getProperty(ProjectProperties.PM_PROFILES.getPropName()) != null) { for (String fn : StringUtils .split(this.properties.getProperty(ProjectProperties.PM_PROFILES.getPropName()))) { File f = new File(this.pmDir + File.separator + fn); if (f.exists() && f.canRead()) { this.profiles.add(f); } else { throw new IllegalArgumentException( "project <" + this.pmId + "> required profile file <" + f + ">"); } } } }
From source file:com.hortonworks.processors.network.GetTcpDumpAttributes.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();//from w w w . j a v a2 s . c om if (flowFile == null) { return; } flowFile.getAttributes(); final Map<String, String> attributes = new HashMap<>(); session.read(flowFile, new InputStreamCallback() { @Override public void process(InputStream in) throws IOException { // Parse the data as string and extract scr/dest host/ports String data = IOUtils.toString(in); String[] components = StringUtils.split(data); attributes.put("src.socket", components[2]); attributes.put("dest.socket", StringUtils.replace(components[4], ":", "")); } }); //write out attributes to Flow file flowFile = session.putAllAttributes(flowFile, attributes); session.transfer(flowFile, SUCCESS_RELATIONSHIP); }
From source file:com.arcao.geocaching.api.data.coordinates.CoordinatesParser.java
protected static ParseResult parse(String coordinate, CoordinateType coordinateType) throws ParseException { Pattern pattern;/*from w ww .j a v a 2s. com*/ switch (coordinateType) { case LAT_UNSAFE: pattern = LATITUDE_PATTERN_UNSAFE; break; case LON_UNSAFE: pattern = LONGITUDE_PATTERN_UNSAFE; break; case LON: pattern = LONGITUDE_PATTERN; break; case LAT: default: pattern = LATITUDE_PATTERN; break; } final Matcher matcher = pattern.matcher(coordinate); if (matcher.find()) { double sign = matcher.group(1).equalsIgnoreCase("S") || matcher.group(1).equalsIgnoreCase("W") ? -1.0 : 1.0; double degree = Double.parseDouble(matcher.group(2)); if (degree < 0) { sign = -1; degree = Math.abs(degree); } double minutes = 0.0; double seconds = 0.0; if (matcher.group(3) != null) { minutes = Double.parseDouble(matcher.group(3)); if (matcher.group(4) != null) { seconds = Double.parseDouble("0." + matcher.group(4)) * 60.0; } else if (matcher.group(5) != null) { seconds = Double.parseDouble(matcher.group(5).replace(",", ".")); } } double result = sign * (degree + minutes / 60.0 + seconds / 3600.0); // normalize result switch (coordinateType) { case LON_UNSAFE: case LON: result = normalize(result, -180, 180); break; case LAT_UNSAFE: case LAT: default: result = normalize(result, -90, 90); break; } return new ParseResult(result, matcher.start(), matcher.group().length()); } else { // Nothing found with "N 52...", try to match string as decimaldegree try { final String[] items = StringUtils.split(coordinate.trim()); if (items.length > 0) { final int index = (coordinateType == CoordinateType.LON ? items.length - 1 : 0); final int pos = (coordinateType == CoordinateType.LON ? coordinate.lastIndexOf(items[index]) : coordinate.indexOf(items[index])); return new ParseResult(Double.parseDouble(items[index]), pos, items[index].length()); } } catch (NumberFormatException e) { logger.error(e.getMessage(), e); } } throw new ParseException("Could not parse coordinate: \"" + coordinate + "\"", 0); }
From source file:com.threewks.thundr.jpa.JpaModule.java
/** * Gets a list of persistence unit names to initialize. Defaults to a single persistence unit named after the * current environment as provided by {@link Environment#get()}. Override this if you wish to initialize a * different or multiple persistence managers. * // ww w .j a v a 2s. c om * @param injectionContext * * @return a list of persistence unit names */ protected Map<String, String> getPersistenceUnitNames(UpdatableInjectionContext injectionContext) { Map<String, String> persistenceManagerAndPersistenceUnit = new LinkedHashMap<String, String>(); String persistenceManagersString = injectionContext.get(String.class, PersistenceManagersConfigName); String[] persistenceManagers = StringUtils.split(persistenceManagersString); if (persistenceManagers == null) { persistenceManagerAndPersistenceUnit.put(PersistenceManager.DefaultName, PersistenceManager.DefaultName); } else { for (String persistenceManager : persistenceManagers) { String[] persistenceManagerAndUnit = StringUtils.split(persistenceManager, ":"); if (persistenceManagerAndUnit.length != 2) { throw new JpaException( "Failed to initialise persistence managers, each persistence manager is expected to be paired with a persistence unit in the form <manager:unit>, but got '%s'", persistenceManager); } persistenceManagerAndPersistenceUnit.put(persistenceManagerAndUnit[0], persistenceManagerAndUnit[1]); } } return persistenceManagerAndPersistenceUnit; }