Пример #1
0
  @Override
  public NodeTypeIterator registerNodeTypes(URL url, boolean allowUpdate)
      throws IOException, RepositoryException {
    String content = IoUtil.read(url.openStream());
    if (content.startsWith("<?xml")) {
      // This is Jackrabbit XML format ...
      return registerNodeTypes(
          importFromXml(new InputSource(new StringReader(content))), allowUpdate);
    }
    // Assume this is CND format ...
    CndImporter importer = new CndImporter(context(), true);
    Problems problems = new SimpleProblems();
    importer.importFrom(content, problems, url.toExternalForm());

    // Check for (and report) any problems ...
    if (problems.hasProblems()) {
      // There are errors and/or warnings, so report them ...
      String summary = messageFrom(problems);
      if (problems.hasErrors()) {
        String msg = JcrI18n.errorsParsingNodeTypeDefinitions.text(url.toExternalForm(), summary);
        throw new RepositoryException(msg);
      }
      // Otherwise, there are warnings, so log them ...
      I18n msg = JcrI18n.warningsParsingNodeTypeDefinitions;
      Logger.getLogger(getClass()).warn(msg, url.toExternalForm(), summary);
    }

    // Register the node types ...
    return registerNodeTypes(importer.getNodeTypeDefinitions(), allowUpdate);
  }
  protected Binary storeAndCheck(int contentIndex, Class<? extends Binary> valueClass)
      throws Exception {
    String content = CONTENT[contentIndex];
    String sha1 = CONTENT_HASHES[contentIndex];
    InputStream stream = new ByteArrayInputStream(content.getBytes());

    Stopwatch sw = new Stopwatch();
    sw.start();
    Binary binary = store.storeValue(stream, false);
    sw.stop();
    if (print) System.out.println("Time to store 18MB file: " + sw.getTotalDuration());

    if (valueClass != null) {
      assertThat(binary, is(instanceOf(valueClass)));
    }
    if (content.length() == 0) {
      assertThat(binary, is(instanceOf(EmptyBinaryValue.class)));
    } else if (content.length() < MIN_BINARY_SIZE) {
      assertThat(binary, is(instanceOf(InMemoryBinaryValue.class)));
    } else {
      assertThat(binary, is(instanceOf(StoredBinaryValue.class)));
    }
    assertThat(binary.getHexHash(), is(sha1));
    String binaryContent = IoUtil.read(binary.getStream());
    assertThat(binaryContent, is(content));
    return binary;
  }
Пример #3
0
 protected Map<Name, Property> load(File propertiesFile, ExecutionContext context)
     throws RepositorySourceException {
   if (!propertiesFile.exists() || !propertiesFile.canRead()) return NO_PROPERTIES_MAP;
   try {
     String content = IoUtil.read(propertiesFile);
     ValueFactories factories = context.getValueFactories();
     PropertyFactory propFactory = context.getPropertyFactory();
     Map<Name, Property> result = new HashMap<Name, Property>();
     for (String line : StringUtil.splitLines(content)) {
       // Parse each line ...
       Property property = parse(line, factories, propFactory);
       if (property != null) {
         result.put(property.getName(), property);
       }
     }
     return result;
   } catch (IOException e) {
     throw new RepositorySourceException(sourceName, e);
   }
 }
  @Test
  public void shouldCleanTrashFilesWhenFilesBecomeUsed() throws Exception {
    Set<Binary> binaries = new HashSet<Binary>();
    int storedCount = 0;
    for (int i = 0; i != CONTENT.length; ++i) {
      Binary binary = storeAndCheck(i);
      assertThat(binary, is(notNullValue()));
      binaries.add(binary);
      if (binary instanceof StoredBinaryValue) storedCount++;
    }

    // Make sure there are files for all stored values ...
    assertThat(countStoredFiles(), is(storedCount));
    assertThat(countTrashFiles(), is(0));

    // Mark one of the files as being unused ...
    String unused = binaries.iterator().next().getHexHash();
    BinaryKey unusedKey = new BinaryKey(unused);
    store.markAsUnused(Collections.singleton(unusedKey));

    // Make sure the file was moved to the trash ...
    assertThat(countStoredFiles(), is(storedCount));
    assertThat(countTrashFiles(), is(1));

    // Now access all the binary files which will not change there used/unused state
    for (Binary binary : binaries) {
      InputStream stream = binary.getStream();
      String content = IoUtil.read(stream);
      assertThat(content.length() != 0, is(true));
    }

    // Make sure there are files for all stored values ...
    assertThat(countStoredFiles(), is(storedCount));
    assertThat(countTrashFiles(), is(1));

    // Now mark the file explicitly as used and check that the file from the trash was removed
    store.markAsUsed(Collections.singleton(unusedKey));
    assertThat(countTrashFiles(), is(0));
  }