Пример #1
0
  /**
   * Add the supplied data as an entry in the deployment.
   *
   * @param path The target path of the entry when added to the archive.
   * @param data The data. Pass null to create a directory.
   * @return This archive instance.
   */
  public Archive addEntry(String path, byte[] data) {
    AssertArgument.isNotNullAndNotEmpty(path, "path");

    File entryFile = new File(tmpDir, path);

    if (entryFile.exists()) {
      entryFile.delete();
    }

    entryFile.getParentFile().mkdirs();
    if (data == null) {
      entryFile.mkdir();
    } else {
      try {
        FileUtils.writeFile(data, entryFile);
      } catch (IOException e) {
        throw new IllegalStateException(
            "Unexpected error writing Archive file '" + entryFile.getAbsolutePath() + "'.", e);
      }
    }

    entries.put(trimLeadingSlash(path.trim()), entryFile);

    return this;
  }
Пример #2
0
  /**
   * Add an "empty" entry in the deployment.
   *
   * <p>Equivalent to adding an empty folder.
   *
   * @param path The target path of the entry when added to the archive.
   * @return This archive instance.
   */
  public Archive addEntry(String path) {
    AssertArgument.isNotNullAndNotEmpty(path, "path");

    path = path.trim();
    if (path.endsWith("/")) {
      entries.put(trimLeadingSlash(path), null);
    } else {
      entries.put(trimLeadingSlash(path) + "/", null);
    }

    return this;
  }
  /* (non-Javadoc)
   * @see org.milyn.scribe.Finder#findBy(java.lang.String, java.util.Map)
   */
  @SuppressWarnings("unchecked")
  public Collection<Object> lookup(final String name, final Map<String, ?> parameters) {
    AssertArgument.isNotNullAndNotEmpty(name, "name");
    AssertArgument.isNotNull(parameters, "parameters");

    final Query emQuery = entityManager.createNamedQuery(name);

    for (final String key : parameters.keySet()) {

      emQuery.setParameter(key, parameters.get(key));
    }
    return emQuery.getResultList();
  }
Пример #4
0
  /**
   * Add the supplied character data as an entry in the deployment.
   *
   * @param path The target path of the entry when added to the archive.
   * @param data The data.
   * @return This archive instance.
   */
  public Archive addEntry(String path, String data) {
    AssertArgument.isNotNullAndNotEmpty(path, "path");
    AssertArgument.isNotNull(data, "data");

    try {
      addEntry(trimLeadingSlash(path.trim()), data.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(
          "Unexpected UnsupportedEncodingException exception for encoding 'UTF-8' when writing Archive entry from a StringBuilder instance.",
          e);
    }

    return this;
  }
  /* (non-Javadoc)
   * @see org.milyn.scribe.Finder#findBy(java.lang.String, java.util.Map)
   */
  @SuppressWarnings("unchecked")
  public Collection<Object> lookup(final String name, final Object... parameters) {
    AssertArgument.isNotNullAndNotEmpty(name, "name");
    AssertArgument.isNotNull(parameters, "parameters");

    final Query emQuery = entityManager.createNamedQuery(name);

    for (int i = 0; i < parameters.length; i++) {

      emQuery.setParameter(i + 1, parameters[i]);
    }

    return emQuery.getResultList();
  }
Пример #6
0
  /**
   * Add the supplied data as an entry in the deployment.
   *
   * @param path The target path of the entry when added to the archive.
   * @param data The data.
   * @return This archive instance.
   * @throws IOException Error reading from data stream.
   */
  public Archive addEntry(String path, InputStream data) throws IOException {
    AssertArgument.isNotNullAndNotEmpty(path, "path");
    AssertArgument.isNotNull(data, "data");

    try {
      byte[] dataBytes = StreamUtils.readStream(data);
      addEntry(trimLeadingSlash(path.trim()), dataBytes);
    } finally {
      try {
        data.close();
      } catch (IOException e) {
        logger.warn("Unable to close input stream for archive entry '" + path + "'.");
      }
    }

    return this;
  }
  /* (non-Javadoc)
   * @see org.milyn.scribe.QueryFinder#findByQuery(java.lang.String, java.util.Map)
   */
  @SuppressWarnings("unchecked")
  public Collection<Object> lookupByQuery(final String query, final Map<String, ?> parameters) {
    AssertArgument.isNotNullAndNotEmpty(query, "query");
    AssertArgument.isNotNull(parameters, "parameters");

    // Is this useful?
    if (query.startsWith("@")) {
      return lookup(query.substring(1), parameters);
    }

    final Query emQuery = entityManager.createQuery(query);

    for (final String key : parameters.keySet()) {

      emQuery.setParameter(key, parameters.get(key));
    }
    return emQuery.getResultList();
  }
  /* (non-Javadoc)
   * @see org.milyn.scribe.QueryFinder#findByQuery(java.lang.String, java.util.List)
   */
  @SuppressWarnings("unchecked")
  public Collection<Object> lookupByQuery(final String query, final Object... parameters) {
    AssertArgument.isNotNullAndNotEmpty(query, "query");
    AssertArgument.isNotNull(parameters, "parameters");

    // Is this useful?
    if (query.startsWith("@")) {
      return lookup(query.substring(1), parameters);
    }

    final Query emQuery = entityManager.createQuery(query);

    for (int i = 0; i < parameters.length; i++) {

      emQuery.setParameter(i + 1, parameters[i]);
    }

    return emQuery.getResultList();
  }
Пример #9
0
 /**
  * Public constructor.
  *
  * @param archiveName The archive name of the deployment.
  * @param archiveStream Archive stream containing initial archive entries.
  * @throws IOException Error reading from zip stream.
  */
 public Archive(String archiveName, ZipInputStream archiveStream) throws IOException {
   AssertArgument.isNotNullAndNotEmpty(archiveName, "archiveName");
   this.archiveName = archiveName;
   createTempDir();
   addEntries(archiveStream);
 }
Пример #10
0
 /**
  * Get an Archive entry file.
  *
  * @param resName Entry resource name.
  * @return The entry File, or null if the entry is not in the Archive.
  */
 public File getEntry(String resName) {
   AssertArgument.isNotNullAndNotEmpty(resName, "resName");
   return entries.get(resName);
 }