commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Reopened: (VALIDATOR-172) [validator] Return of result object from Validte Results
Date Wed, 19 Jul 2006 13:31:36 GMT
     [ http://issues.apache.org/jira/browse/VALIDATOR-172?page=all ]

Niall Pemberton reopened VALIDATOR-172:
---------------------------------------

             

> [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
>            Priority: Minor
>
> 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


Mime
View raw message