/** * @param id unique identifier for the target object * @param target the object to be ordered; this may also be null (in which case the id represents a placeholder) */ public Orderable(String id, T target, String... constraints) { assert InternalUtils.isNonBlank(id); this.id = id; this.target = target; this.constraints = constraints; }
/** * Splits a value around commas. Whitespace around the commas is removed, as is leading and trailing whitespace. * * @since 5.1.0.0 */ public static String[] splitAtCommas(String value) { if (InternalUtils.isBlank(value)) return InternalConstants.EMPTY_STRING_ARRAY; return COMMA_PATTERN.split(value.trim()); }
/** * Converts an list of strings into a space-separated string combining them all, suitable for use as an HTML class * attribute value. * * @param classes classes to combine * @return the joined classes, or null if classes is empty */ public static String toClassAttributeValue(List<String> classes) { if (classes.isEmpty()) return null; return InternalUtils.join(classes, " "); }
public Link addParameter(String parameterName, String value) { assert InternalUtils.isNonBlank(parameterName); if (parameters == null) { parameters = new TreeMap<String, List<String>>(); } InternalUtils.addToMapList(parameters, parameterName, value == null ? "" : value); return this; }
private boolean hasSlidesClass(Element element) { return InternalUtils.isBlank(element.getAttribute("class")) || (InternalUtils.isNonBlank(element.getAttribute("class")) && !element.getAttribute("class").contains("slides")); } });
private FieldValidator createValidator(Field field, ValidatorSpecification spec, String overrideId, Messages overrideMessages) { String validatorType = spec.getValidatorType(); assert InternalUtils.isNonBlank(validatorType); Validator validator = validators.get(validatorType); if (validator == null) throw new IllegalArgumentException(String.format("Unknown validator type '%s'. Configured validators are %s.", validatorType, InternalUtils.join(InternalUtils.sortedKeys(validators)))); // I just have this thing about always treating parameters as finals, so // we introduce a second variable to treat a mutable. String formValidationid = formSupport.getFormValidationId(); Object coercedConstraintValue = computeConstraintValue(validatorType, validator, spec.getConstraintValue(), formValidationid, overrideId, overrideMessages); MessageFormatter formatter = findMessageFormatter(formValidationid, overrideId, overrideMessages, validatorType, validator); return new FieldValidatorImpl(field, coercedConstraintValue, formatter, validator, formSupport); }
@Override public void render(LessCompiler.Problem problem, MarkupWriter writer) { List<String> strings = CollectionFactory.newList(); if (InternalUtils.isNonBlank(problem.getMessage())) { strings.add(problem.getMessage()); } // Inside WRO4J we see that the LessSource is a StringSource with no useful toString(), so // it is omitted. We may need to create our own processors, stripping away a couple of layers of // WRO4J to get proper exception reporting! if (problem.getLine() > 0) { strings.add("line " + problem.getLine()); } if (problem.getCharacter() > 0) { strings.add("position " + problem.getCharacter()); } writer.write(InternalUtils.join(strings, " - ")); } });
/** * Check whether container supports opening a stream on a dir/package to get a list of its contents. */ private static boolean supportsDirStream(URL packageURL) { InputStream is = null; try { is = packageURL.openStream(); return true; } catch (FileNotFoundException ex) { return false; } catch (IOException ex) { return false; } finally { InternalUtils.close(is); } }
/** * @return the list of names of parameters in this content type, in alphabetical order. */ public List<String> getParameterNames() { return InternalUtils.sortedKeys(parameters); }
/** * Identifies the module class and a list of service ids within the module. */ @Override public String toString() { return String.format("ModuleDef[%s %s]", moduleClass.getName(), InternalUtils.joinSorted(serviceDefs.keySet())); }
void setupRender() { alphaKeyItems = new TreeMap<String, List<Item>>(); for (Item item : ITEMS) { InternalUtils.addToMapList(alphaKeyItems, item.label.substring(0, 1), item); } }
public void validateEmbeddedIds(Map<String, Location> componentIds, Resource templateResource) { Map<String, Boolean> embeddedIds = CollectionFactory.newCaseInsensitiveMap(); for (String id : getModel().getEmbeddedComponentIds()) embeddedIds.put(id, true); for (String id : componentIds.keySet()) { allocator.allocateId(id); embeddedIds.remove(id); } if (!embeddedIds.isEmpty()) { String className = getModel().getComponentClassName(); throw new RuntimeException(String.format("Embedded component(s) %s are defined within component class %s (or a super-class of %s), but are not present in the component template (%s).", InternalUtils.joinSorted(embeddedIds.keySet()), className, InternalUtils.lastTerm(className), templateResource)); } }
public String getClientId() { if (InternalUtils.isBlank(clientId)) clientId = (InternalUtils.isNonBlank(resources.getInformalParameter("id", String.class))) ? resources .getInformalParameter("id", String.class) : javaScriptSupport.allocateClientId(resources); return clientId; }
@Override public void render(LessCompiler.Problem problem, MarkupWriter writer) { List<String> strings = CollectionFactory.newList(); if (InternalUtils.isNonBlank(problem.getMessage())) { strings.add(problem.getMessage()); } // Inside WRO4J we see that the LessSource is a StringSource with no useful toString(), so // it is omitted. We may need to create our own processors, stripping away a couple of layers of // WRO4J to get proper exception reporting! if (problem.getLine() > 0) { strings.add("line " + problem.getLine()); } if (problem.getCharacter() > 0) { strings.add("position " + problem.getCharacter()); } writer.write(InternalUtils.join(strings, " - ")); } });
public void addInitialization(InitializationPriority priority, String moduleName, String functionName, JSONArray arguments) { assert priority != null; assert InternalUtils.isNonBlank(moduleName); String name = functionName == null ? moduleName : moduleName + ":" + functionName; if ((arguments == null || arguments.length() == 0)) { if (pureInits.contains(name)) { // A degenerate case is a pure init added repeatedly with different priorities. That isn't handled: // the first priority wins. return; } pureInits.add(name); InternalUtils.addToMapList(inits, priority, name); } else { JSONArray init = new JSONArray(); init.put(name); init.putAll(arguments); InternalUtils.addToMapList(inits, priority, init); } initCount++; }
/** * Check whether container supports opening a stream on a dir/package to get a list of its contents. */ private static boolean supportsDirStream(URL packageURL) { InputStream is = null; try { is = packageURL.openStream(); return true; } catch (FileNotFoundException ex) { return false; } catch (IOException ex) { return false; } finally { InternalUtils.close(is); } }
/** * Returns a list of all allocated ids, sorted alphabetically. */ public List<String> getAllocatedIds() { return InternalUtils.sortedKeys(generatorMap); }
/** * Identifies the module class and a list of service ids within the module. */ @Override public String toString() { return String.format("ModuleDef[%s %s]", moduleClass.getName(), InternalUtils.joinSorted(serviceDefs.keySet())); }
private void addMethodToRenderPhaseCategoryMap(Map<Class, List<PlasticMethod>> map, PlasticMethod method) { Class categorized = categorizeMethod(method); if (categorized != null) { validateAsRenderPhaseMethod(method); InternalUtils.addToMapList(map, categorized, method); } }
public DecoratorDefImpl(Method decoratorMethod, String[] patterns, String[] constraints, PlasticProxyFactory proxyFactory, String decoratorId, Class serviceInterface, Set<Class> markers) { super(decoratorMethod, patterns, constraints, serviceInterface, markers, proxyFactory); assert InternalUtils.isNonBlank(decoratorId); this.decoratorId = decoratorId; }