コード例 #1
0
  public void testCrawlUp() throws Exception {
    String text = "Look Pa, some more!";

    ModifiableTraversableSource src =
        (ModifiableTraversableSource) resolver.resolveURI("jcr://path/to/very/deep/content");
    write(src, text);

    // Do a fresh lookup
    src = (ModifiableTraversableSource) resolver.resolveURI("jcr://path/to/very/deep/content");

    ModifiableTraversableSource parent = (ModifiableTraversableSource) src.getParent();
    assertTrue(parent.exists());
    assertEquals("jcr://path/to/very/deep", parent.getURI());

    parent = (ModifiableTraversableSource) parent.getParent();
    assertTrue(parent.exists());
    assertEquals("jcr://path/to/very", parent.getURI());

    parent = (ModifiableTraversableSource) parent.getParent();
    assertTrue(parent.exists());
    assertEquals("jcr://path/to", parent.getURI());

    parent = (ModifiableTraversableSource) parent.getParent();
    assertTrue(parent.exists());
    assertEquals("jcr://path", parent.getURI());

    parent = (ModifiableTraversableSource) parent.getParent();
    assertTrue(parent.exists());
    assertEquals("jcr://", parent.getURI());

    // Root node has no parent
    parent = (ModifiableTraversableSource) parent.getParent();
    assertNull(parent);
  }
コード例 #2
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);
        }
      }
    }
  }
コード例 #3
0
  public void testDeleteFile() throws Exception {
    String text = "Yeah! Some content!";
    ModifiableSource source = (ModifiableSource) resolver.resolveURI("jcr://yet/another/deep/file");

    assertFalse(source.exists());
    write(source, text);

    // Lookup a fresh source
    source = (ModifiableSource) resolver.resolveURI("jcr://yet/another/deep/file");
    assertTrue(source.exists());
    source.delete();
    assertFalse(source.exists());

    // Lookup again to check it was really deleted
    source = (ModifiableSource) resolver.resolveURI("jcr://yet/another/deep/file");
    assertFalse(source.exists());
  }
コード例 #4
0
  public void testGetRootNode() throws Exception {

    JCRNodeSource source = (JCRNodeSource) resolver.resolveURI("jcr://");

    assertTrue("Root node should exist", source.exists());
    System.err.println("Root node type = " + source.getNode().getPrimaryNodeType().getName());
    assertTrue("Root node should be a collection", source.isCollection());
  }
コード例 #5
0
ファイル: SendNewsletter.java プロジェクト: wyona/lenya
 /**
  * Resolves the URI and returns it's contents as a String object
  *
  * @param resolver The SourceResolver
  * @param uri The URI
  * @return The URI content
  * @throws Exception
  */
 private String getURIContentsAsString(SourceResolver resolver, String uri) throws Exception {
   Source source = resolver.resolveURI(uri);
   Reader reader = new InputStreamReader(source.getInputStream(), "UTF-8");
   StringBuffer buf = new StringBuffer();
   int rb = 0;
   char[] cbuf = new char[1024];
   while ((rb = reader.read(cbuf)) > 0) {
     buf.append(cbuf, 0, rb);
   }
   return buf.toString();
 }
コード例 #6
0
  public void testCreateDeepFile() throws Exception {
    String anotherText = "another text";

    JCRNodeSource source = (JCRNodeSource) resolver.resolveURI("jcr://some/deep/path/to/file");
    assertFalse(source.exists());

    write(source, anotherText);

    // Lookup again, using the parent, doing some traversal
    TraversableSource dir = (TraversableSource) resolver.resolveURI("jcr://some/deep");
    assertTrue(dir.isCollection());
    dir = (TraversableSource) dir.getChild("path");
    assertTrue(dir.isCollection());
    dir = (TraversableSource) dir.getChild("to");
    assertTrue(dir.isCollection());

    source = (JCRNodeSource) dir.getChild("file");
    assertTrue(source.exists());

    assertEquals(anotherText, read(source));
  }
コード例 #7
0
  public void testDeleteDir() throws Exception {
    String text = "Wow, a lot of data going there";
    ModifiableTraversableSource source =
        (ModifiableTraversableSource) resolver.resolveURI("jcr://and/again/a/deep/node");

    assertFalse(source.exists());
    write(source, text);

    // Lookup 'a' node
    source = (ModifiableTraversableSource) resolver.resolveURI("jcr://and/again/a/");
    assertTrue(source.isCollection());
    source.delete();
    assertFalse(source.exists());

    // Double check with a fresh source
    source = (ModifiableTraversableSource) resolver.resolveURI("jcr://and/again/a/");
    assertFalse(source.exists());

    // Check on children
    source = (ModifiableTraversableSource) resolver.resolveURI("jcr://and/again/a/deep/node");
    assertFalse(source.exists());
  }
コード例 #8
0
 private static Source resolve(String uri) throws MalformedURLException, IOException {
   SourceResolver resolver = null;
   TraversableSource source;
   try {
     resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
     source = (TraversableSource) resolver.resolveURI(uri);
   } catch (ComponentException ce) {
     throw new IOException("ComponentException");
   } finally {
     manager.release((Component) resolver);
   }
   return source;
 }
コード例 #9
0
  public void testCreateFirstLevelFile() throws Exception {

    String someText = "Some text";

    JCRNodeSource root = (JCRNodeSource) resolver.resolveURI("jcr://");

    JCRNodeSource firstChild = (JCRNodeSource) root.getChild("child1");

    assertFalse(firstChild.exists());
    assertEquals(firstChild.getURI(), "jcr://child1");

    write(firstChild, someText);

    assertTrue(firstChild.exists());

    // Check content
    Source child1 = resolver.resolveURI("jcr://child1");
    assertTrue(child1.exists());

    int len = (int) child1.getContentLength();
    assertEquals(someText.length(), len);
    assertEquals(someText, read(child1));
  }
コード例 #10
0
  public void testTraverseDir() throws Exception {
    String text = "Look Ma, more data!";

    ModifiableTraversableSource dir =
        (ModifiableTraversableSource) resolver.resolveURI("jcr://path/to/dir");
    dir.makeCollection();

    for (int i = 0; i < 10; i++) {
      ModifiableTraversableSource src = (ModifiableTraversableSource) dir.getChild("file" + i);
      write(src, text + i);
    }

    // Lookup dir again, and inspect children
    dir = (ModifiableTraversableSource) resolver.resolveURI("jcr://path/to/dir");
    Collection children = dir.getChildren();

    assertEquals(10, children.size());

    for (int i = 0; i < 10; i++) {
      Source src = dir.getChild("file" + i);
      assertTrue(src.exists());
      assertEquals(text + i, read(src));
    }
  }
コード例 #11
0
ファイル: ZipSourceFactory.java プロジェクト: tpso-src/cocoon
  public Source getSource(String location, Map parameters)
      throws IOException, MalformedURLException {
    // Checks URL syntax
    int protocolEnd = location.indexOf(":");
    if (protocolEnd == -1) {
      throw new MalformedURLException("Protocol ':' separator is missing in URL: " + location);
    }

    int archiveEnd = location.lastIndexOf("!/");
    if (archiveEnd == -1) {
      throw new MalformedURLException("File path '!/' separator is missing in URL: " + location);
    }

    // Get protocol. Protocol is configurable via cocoon.xconf
    final String protocol = location.substring(0, protocolEnd - 1);

    // Get archive URL
    final String archiveURL = location.substring(protocolEnd + 1, archiveEnd);

    // Get file path
    final String filePath = location.substring(archiveEnd + 2);

    // Resolve archive source
    Source archive;
    SourceResolver resolver = null;
    try {
      resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
      archive = resolver.resolveURI(archiveURL);
    } catch (ServiceException se) {
      throw new SourceException("SourceResolver is not available.", se);
    } finally {
      this.manager.release(resolver);
    }

    return new ZipSource(protocol, archive, filePath);
  }