Example #1
0
  /**
   * TODO support references relative to current resource, like "../foo.mp4".
   *
   * @param mediaRef link/reference to a media resource. Must either be root relative path or an
   *     absolute URL with protocol.
   * @return a {@link URL} instance, or <code>null</code> if no appropriate URL could be created
   *     from reference.
   */
  private URL createUrl(String mediaRef) {

    if (mediaRef == null) return null;

    if (URL.isEncoded(mediaRef)) {
      mediaRef = urlDecodeMediaRef(mediaRef);
    }

    if (mediaRef.startsWith("/")) {
      URL localURL = null;
      try {
        Path uri = Path.fromString(mediaRef);
        localURL = this.viewService.constructURL(uri);
      } catch (Exception e) {
        // ignore
      }
      if (localURL != null) {
        return localURL;
      }

    } else {
      URL externalURL = null;
      try {
        externalURL = URL.parse(mediaRef);
      } catch (Exception e) {
        // ignore
      }
      if (externalURL != null) {
        return externalURL;
      }
    }
    return null;
  }
Example #2
0
  private Resource getLocalResource(String resourceRef) throws Exception {
    if (resourceRef != null && resourceRef.startsWith("/")) {
      RequestContext requestContext = RequestContext.getRequestContext();
      Repository repository = requestContext.getRepository();
      String token = requestContext.getSecurityToken();
      return repository.retrieve(token, Path.fromString(resourceRef), true);
    }

    return null;
  }
Example #3
0
  /**
   * Returns all currently cached descendant URIs.
   *
   * @param uri
   * @return
   */
  public List<Path> getCachedDescendantPaths(Path uri) {
    List<Path> paths = new ArrayList<Path>();

    for (Path cachedUri : this.items.uriSet()) {
      if (uri.isAncestorOf(cachedUri)) {
        paths.add(cachedUri);
      }
    }

    return paths;
  }
  @Override
  public PropertySet getPropertySetByURI(Path uri) throws IndexException {
    PropertySet propSet = null;

    try {
      List<Document> docs =
          lookupDocs(new Term(ResourceFields.URI_FIELD_NAME, uri.toString()), null);
      if (docs.size() > 0) {
        Document doc = docs.get(0); // Just pick first in case of duplicates
        propSet = mapper.getPropertySet(doc);
      }
    } catch (IOException io) {
      throw new IndexException(io);
    }

    return propSet;
  }
  @Override
  public int countInstances(Path uri) throws IndexException {

    Term term = new Term(ResourceFields.URI_FIELD_NAME, uri.toString());
    try {
      List<Document> docs =
          lookupDocs(
              term,
              new LoadFieldCallback() {
                @Override
                public boolean loadField(String fieldName) {
                  return false;
                }
              });
      return docs.size();
    } catch (IOException io) {
      throw new IndexException(io);
    }
  }
Example #6
0
  @Test
  public void appendCopySuffix() {
    Path original = Path.fromString("/lala.html");

    Path firstCopy = copyHelper.appendCopySuffix(original, 1);
    assertEquals(firstCopy, Path.fromString("/lala(1).html"));

    Path secondCopy = copyHelper.appendCopySuffix(firstCopy, 1);
    assertEquals(secondCopy, Path.fromString("/lala(2).html"));

    Path thirdCopy = copyHelper.appendCopySuffix(secondCopy, 1);
    assertEquals(thirdCopy, Path.fromString("/lala(3).html"));

    Path parenthesisName = Path.fromString("/test/te(3)st.xml");
    Path copiedParenthesis = copyHelper.appendCopySuffix(parenthesisName, 3);
    assertEquals(copiedParenthesis, Path.fromString("/test/te(3)st(3).xml"));

    Path copyToDoubleDigit = Path.fromString("/foo(9).html");
    Path firstToDoubleDigitCopy = copyHelper.appendCopySuffix(copyToDoubleDigit, 1);
    assertEquals(firstToDoubleDigitCopy, Path.fromString("/foo(10).html"));
  }
Example #7
0
    public synchronized void remove(final Path uri, boolean removeDescendants) {
      Item item = this.map.remove(uri);
      if (item != null) {
        // Something was actually removed
        --this.size;
        removeFromEvictionQueue(item);
      }

      if (removeDescendants) {
        for (Iterator<Map.Entry<Path, Item>> iter = this.map.entrySet().iterator();
            iter.hasNext(); ) {
          Map.Entry<Path, Item> entry = iter.next();

          if (uri.isAncestorOf(entry.getKey())) {
            removeFromEvictionQueue(entry.getValue());
            iter.remove();
            --this.size;
          }
        }
      }
    }
  @Override
  public PropertySetInternalData getPropertySetInternalData(final Path uri) throws IndexException {

    try {
      LoadFieldCallback lfc =
          new LoadFieldCallback() {
            @Override
            public boolean loadField(String fieldName) {
              if (ResourceFields.URI_FIELD_NAME.equals(fieldName)
                  || ResourceFields.RESOURCETYPE_FIELD_NAME.equals(fieldName)
                  || ResourceFields.ID_FIELD_NAME.equals(fieldName)) {
                return true;
              }
              if (fieldName.startsWith(AclFields.ACL_FIELD_PREFIX)) {
                return true;
              }

              return false;
            }
          };

      List<Document> docs =
          lookupDocs(new Term(ResourceFields.URI_FIELD_NAME, uri.toString()), lfc);
      if (docs.isEmpty()) return null;

      Document doc = docs.get(0); // Just pick first in case of duplicates
      final String rt = doc.get(ResourceFields.RESOURCETYPE_FIELD_NAME);
      final int id = ResourceFields.getResourceId(doc);
      final int aclInheritedFrom = AclFields.aclInheritedFrom(doc);
      final Acl acl = mapper.getAclFields().fromDocument(doc);

      return new PropertySetInternalData() {
        @Override
        public Path getURI() {
          return uri;
        }

        @Override
        public String getResourceType() {
          return rt;
        }

        @Override
        public int getResourceId() {
          return id;
        }

        @Override
        public int getAclInheritedFromId() {
          return aclInheritedFrom;
        }

        @Override
        public Acl getAcl() {
          return acl;
        }
      };
    } catch (IOException io) {
      throw new IndexException(io);
    }
  }