/** * Perform validation on namespace qualified attribute values if present. This includes the * validation of namespace presence and equality. * * @param receivedElement * @param receivedAttribute * @param sourceElement * @param sourceAttribute */ private void doNamespaceQualifiedAttributeValidation( Node receivedElement, Node receivedAttribute, Node sourceElement, Node sourceAttribute) { String receivedValue = receivedAttribute.getNodeValue(); String sourceValue = sourceAttribute.getNodeValue(); if (receivedValue.contains(":") && sourceValue.contains(":")) { // value has namespace prefix set, do special QName validation String receivedPrefix = receivedValue.substring(0, receivedValue.indexOf(':')); String sourcePrefix = sourceValue.substring(0, sourceValue.indexOf(':')); Map<String, String> receivedNamespaces = XMLUtils.lookupNamespaces(receivedAttribute.getOwnerDocument()); receivedNamespaces.putAll(XMLUtils.lookupNamespaces(receivedElement)); if (receivedNamespaces.containsKey(receivedPrefix)) { Map<String, String> sourceNamespaces = XMLUtils.lookupNamespaces(sourceAttribute.getOwnerDocument()); sourceNamespaces.putAll(XMLUtils.lookupNamespaces(sourceElement)); if (sourceNamespaces.containsKey(sourcePrefix)) { Assert.isTrue( sourceNamespaces.get(sourcePrefix).equals(receivedNamespaces.get(receivedPrefix)), ValidationUtils.buildValueMismatchErrorMessage( "Values not equal for attribute value namespace '" + receivedValue + "'", sourceNamespaces.get(sourcePrefix), receivedNamespaces.get(receivedPrefix))); // remove namespace prefixes as they must not form equality receivedValue = receivedValue.substring((receivedPrefix + ":").length()); sourceValue = sourceValue.substring((sourcePrefix + ":").length()); } else { throw new ValidationException( "Received attribute value '" + receivedAttribute.getLocalName() + "' describes namespace qualified attribute value," + " control value '" + sourceValue + "' does not"); } } } Assert.isTrue( receivedValue.equals(sourceValue), ValidationUtils.buildValueMismatchErrorMessage( "Values not equal for attribute '" + receivedAttribute.getLocalName() + "'", sourceValue, receivedValue)); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("rem"); int size; if (definitionURL != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "definitionURL", definitionURL); } if (classValue != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "class", classValue); } if (style != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "style", style); } if (id != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "id", id); } if (other != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "other", other); } parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("fixme"); int size; if (this.author_ != null) { URelaxer.setAttributePropertyByString(element, "author", this.author_); } if (this.id_ != null) { URelaxer.setAttributePropertyByString(element, "id", this.id_); } if (this.xmlLang_ != null) { URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_); } size = this.content_.size(); for (int i = 0; i < size; i++) { IFdContentMixMixed value = (IFdContentMixMixed) this.content_.get(i); value.makeElement(element); } parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("set"); int size; if (classValue != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "class", classValue); } if (style != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "style", style); } if (id != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "id", id); } if (other != null) { URelaxer2.setAttributePropertyByString( element, "http://www.w3.org/1998/Math/MathML", "other", other); } size = content.size(); for (int i = 0; i < size; i++) { IMSetContent value = (IMSetContent) this.content.get(i); value.makeElement(element); } parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("table"); int size; if (this.id_ != null) { URelaxer.setAttributePropertyByString(element, "id", this.id_); } if (this.xmlLang_ != null) { URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_); } if (this.caption_ != null) { this.caption_.makeElement(element); } size = this.tr_.size(); for (int i = 0; i < size; i++) { FcTr value = (FcTr) this.tr_.get(i); value.makeElement(element); } parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc = parent.getOwnerDocument(); Element element = (Element) parent; int size; size = this.paramListParam_.size(); for (int i = 0; i < size; i++) { XParamListParam value = (XParamListParam) this.paramListParam_.get(i); value.makeElement(element); } }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("center"); int size; URelaxer.setElementPropertyByString(element, "ra", ra); URelaxer.setElementPropertyByString(element, "decl", decl); parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElementNS( "http://www.iso_relax.org/xmlns/miaou/binaryTreeAutomaton", "textTransition"); rNSContext_.setupNamespace(element); int size; URelaxer.setAttributePropertyByInt(element, "target", this.target_); URelaxer.setAttributePropertyByInt(element, "right", this.right_); parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElementNS("http://www.asahi-net.or.jp/~cs8k-cyu/bulletml", "direction"); rNSContext_.setupNamespace(element); URelaxer.setElementPropertyByString(element, this.content_); int size; if (this.type_ != null) { URelaxer.setAttributePropertyByString(element, "type", this.type_); } parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("header"); int size; if (this.id_ != null) { URelaxer.setAttributePropertyByString(element, "id", this.id_); } if (this.xmlLang_ != null) { URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_); } this.title_.makeElement(element); if (this.subtitle_ != null) { this.subtitle_.makeElement(element); } if (this.version_ != null) { this.version_.makeElement(element); } if (this.type_ != null) { this.type_.makeElement(element); } if (this.authors_ != null) { this.authors_.makeElement(element); } size = this.notice_.size(); for (int i = 0; i < size; i++) { FtNotice value = (FtNotice) this.notice_.get(i); value.makeElement(element); } if (this.abstract_ != null) { this.abstract_.makeElement(element); } parent.appendChild(element); }
/** * This method validates one field. * * @param field the field which should be validated. * @return true is the field is valid, false if it is invalid. */ public static boolean validateField(Node field) { String ftype = Utils.getAttribute(field, "ftype", ""); String dttype = Utils.getAttribute(field, "dttype", "string"); if (ftype.equals("data") || ftype.equals("startwizard")) return true; // ok. String value = Utils.getText(Utils.selectSingleNode(field, "value"), ""); // clean up old validation info if exists Node val = Utils.selectSingleNode(field, "validator"); if (val != null) { field.removeChild(val); } val = field.getOwnerDocument().createElement("validator"); field.appendChild(val); Utils.setAttribute(val, "valid", "true"); int valueLength = value.length(); if ("binary".equals(dttype) && (valueLength == 0)) { String valueSize = Utils.getAttribute(field, "size", "0"); try { valueLength = Integer.parseInt(valueSize); } catch (NumberFormatException nfe) { valueLength = 0; } } boolean required = Utils.getAttribute(field, "dtrequired", "false").equals("true"); if (required && valueLength <= 0) { addValidationError(val, 1, "Value is required."); } else { if ("string".equals(dttype)) { int dtminlength = 0; try { dtminlength = Integer.parseInt(Utils.getAttribute(field, "dtminlength", "0")); } catch (Exception e) { // don't mind that } if (valueLength < dtminlength) { addValidationError(val, 1, "Entered text is too short."); } else { int dtmaxlength = 640000; try { dtmaxlength = Integer.parseInt(Utils.getAttribute(field, "dtmaxlength", "640000")); } catch (Exception e) { // don't mind that again } if (valueLength > dtmaxlength) { addValidationError(val, 1, "Entered text is too long."); } } } if ("int".equals(dttype) && valueLength > 0) { // int int nr = 0; boolean isint = false; try { nr = Integer.parseInt(value); isint = true; } catch (Exception e) { addValidationError(val, 1, "Entered value is not a valid integer number."); } if (isint) { // check min and max bounds int dtmin = Integer.parseInt(Utils.getAttribute(field, "dtmin", "0")); int dtmax = Integer.parseInt(Utils.getAttribute(field, "dtmax", "999999999")); if (nr < dtmin || nr > dtmax) { addValidationError(val, 1, "Integer value is too small or too large."); } } } if ("date".equals(dttype)) { // date // TODO } if ("enum".equals(dttype)) { // enum // TODO } } return Utils.getAttribute(val, "valid").equals("true"); }
/** * This method adds a validation error to the form. * * @param validationnode this node was validated * @param errortype what kind of error was it? * @param errormsg what errormessage should be placed. */ public static void addValidationError(Node validationnode, int errortype, String errormsg) { Utils.setAttribute(validationnode, "valid", "false"); Node msg = validationnode.getOwnerDocument().createElement("error"); Utils.setAttribute(msg, "type", errortype + ""); Utils.storeText(msg, errormsg); }
public XML addChild(XML child) { Document document = node.getOwnerDocument(); Node newChild = document.importNode((Node) child.getNative(), true); return appendChild(newChild); }
/** * @webref xml:method * @brief Appends a new child to the element */ public XML addChild(String tag) { Document document = node.getOwnerDocument(); Node newChild = document.createElement(tag); return appendChild(newChild); }
/** * @webref xml:method * @brief Sets the element's name */ public void setName(String newName) { Document document = node.getOwnerDocument(); node = document.renameNode(node, null, newName); // name = node.getNodeName(); }