You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2006/07/19 15:44:16 UTC

[jira] Resolved: (VALIDATOR-172) [validator] Return of result object from Validte Results

     [ http://issues.apache.org/jira/browse/VALIDATOR-172?page=all ]

Niall Pemberton resolved VALIDATOR-172.
---------------------------------------

    Fix Version/s: 1.2.0 Release
       Resolution: Fixed
         Assignee: Niall Pemberton

Re-openned and the set to "Resolved Fixed" again to correct "resolution" which was lost in Bugzilla --> JIRA conversion

> [validator] Return of result object from Validte Results
> --------------------------------------------------------
>
>                 Key: VALIDATOR-172
>                 URL: http://issues.apache.org/jira/browse/VALIDATOR-172
>             Project: Commons Validator
>          Issue Type: Improvement
>    Affects Versions: Nightly Builds
>         Environment: Operating System: Windows XP
> Platform: PC
>            Reporter: Manish Inala
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.2.0 Release
>
>
> I have implemented my own function to validate various text fields for correct
> html validation.
> I have this function in TestValidator.
> // import org.w3c.tidy.Tidy;  import this package 
> /**
>     * Checks if the field is required.
>     *
>     * @param 	value 		The value validation is being performed on.
>     * @return	boolean/Object	If the field isn't <code>null</code> and 
>     *                           has a length greater than zero, 
>     *                           <code>true</code> is returned.  
>     *                           Otherwise <code>false</code>.
>    */
>    public static Object validateHtml(Object bean, Field field) {
>        
>       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
>      
>         //creates a new Tidy
>         Tidy tidy = new Tidy();
>         URL configurationFile =
> Thread.currentThread().getContextClassLoader().getResource("tidy_default.cfg");
>               
>         try {
>             // if configuration file exists load and set it
>             Properties testProperties = new Properties();
>             testProperties.load(configurationFile.openStream());
>             tidy.setConfigurationFromProps(testProperties);
>         } catch ( IOException ioe)
>         { // not found should not happen 
>         }
>         
>         
>         // out
>         ByteArrayInputStream in = new ByteArrayInputStream(value.getBytes());
>         OutputStream out = new ByteArrayOutputStream();
>         // go!
>         StringWriter errorLog = new StringWriter();
>         tidy.setErrout(new PrintWriter(errorLog));       
>      
>         // parse the text  
>         tidy.parse( in, out); 
>         
>         // Put all the errors into a map and also the tidy's
>         // corrected suggestion to fix the errors
>         Map aResultMap = new HashMap();
>         aResultMap.put( "errors", (Object) new String( ""+tidy.getParseErrors()));
>         aResultMap.put( "warnings", (Object) new String(
> ""+tidy.getParseWarnings()));        
>         aResultMap.put( "error_report", (Object) (
> errorLog.getBuffer().toString()) );
>         aResultMap.put( "tidy_report", (Object) ( out.toString()) );
>                 
>         try { 
>            in.close();
>            out.close();
>         } catch (IOException ie)
>         {}                                           
>         return (Object) aResultMap;  
>    }
> By sending a Hashmap(or any object) I get more details about the errors which I
> can send it to the users for corrective action.  The problem I am having is not
> able to retrieve the object added to the ValidatorResult.ResultStatus object.
> If you can add this function(similar to isValid()) in ValidatorResult that would
> be great as we can add more customized errors and parse and display to the user.
>    public Object getResultObject(String validatorName) {
>       Object o = hAction.get(validatorName);
>       ResultStatus aStatus = null;
>       if (o != null) 
>            aStatus = (ResultStatus) o;
>       
>       return aStatus.getResult();
>    } 
> As In my case I have to have the tidy's suggestions to display to the user for a
> given text.
> Thanks
> Manish

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org