You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/03/15 16:52:06 UTC

DO NOT REPLY [Bug 27671] New: - Return of result object from Validte Results.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27671>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27671

Return of result object from Validte Results.

           Summary: Return of result object from Validte Results.
           Product: Commons
           Version: 1.0.2
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Validator
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: minala@idefense.com


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

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