/** * 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; }
@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 getByXPathNS(NamespaceContext namespaceContext, String xpath, Object... args) { Params.notNull(namespaceContext, "Name space context"); Params.notNullOrEmpty(xpath, "XPath"); return ownerDoc.evaluateXPathNodeNS(node, namespaceContext, xpath, args); }
/** * 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; }
@Override public Element getByXPathNS(NamespaceContext namespaceContext, String xpath, Object... args) { Params.notNull(namespaceContext, "Namespace context"); Params.notNullOrEmpty(xpath, "XPath"); return evaluateXPathNodeNS(doc, namespaceContext, xpath, args); }
/** * Create immutable instance type. * * @param value instance type value. * @throws IllegalArgumentException if instance type value is null. */ public InstanceType(String value) { Params.notNull(value, "Instance type value"); this.value = value; }
@Override public EList findByXPathNS(NamespaceContext namespaceContext, String xpath, Object... args) { Params.notNull(namespaceContext, "Name space context"); Params.notNullOrEmpty(xpath, "XPath"); return evaluateXPathNodeListNS(doc, namespaceContext, xpath, args); }
@Override public EList findByCss(String selector, Object... args) { Params.notNull(selector, "CSS selector"); throw new UnsupportedOperationException("CSS selectors not supported."); }
@Override public Element setAttrNS(String namespaceURI, String name, String value) { if (namespaceURI == null) { return setAttr(name, value); } Params.notNullOrEmpty(name, "Attribute name"); Params.notNull(value, "Attribute value"); node.setAttributeNS(namespaceURI, name, value); return this; }
/** * Add child configuration object. * * @param child child configuration object. * @throws IllegalArgumentException if <code>child</code> argument is null. */ public void addChild(Config child) { Params.notNull(child, "Child"); child.parent = this; children.add(child); }
/** * Convenient way to invoke standard date time formatter. * * @param date date value, null not accepted. * @return date value string into standard date time format. * @throws IllegalArgumentException if <code>date</code> argument is null. */ public static String format(Date date) { Params.notNull(date, "Date"); return new SimpleDateFormat(STANDARD_FORMAT).format(date); } }
/** * Remove extension from given file and create a new one with resulting path. * * @param file file to remove extension from. * @return newly created file without extension. * @throws IllegalArgumentException if <code>file</code> parameter is null. */ public static File removeExtension(File file) throws IllegalArgumentException { Params.notNull(file, "File"); return new File(removeExtension(file.getPath())); }
/** * Elements list factory. Create a new list of elements wrapping native W3C DOM nodes. If <code>nodeList</code> parameter * has no items returned elements list is empty. * * @param nodeList native DOM nodes list. * @return newly created elements list, possible empty. * @throws IllegalArgumentException if nodes list parameter is null. */ EList createEList(NodeList nodeList) { Params.notNull(nodeList, "Nodes list"); return new EListImpl(this, nodeList); }
@Override public EList findByCssClass(String cssClass) { Params.notNull(cssClass, "CSS class"); if (cssClass.isEmpty()) { return createEList(new NodeListImpl()); } return findByXPath(XPATH.CSS_CLASS, cssClass); }
@Override public Element addChild(Element... child) { for (Element el : child) { Params.notNull(el, "Element"); if (el.getDocument() != ownerDoc) { el = ownerDoc.importElement(el); } node.appendChild(node(el)); } return this; }
@Override public Element replaceChild(Element replacement, Element existing) { Params.notNull(replacement, "Replacement element"); Params.notNull(existing, "Exiting element"); if (replacement.getDocument() != ownerDoc) { replacement = ownerDoc.importElement(replacement); } node.replaceChild(node(replacement), node(existing)); return this; }
@Override public <T> T getInstance(Class<? super T> interfaceClass, Object... args) { Params.notNull(interfaceClass, "Interface class"); ManagedClassSPI managedClass = classesPool.get(interfaceClass); if (managedClass == null) { throw new BugError("No managed class associated with interface class |%s|.", interfaceClass); } InstanceKey instanceKey = new InstanceKey(managedClass.getKey()); return getInstance(managedClass, instanceKey, args); }
@Override public Element insertChild(Element child) { Params.notNull(child, "Child element"); Element firstChild = getFirstChild(); if (firstChild != null) { firstChild.insertBefore(child); } else { addChild(child); } return this; }
@Override public Element importElement(Element el) { Params.notNull(el, "Element"); Params.isTrue(el.getDocument() != this, "Element already belongs to this document."); return getElement(doc.importNode(((ElementImpl) el).getNode(), true)); }
@Override public void replace(Element replacement) { Params.notNull(replacement, "Replacement element"); if (replacement.getDocument() != ownerDoc) { replacement = ownerDoc.importElement(replacement); } node.getParentNode().replaceChild(node(replacement), node); node = (org.w3c.dom.Element) node(replacement); }