Ejemplo n.º 1
0
 /** @see IStructuredContentProvider#getElements(Object) */
 @Override
 public Object[] getElements(Object inputElement) {
   if (inputElement instanceof Class<?> && ((Class<?>) inputElement).isEnum()) {
     @SuppressWarnings("unchecked")
     Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) inputElement;
     try {
       Method method = enumClass.getMethod("values");
       return (Object[]) method.invoke(null);
     } catch (Exception e) {
       log.error("Could not get values from enum.");
     }
   }
   return new Object[] {};
 }
Ejemplo n.º 2
0
  /**
   * Create an I/O advisor for the given content type.
   *
   * @param contentType the content type, may be <code>null</code>
   * @return the resource advisor for that content type or a default resource advisor
   */
  public ResourceAdvisor getAdvisor(IContentType contentType) {
    if (contentType == null) {
      return DEFAULT;
    }

    boolean error = false;
    for (ResourceAdvisorDescriptor factory : getFactories()) {
      if (factory.getAssociatedTypes().contains(contentType)) {
        try {
          return factory.createExtensionObject();
        } catch (Exception e) {
          log.error("Could not create resource advisor " + factory.getIdentifier(), e);
          error = true;
        }
      }
    }

    if (error) {
      log.warn(
          "Using default resource advisor as fall-back for content type " + contentType.getName());
    }

    return DEFAULT;
  }
Ejemplo n.º 3
0
  /** @see Form#onSubmit() */
  @Override
  protected void onSubmit() {
    final String project = identifier.getModel().getObject();
    try {
      final FileUpload upload = file.getFileUpload();
      if (upload != null) {
        File dir = projects.reserveResourceId(project);

        //				File target = new File(dir, upload.getClientFileName());
        String type = upload.getContentType();
        if (checkContentType(type)) {
          //					IOUtils.copy(upload.getInputStream(), new FileOutputStream(target));

          // try extracting the archive
          IOUtils.extract(dir, new BufferedInputStream(upload.getInputStream()));

          // trigger scan after upload
          projects.triggerScan();
          info("Successfully uploaded project");

          onUploadSuccess();
        } else {
          projects.releaseResourceId(project);
          error(getTypeErrorMessage(type));
        }
      } else {
        warn("Please provide a file for upload");
      }
    } catch (ScavengerException e) {
      error(e.getMessage());
    } catch (Exception e) {
      projects.releaseResourceId(project);
      log.error("Error while uploading file", e);
      error("Error saving the file");
    }
  }