コード例 #1
0
ファイル: HTMLTransformer.java プロジェクト: tpso-src/cocoon
  /** 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
  public SourceProperty getSourceProperty(Source source, String namespace, String name)
      throws SourceException {

    if ((namespace.equals(m_namespace))
        && (name.equals(m_propertyname))
        && (source.getURI().endsWith(m_extension))) {

      DOMParser parser = null;
      Document doc = null;
      try {
        parser = (DOMParser) manager.lookup(DOMParser.ROLE);
        InputSource is = new InputSource(source.getInputStream());
        is.setSystemId(source.getURI());
        doc = parser.parseDocument(is);
      } catch (SAXException se) {
        getLogger().error(source.getURI() + " is not a valid XML file");
      } catch (IOException ioe) {
        getLogger().error("Could not read file", ioe);
      } catch (ServiceException ce) {
        getLogger().error("Missing service dependency: DOMParser", ce);
      } finally {
        if (parser != null) {
          this.manager.release(parser);
        }
      }

      if (doc != null) {
        XPathProcessor processor = null;
        try {
          processor = (XPathProcessor) manager.lookup(XPathProcessor.ROLE);
          NodeList nodelist = processor.selectNodeList(doc.getDocumentElement(), m_xpath);
          SourceProperty property = new SourceProperty(m_namespace, m_propertyname);
          property.setValue(nodelist);
          return property;
        } catch (ServiceException se) {
          this.getLogger().error("Could not retrieve component", se);
        } finally {
          if (processor != null) {
            this.manager.release(processor);
          }
        }
      }
    }
    return null;
  }
コード例 #3
0
 /** Checks the source uri for the .jp(e)g extension. */
 protected final boolean isImageMimeType(Source source) {
   final String uri = source.getURI();
   final int index = uri.lastIndexOf('.');
   if (index != -1) {
     String extension = uri.substring(index);
     return extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".JPEG");
   }
   return false;
 }
コード例 #4
0
ファイル: TextGenerator.java プロジェクト: tpso-src/cocoon
 /**
  * Generate the unique key. This key must be unique inside the space of this component.
  *
  * @return The generated key hashes the src
  */
 public Serializable getKey() {
   return inputSource.getURI() + ";localizable=" + localizable + ";encoding=" + encoding;
 }