Exemplo n.º 1
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());
  }
Exemplo n.º 2
0
  public static boolean remove(ModifiableTraversableSource resource) {
    boolean success = true;

    if (resource.isCollection()) {
      Collection contents;
      try {
        contents = resource.getChildren();
      } catch (SourceException se) {
        throw new RuntimeException("Unable to list contents for collection " + resource);
      }
      for (Iterator iter = contents.iterator(); iter.hasNext(); ) {
        ModifiableTraversableSource element = (ModifiableTraversableSource) iter.next();
        success = remove(element);
      }
    }
    try {
      resource.delete();
      return success;
    } catch (SourceException e) {
      return false;
    }
  }