/** * Asserts that passed parameter is not null. In case it is, then an * {@link IllegalArgumentException} is thrown. * * @param param the parameter to check * @param paramName the parameter name * * @throws IllegalArgumentException if param is null */ public static void paramNotNull(Object param, String paramName) { notNull(param, String.format(NULL_PARAM_MESSAGE, paramName)); }
/** * Asserts that passed parameter is not null and not empty. In case it is, then an * {@link IllegalArgumentException} is thrown. * * @param param the parameter to check * @param paramName the parameter name * * @throws IllegalArgumentException if param is null or empty string */ public static void paramNotEmpty(String param, String paramName) { notEmpty(param, String.format(EMPTY_PARAM_MESSAGE, paramName)); }
/** * Creates new instance of {@link StaxEventHandler} with given {@link XMLEventWriter}. * * @param xmlEventWriter the {@link XMLEventWriter} to be used * * @throws IllegalArgumentException if xmlEventWriter is null */ public StaxEventHandler(XMLEventWriter xmlEventWriter) { Assert.paramNotNull(xmlEventWriter, "xmlEventWriter"); this.xmlEventWriter = xmlEventWriter; }
/** * Asserts that passed object instance is not null and not empty. In case it is, then an * {@link IllegalArgumentException} is thrown. * * @param obj the object instance to check * @param msg the error message to use * * @throws IllegalArgumentException if obj is null or empty string */ public static void notEmpty(String obj, String msg) { notNull(obj, msg); if (obj.trim().length() == 0) { throw new IllegalArgumentException(msg); } } }
/** * Creates new instance of {@link StaxStreamHandler} class. * * @param xmlStreamWriter the instance of {@link XMLStreamWriter} to use * * @throws IllegalArgumentException if xmlStreamWriter is null */ public StaxStreamHandler(XMLStreamWriter xmlStreamWriter) { Assert.paramNotNull(xmlStreamWriter, "xmlStreamWriter"); this.xmlStreamWriter = xmlStreamWriter; }
/** * Returns the Namespace prefixes associated with the given URI. * * @param nsURI the namespace URI to lookup * @param local a boolean that when true indicates only the local scope is searched. * @return the namespace prefixes associated with the given URI * * @throws IllegalArgumentException if nsURI is null **/ public String[] getNamespacePrefixes(String nsURI) { // check the result Assert.notNull(nsURI, "Namespace URI must not be null."); List<String> prefixes = new ArrayList<String>(); for (Namespace namespace : namespaces) { if (namespace.getUri().equals(nsURI)) { prefixes.add(namespace.getPrefix()); } } return prefixes.toArray(new String[0]); }
/** * Returns the Namespace prefix associated with the given URI. If multiple namespace prefixes have * been declared, then the first one found is returned. To obtain all prefixes see * <code>#getNamespacePrefixes</code>. * * @param nsURI the namespace URI to lookup * @return the namespace prefix associated with the given URI * * @throws IllegalArgumentException if nsURI is null **/ public String getNamespacePrefix(String nsURI) { // check the input parameter Assert.notNull(nsURI, "Namespace URI must not be null."); for (Namespace namespace : namespaces) { if (nsURI.equals(namespace.getUri())) { return namespace.getPrefix(); } } // -- handle built-in namespace prefixes if (XML_NAMESPACE.equals(nsURI)) { return XML_NAMESPACE_PREFIX; } return null; }
Assert.notNull(uri, "Namespace URI must not be null");
/** * Returns the Namespace prefix associated with the given URI. Or null if no prefix has been * declared. This method will ignore the default namespace. This is useful when dealing with * attributes that do not use the default namespace. * * @param nsURI the namespace URI to lookup * @return the namespace prefix associated with the given URI * * @throws IllegalArgumentException if nsURI is null **/ public String getNonDefaultNamespacePrefix(String nsURI) { Assert.notNull(nsURI, "Namespace URI must not be null."); for (Namespace namespace : namespaces) { if (nsURI.equals(namespace.getUri()) && namespace.getPrefix().length() > 0) { return namespace.getPrefix(); } } // -- handle built-in namespace prefixes if (XML_NAMESPACE.equals(nsURI)) { return XML_NAMESPACE_PREFIX; } return null; }