@Override public Element setAttr(String name, String value) { Params.notNullOrEmpty(name, "Attribute name"); Params.notNull(value, "Attribute value"); node.setAttribute(name, value); return this; }
@Override public Element setAttrs(String... nameValuePairs) { Params.isTrue(nameValuePairs.length % 2 == 0, "Missing value for last attribute."); for (int i = 0, l = nameValuePairs.length - 1; i < l; i += 2) { Params.notNull(nameValuePairs[i + 1], "Attribute value"); node.setAttribute(nameValuePairs[i], nameValuePairs[i + 1]); } return this; }
@Override public boolean put(String name, T t, Locale... locale) { Params.notNullOrEmpty(name, "Name"); Params.notNullOrEmpty(locale, "Locale"); Params.empty(locale[0].getVariant(), "Locale variant"); Params.empty(locale[0].getScript(), "Locale script"); Params.empty(locale[0].getExtensionKeys(), "Locale extension"); Map<String, T> maps = localeMaps.get(locale[0].toLanguageTag()); if (maps == null) { maps = new HashMap<String, T>(); localeMaps.put(locale[0].toLanguageTag(), maps); } return maps.put(name, t) != null; }
/** * Create file resource for requested file and content type. * * @param file source file, absolute or relative to current working directory. * @param contentType file content type. * @throws IllegalArgumentException if <code>file</code> argument is null or not an ordinary file. * @throws IllegalArgumentException if <code>contentType</code> argument is null. */ public FileResource(File file, ContentType contentType) { Params.notNull(file, "File"); Params.isFile(file, "File"); Params.notNull(contentType, "Content type"); this.file = file; this.contentType = contentType.getValue(); }
/** * Construct content instance. * * @param converterRegistry converter manager, * @param model model object. * @throws IllegalArgumentException if <code>model</code> parameter is null. */ public Content(Object model) throws IllegalArgumentException { Params.notNull(model, "Model"); this.model = model; }
/** * Create configuration object with name. * * @param name configuration object name. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. */ public Config(String name) { Params.notNullOrEmpty(name, "Root name"); this.name = name; }
@Override public Element createElement(String tagName, String... attrNameValues) { Params.notNullOrEmpty(tagName, "Tag name"); Params.isTrue(attrNameValues.length % 2 == 0, "Missing value for last attribute."); Element el = getElement(doc.createElement(tagName)); if (attrNameValues.length > 0) { el.setAttrs(attrNameValues); } return el; }
/** * Remove ALL files and directories from a given base directory. This method remove ALL files and directory tree, * child of given <code>baseDir</code> but directory itself is not removed. As a result <code>baseDir</code> becomes * empty, that is, no children. If exception occur base directory state is not defined, that is, some files may be * removed and other may still be there. * * @param baseDir base directory to clean-up. * @throws IOException if remove operation fails. */ public static void removeFilesHierarchy(File baseDir) throws IOException { Params.notNull(baseDir, "Base directory"); Params.isDirectory(baseDir, "Base directory"); log.debug("Remove files hierarchy with base directory |%s|.", baseDir); removeDirectory(baseDir); }
/** * Construct I18N file instance bound to specified locale settings. Given locale should be based only on language and * optional country, encoded with ISO 639 alpha-2, respective ISO 3166 alpha-2; script, variant and extension should be * empty. * * @param file underlying filesystem file path, * @param locale locale settings. * @throws IllegalArgumentException if <code>locale</code> argument is null or has variant, script or extension. */ I18nFile(File file, Locale locale) throws IllegalArgumentException { this.file = file; Params.notNull(locale, "Locale"); Params.empty(locale.getVariant(), "Locale variant"); Params.empty(locale.getScript(), "Locale script"); Params.empty(locale.getExtensionKeys(), "Locale extension"); this.locale = locale; }
/** * Create serializer instance with inband type information. * * @param includeClass always true to include class name before serialized value. * @throws IllegalArgumentException if <code>includeClass</code> is not true. */ public Serializer(boolean includeClass) throws IllegalArgumentException { Params.isTrue(includeClass, "Include class flag should always be true."); this.includeClass = includeClass; }
@Override public void moveTo(File targetDir) throws IOException { Params.isDirectory(targetDir, "Target directory"); Files.renameTo(file, new File(targetDir, fileName)); }
/** * Get named objects map bound to requested locale settings. * * @param locale locale settings to retrieve objects map for. * @return objects map bound to requested locale settings. * @throws IllegalArgumentException if <code>locale</code> argument has variant, script or extension. */ private Map<String, T> maps(Locale locale) { Params.empty(locale.getVariant(), "Locale variant"); Params.empty(locale.getScript(), "Locale script"); Params.empty(locale.getExtensionKeys(), "Locale extension"); Map<String, T> maps = localeMaps.get(locale.toLanguageTag()); if (maps == null) { throw new BugError("Missing repository for locale |%s|.", locale); } return maps; } }
/** * Construct redirect instance for given location, relative or absolute. See * {@link HttpServletResponse#sendRedirect(String)} for a discussion about location syntax and processing. * * @param location redirect location, absolute or relative. * @throws IllegalArgumentException if <code>location</code> argument is null. */ public Redirect(String location) { Params.notNull(location, "Redirect location."); this.location = location; }
/** * Construct a new case-sensitive wildcard filter instance. * * @param pattern pattern used to match file names and strings. * @throws IllegalArgumentException if the pattern is null or empty. */ public WildcardFilter(String pattern) { Params.notNullOrEmpty(pattern, "Pattern"); this.pattern = pattern; }
/** * Create I18N repository instance and configure it. See {@link ConfigBuilder} for configuration object properties. * * @param config configuration object. * @throws IllegalArgumentException if configured base directory does not denote an existing directory. * @throws IOException if reading directories content fails, perhaps for lack of authorization. * @throws BugError if no files matching files pattern found or missing locale directory. */ public I18nRepository(Config config) throws IOException { this.multiLocale = config.getProperty("multi-locale", Boolean.class, true); File baseDir = config.getProperty("base-dir", File.class); Params.isDirectory(baseDir, "Base directory"); FileFilter fileFilter = new WildcardFilter(config.getProperty("files-pattern", WildcardFilter.ACCEPT_ALL)); if(this.multiLocale) { this.iterable = new MultipleLocale(baseDir, config.getProperty("sub-path"), fileFilter); } else { this.iterable = new SingleLocale(baseDir, fileFilter); } }
@Override public Element getByXPathNS(NamespaceContext namespaceContext, String xpath, Object... args) { Params.notNull(namespaceContext, "Name space context"); Params.notNullOrEmpty(xpath, "XPath"); return ownerDoc.evaluateXPathNodeNS(node, namespaceContext, xpath, args); }
/** * Create instance key with given value. * * @param value instance key value. * @throws IllegalArgumentException if key value is null. */ public InstanceKey(String value) { Params.notNull(value, "Key value"); this.value = value; }
/** * Create file for given path. * * @param path file path. * @return newly create file. * @throws IllegalArgumentException if <code>path</code> argument is null or empty. */ private static File file(String path) { Params.notNullOrEmpty(path, "File path"); return new File(path); }
/** * Construct transactional proxy invocation handler for given managed instance. * * @param transactionalResource transactional resource, * @param managedClass managed class, * @param managedInstance instance of managed class. * @throws IllegalArgumentException if <code>managedClass</code> is null or not transactional or * <code>managedInstance</code> is null. */ public ManagedProxyHandler(TransactionalResource transactionalResource, ManagedClassSPI managedClass, Object managedInstance) { Params.notNull(managedClass, "Managed class"); if (transactionalResource != null) { Params.isTrue(managedClass.isTransactional(), "Managed class is not transactional"); } Params.notNull(managedInstance, "Managed instance"); this.transactionalResource = transactionalResource; this.managedClass = managedClass; this.managedInstance = managedInstance; }