public boolean allowsMimeType(MimeType mimeType) {
    if (!getHasMimeTypes()) {
      return true;
    }

    if (getMimeTypes() == null || getMimeTypes().isEmpty()) {
      return true;
    }

    for (Iterator i = getMimeTypes().iterator(); i.hasNext(); ) {
      ItemDefinitionMimeType currentType = (ItemDefinitionMimeType) i.next();

      if (currentType.getSecondary() != null) {
        if (mimeType.getSubType().equals(currentType.getSecondary())
            && mimeType.getPrimaryType().equals(currentType.getPrimary())) {
          return true;
        }
      } else {
        if (mimeType.getPrimaryType().equals(currentType.getPrimary())) {
          return true;
        }
      }
    }

    return false;
  }
Exemplo n.º 2
0
  public Collection findByOwnerAndType(Id owner, String type, MimeType mimeType) {
    String primaryMimeType = null;
    String subMimeType = null;

    if (mimeType != null) {
      primaryMimeType = mimeType.getPrimaryType();
      subMimeType = mimeType.getSubType();
    }

    List artifacts =
        getContentHostingService()
            .findResources(ResourceProperties.FILE_TYPE, primaryMimeType, subMimeType);

    Collection returned = new ArrayList();

    for (Iterator i = artifacts.iterator(); i.hasNext(); ) {
      ContentResource resource = (ContentResource) i.next();
      // FIXME: Refactor to avoid double trips to AgentManager on every artifact -- Agent user type
      // gives performance hits
      Agent resourceOwner =
          getAgentManager()
              .getAgent(resource.getProperties().getProperty(ResourceProperties.PROP_CREATOR));
      if (owner == null || owner.equals(resourceOwner.getId())) {
        Artifact resourceArtifact = createArtifact(resource);
        returned.add(resourceArtifact);
      }
    }

    return returned;
  }