Changeset 6999


Ignore:
Timestamp:
09/28/10 11:08:46 (9 years ago)
Author:
melissa
Message:

Merged common XML changes in to 4.2: r6717, r6888, and r6985.

Location:
branches/4.2/components/common/src/loci/common/xml
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/4.2/components/common/src/loci/common/xml/ValidationErrorHandler.java

    r6495 r6999  
    3838 * @author Melissa Linkert melissa at glencoesoftware.com 
    3939 */ 
    40 class ValidationErrorHandler implements ErrorHandler { 
    41   private boolean ok = true; 
    42   public boolean ok() { return ok; } 
     40public class ValidationErrorHandler implements ErrorHandler { 
     41 
     42  private int errors = 0; 
     43 
     44  public boolean ok() { return errors == 0; } 
     45 
     46  public int getErrorCount() { return errors; } 
     47 
    4348  public void error(SAXParseException e) { 
    44     XMLTools.LOGGER.error(e.getMessage(), e); 
    45     ok = false; 
     49    XMLTools.LOGGER.error(e.getMessage()); 
     50    errors++; 
    4651  } 
     52 
    4753  public void fatalError(SAXParseException e) { 
    48     XMLTools.LOGGER.error(e.getMessage(), e); 
    49     ok = false; 
     54    XMLTools.LOGGER.error(e.getMessage()); 
     55    errors++; 
    5056  } 
     57 
    5158  public void warning(SAXParseException e) { 
    52     XMLTools.LOGGER.warn(e.getMessage(), e); 
    53     ok = false; 
     59    XMLTools.LOGGER.warn(e.getMessage()); 
     60    errors++; 
    5461  } 
     62 
    5563} 
  • branches/4.2/components/common/src/loci/common/xml/XMLTools.java

    r6667 r6999  
    127127    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    128128    DocumentBuilder db = factory.newDocumentBuilder(); 
     129    db.setErrorHandler(new ParserErrorHandler()); 
    129130    return db.parse(is); 
    130131  } 
     
    155156      } 
    156157    } 
    157     return s; 
     158    return s.replaceAll("&#", ""); 
    158159  } 
    159160 
     
    396397    try { 
    397398      trans = xslt.newTransformer(); 
     399      trans.setErrorListener(new XMLListener()); 
    398400    } 
    399401    catch (TransformerConfigurationException exc) { 
     
    503505    catch (IOException exc) { exception = exc; } 
    504506    catch (SAXException exc) { exception = exc; } 
    505     if (exception != null) { 
    506       LOGGER.info("Error validating document", exception); 
     507    final int errors = errorHandler.getErrorCount(); 
     508    if (errors > 0) { 
     509      LOGGER.info("Error validating document: {} errors found", errors); 
    507510      return false; 
    508511    } 
    509     if (errorHandler.ok()) LOGGER.info("No validation errors found."); 
     512    else LOGGER.info("No validation errors found."); 
    510513    return errorHandler.ok(); 
    511514  } 
     
    516519  static class XMLListener implements ErrorListener { 
    517520    public void error(TransformerException e) { 
    518       LOGGER.warn("", e); 
     521      LOGGER.debug("", e); 
    519522    } 
    520523 
    521524    public void fatalError(TransformerException e) { 
    522       LOGGER.warn("", e); 
     525      LOGGER.debug("", e); 
    523526    } 
    524527 
Note: See TracChangeset for help on using the changeset viewer.