Return-Path: Delivered-To: apmail-xerces-commits-archive@www.apache.org Received: (qmail 65189 invoked from network); 30 Oct 2010 06:17:12 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 30 Oct 2010 06:17:12 -0000 Received: (qmail 55868 invoked by uid 500); 30 Oct 2010 06:17:12 -0000 Delivered-To: apmail-xerces-commits-archive@xerces.apache.org Received: (qmail 55811 invoked by uid 500); 30 Oct 2010 06:17:10 -0000 Mailing-List: contact commits-help@xerces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@xerces.apache.org Received: (qmail 55804 invoked by uid 99); 30 Oct 2010 06:17:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 Oct 2010 06:17:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 Oct 2010 06:17:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 60498238890D; Sat, 30 Oct 2010 06:16:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1029000 - /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java Date: Sat, 30 Oct 2010 06:16:09 -0000 To: commits@xerces.apache.org From: mukulg@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101030061609.60498238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mukulg Date: Sat Oct 30 06:16:09 2010 New Revision: 1029000 URL: http://svn.apache.org/viewvc?rev=1029000&view=rev Log: doing a little improvement (thought this was useful, and is optional) to assertions error messages (which uses Xerces extensions namespace). we are now able to provide an atomic value available in validation context (the value of assertions XPath2 context variable $value) to assertions error messages. for example, if there is an assertion facet defined like following: and if this assertion fails in an validation episode, the following error message is generated by Xerces: "The value must be divisible by 2. Atomic value 101 is not divisible by 2." (the instance document had value 101) The placeholder for this feature must be {$value} and there can be multiple instances of this placeholder in single message, and all of them will be replace by the run-time value of $value. Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=1029000&r1=1028999&r2=1029000&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java Sat Oct 30 06:16:09 2010 @@ -113,6 +113,9 @@ public class XMLAssertPsychopathImpl ext // an instance variable to track the name of an attribute currently // been processed for assertions. private String fAttrName = null; + + // a placeholder definition used for assertions error messages. + private final String ERROR_PLACEHOLDER_REGEX = "\\{\\$value\\}"; /* @@ -258,7 +261,7 @@ public class XMLAssertPsychopathImpl ext /* * Method to evaluate all of XML schema 1.1 assertions for an element tree. - * This is the root method, which evaluates all XML schema assertions, in + * This is the root method which evaluates all XML schema assertions, in * a single XML instance validation episode. */ private void processAllAssertionsOnElement(QName element, @@ -921,6 +924,7 @@ public class XMLAssertPsychopathImpl ext QName element = assertError.getElement(); XSAssertImpl assertImpl = assertError.getAssertion(); boolean isList = assertError.isList(); + String value = assertError.getValue(); XSTypeDefinition typeDef = assertImpl.getTypeDefinition(); String typeString = ""; @@ -948,6 +952,12 @@ public class XMLAssertPsychopathImpl ext String message = assertImpl.getMessage(); if (message != null) { + // substitute all placeholder macro instances of "{$value}" with atomic value + // stored in variable "value". + if (value != null && !"".equals(value)) { + message = message.replaceAll(ERROR_PLACEHOLDER_REGEX, value); + } + if (!message.endsWith(".")) { message = message + "."; } @@ -958,7 +968,7 @@ public class XMLAssertPsychopathImpl ext else { message = "Assertion failed for schema type '" + typeString + "'. " + message; - } + } fValidator.reportSchemaError("cvc-assertion.failure", new Object[] { message, listAssertErrMessage } ); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org For additional commands, e-mail: commits-help@xerces.apache.org