Пример #1
0
  /** Configure this transformer, possibly passing to it a jtidy configuration file location. */
  public void configure(Configuration config) throws ConfigurationException {
    super.configure(config);

    String configUrl = config.getChild("jtidy-config").getValue(null);
    if (configUrl != null) {
      org.apache.excalibur.source.SourceResolver resolver = null;
      Source configSource = null;
      try {
        resolver =
            (org.apache.excalibur.source.SourceResolver)
                this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
        configSource = resolver.resolveURI(configUrl);
        if (getLogger().isDebugEnabled()) {
          getLogger().debug("Loading configuration from " + configSource.getURI());
        }
        this.properties = new Properties();
        this.properties.load(configSource.getInputStream());

      } catch (Exception e) {
        getLogger().warn("Cannot load configuration from " + configUrl);
        throw new ConfigurationException("Cannot load configuration from " + configUrl, e);
      } finally {
        if (null != resolver) {
          this.manager.release(resolver);
          resolver.release(configSource);
        }
      }
    }
  }
Пример #2
0
 /**
  * Start buffering text if inside a tag to be normalized, passthru otherwise.
  *
  * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
  *     java.lang.String, org.xml.sax.Attributes)
  */
 public void startElement(String uri, String name, String raw, Attributes attr)
     throws SAXException {
   super.startElement(uri, name, raw, attr);
   if (this.tags.containsKey(name)) {
     this.startTextRecording();
   }
 }
Пример #3
0
 /**
  * React on endElement calls that contain a tag to be tidied and run Jtidy on it, otherwise
  * passthru.
  *
  * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String,
  *     java.lang.String)
  */
 public void endElement(String uri, String name, String raw) throws SAXException {
   if (this.tags.containsKey(name)) {
     String toBeNormalized = this.endTextRecording();
     try {
       this.normalize(toBeNormalized);
     } catch (ProcessingException e) {
       e.printStackTrace();
     }
   }
   super.endElement(uri, name, raw);
 }
Пример #4
0
 /** Setup this component, passing the tag names to be tidied. */
 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
     throws ProcessingException, SAXException, IOException {
   super.setup(resolver, objectModel, src, par);
   String tagsParam = par.getParameter("tags", "");
   if (getLogger().isDebugEnabled()) {
     getLogger().debug("tags: " + tagsParam);
   }
   this.tags = new HashMap();
   StringTokenizer tokenizer = new StringTokenizer(tagsParam, ",");
   while (tokenizer.hasMoreElements()) {
     String tok = tokenizer.nextToken().trim();
     this.tags.put(tok, tok);
   }
 }