/** * Splits a string into an array using provided delimiter. Empty (but not blank) split chunks are omitted. * The split chunks are trimmed. * * @param input string to split. * @param delimiter delimiter * @return a string split into an array using a provided delimiter */ public static String[] split(String input, char delimiter) { return split(input, String.valueOf(delimiter)); }
/** * Convenience method, does the same as {@link #execute(String...)}, but will * automatically convert a full command string to tokens for convenience. * Here is how to call: * * <pre> * System.out.println(execute("ls -ls").out); * </pre> * * @param command - a single string representing a command and its arguments. * @return instance of {@link Response} with result of execution. */ public static Response execute(String command) { return execute(Util.split(command, " ")); }
private static synchronized Map<String, Set<String>> getModelMap() { if (modelMap == null) { try { modelMap = new HashMap<>(); Enumeration<URL> urls = Registry.instance().getClass().getClassLoader().getResources("activejdbc_models.properties"); while(urls.hasMoreElements()) { URL url = urls.nextElement(); LogFilter.log(LOGGER, LogLevel.INFO, "Loading models from: {}", url.toExternalForm()); String modelsFile = Util.read(url.openStream()); String[] lines = Util.split(modelsFile, System.getProperty("line.separator")); for(String line : lines) { String[] parts = Util.split(line, ':'); String modelName = parts[0]; String dbName = parts[1]; Set<String> modelNames = modelMap.computeIfAbsent(dbName, k -> new HashSet<>()); if (!modelNames.add(modelName)) { throw new InitException(String.format("Model '{}' already exists for database '{}'", modelName, dbName)); } } } } catch(IOException e) { throw new InitException(e); } } return modelMap; }
String[] commandAndArgs = command.length == 1 && command[0].contains(" ") ? Util.split(command[0], " ") : command;
@Override public void setArguments(String argumentLine) { this.argumentLine = argumentLine.trim(); String[] arguments = split(argumentLine, " "); singleArgument = arguments.length == 1; }
/** * Splits a string into an array using provided delimiter. Empty (but not blank) split chunks are omitted. * The split chunks are trimmed. * * @param input string to split. * @param delimiter delimiter * @return a string split into an array using a provided delimiter */ public static String[] split(String input, char delimiter) { return split(input, String.valueOf(delimiter)); }
/** * Splits a string into an array using provided delimiter. Empty (but not blank) split chunks are omitted. * The split chunks are trimmed. * * @param input string to split. * @param delimiter delimiter * @return a string split into an array using a provided delimiter */ public static String[] split(String input, char delimiter) { return split(input, String.valueOf(delimiter)); }
private String getTemplatePath(String containerName, String templateArgumentName){ String templatePath; if(!templateArgumentName.startsWith("/")){ //need to get path of container - this is not a shared partial, so expect it is located in teh same //directory with the containing template String path = containerName.substring(0, containerName.lastIndexOf("/")); templatePath = "/" + path + "/" + templateArgumentName; }else{//this is a shared partial if(Util.split(templateArgumentName, '/').length < 2){ throw new IllegalArgumentException("wrong name of shared partial"); } String path = templateArgumentName.substring(0, templateArgumentName.lastIndexOf("/")); templatePath = path + "/" + templateArgumentName.substring(templateArgumentName.lastIndexOf("/") + 1); } return templatePath; }
/** * Convenience method, does the same as {@link #execute(String...)}, but will * automatically convert a full command string to tokens for convenience. * Here is how to call: * * <pre> * System.out.println(execute("ls -ls").out); * </pre> * * @param command - a single string representing a command and its arguments. * @return instance of {@link Response} with result of execution. */ public static Response execute(String command) { return execute(Util.split(command, " ")); }
/** * * @param containerName - name of the container template. * @param templateArgumentName this is a name of a partial provided as an attribute to the "render" tag. * @return full path to a template file. */ private String getTemplatePath(String containerName, String templateArgumentName){ String templatePath; if(!templateArgumentName.startsWith("/")){ //need to get path of container - this is not a shared partial, so expect it is located in teh same //directory with the containing template String path = containerName.substring(0, containerName.lastIndexOf("/")); templatePath = "/" + path + "/_" + templateArgumentName; }else{//this is a shared partial if(Util.split(templateArgumentName, '/').length < 2){ throw new IllegalArgumentException("wrong name of shared partial"); } String path = templateArgumentName.substring(0, templateArgumentName.lastIndexOf("/")); templatePath = path + "/_" + templateArgumentName.substring(templateArgumentName.lastIndexOf("/") + 1); } return templatePath; }
@Override public void setArguments(String argumentLine) { super.setArguments(argumentLine); String[] arguments = Util.split(argumentLine, ' '); if(arguments.length != 3 || !arguments[1].equals("as")) throw new ParseException("List arguments must have format: 'collection as localVar'"); collectionName = arguments[0]; varName = arguments[2]; }
@Override protected void render(Map params, String body, Writer writer) throws Exception { if (params.containsKey("key")) { String key = params.get("key").toString(); if(params.containsKey("locale")){ String localeString = params.get("locale").toString(); String language, country; Locale locale; if(localeString.contains("_")){ language = split(localeString, '_')[0]; country = split(localeString, '_')[1]; locale = new Locale(language, country); }else{ language = localeString; locale = new Locale(language); } writer.write(Messages.message(key, locale, getParamsArray(params))); }else{ writer.write(Messages.message(key, getParamsArray(params))); } }else{ writer.write("<span style=\"display:none\">you failed to supply key for this message tag</span>"); } }
@Override public void setArguments(String argumentLine) { super.setArguments(argumentLine); this.expression = argumentLine.contains("."); boolean hasBuiltIn = argumentLine.contains(" "); if (argumentLine.length() - argumentLine.replace(" ", "").length() > 1) throw new ParseException("Merge token: " + argumentLine + " has more that one space"); if (argumentLine.length() - argumentLine.replace(".", "").length() > 1) throw new ParseException("Merge token: " + argumentLine + " has more that one dots"); if (hasBuiltIn) { String[] parts = Util.split(argumentLine, ' '); String builtInName = parts[1]; builtIn = TemplatorConfig.instance().getBuiltIn(builtInName); if (expression) { parts = Util.split(parts[0], '.'); this.objectName = parts[0]; this.propertyName = parts[1]; } } else if (expression) { String[] parts = Util.split(argumentLine, '.'); this.objectName = parts[0]; this.propertyName = parts[1]; } }
/** * Used for custom routes * @param routeConfig what was specified in the RouteConfig class */ protected RouteBuilder(String routeConfig) { String[] segmentsArr = Util.split(routeConfig, '/'); for (String segmentStr : segmentsArr) { Segment segment = new Segment(segmentStr); segments.add(segment); if (segment.wildCard) { String wildCardSegment = segment.segment; wildcardName = wildCardSegment.substring(1); break; // break from loop, we are done! } } if(segmentsArr.length > segments.size()){ throw new ConfigurationException("Cannot have URI segments past wild card"); } this.routeConfig = routeConfig; for (Segment segment : segments) { if (segment.mandatory) { mandatorySegmentCount++; } } }
String[] requestUriSegments = Util.split(requestUri, '/'); if(isWildcard() && requestUriSegments.length >= segments.size() && wildSegmentsMatch(requestUriSegments, controllerPath)){ String[] tailArr = Arrays.copyOfRange(requestUriSegments, segments.size() - 1, requestUriSegments.length);
while ((line = reader.readLine()) != null) { String[] parts = split(line, ':'); String modelName = parts[0]; String dbName = parts[1];
String[] partialParts = Util.split(params.get("partial").toString(), '/'); String partialName = partialParts[partialParts.length - 1]; Template partialTemplate = env.getConfiguration().getTemplate(partialPath + ".ftl" );