Package ch.entwine.weblounge.common.content

Examples of ch.entwine.weblounge.common.content.ResourceURI


        newPath = targetPath;

      // Move every version of the resource, since we want the path to be
      // in sync across resource versions
      for (long version : index.getRevisions(u)) {
        ResourceURI candidateURI = new ResourceURIImpl(u.getType(), site, null, u.getIdentifier(), version);

        // Load the resource, adjust the path and store it again
        Resource<?> r = get(candidateURI);

        // Store the updated resource
View Full Code Here


    // Check if resource is in temporary cache already by another operation
    if (processor.isProcessing(resource.getURI())) {
      logger.debug("Resource '{}' is being processed, putting anyway", resource.getURI());
    }

    ResourceURI uri = resource.getURI();

    // If the document exists in the given version, update it otherwise add it
    // to the index
    if (index.exists(uri)) {
      index.update(resource);
    } else {
      if (resource.contents().size() > 0)
        throw new IllegalStateException("Cannot add content metadata without content");
      index.add(resource);
    }

    // Make sure related stuff gets thrown out of the cache
    ResponseCache cache = getCache();
    if (cache != null && uri.getVersion() == Resource.LIVE) {
      List<CacheTag> tags = new ArrayList<CacheTag>();

      // resource id
      tags.add(new CacheTagImpl(CacheTag.Resource, uri.getIdentifier()));

      // subjects, so that resource lists get updated
      for (String subject : resource.getSubjects())
        tags.add(new CacheTagImpl(CacheTag.Subject, subject));
View Full Code Here

   *
   * @param resource
   *          the resource
   */
  protected void init(Resource<?> resource) {
    ResourceURI uri = resource.getURI();

    if (uri.getIdentifier() == null)
      throw new IllegalArgumentException("Resource must have an identifier");

    addField(UID, uri.getUID(), false, false);
    addField(RESOURCE_ID, uri.getIdentifier(), true, false);
    addField(PATH, uri.getPath(), true, true);
    addField(TYPE, uri.getType(), true, false);
    addField(VERSION, uri.getVersion(), false, false);

    // Path elements
    if (!StringUtils.isBlank(uri.getPath())) {
      String path = uri.getPath();

      // Index the whole path as prefixes
      StringBuffer prefix = new StringBuffer();
      for (int i = 0; i < path.length(); i++) {
        prefix.append(path.charAt(i));
View Full Code Here

        throw new ContentRepositoryException(e);
      }
    }

    // Have the serializer create an input document
    ResourceURI uri = resource.getURI();
    String resourceType = uri.getType();
    ResourceSerializer<?, ?> serializer = resourceSerializer.getSerializerByType(resourceType);
    if (serializer == null)
      throw new ContentRepositoryException("Unable to create an input document for " + resource + ": no serializer found");

    // Add the resource to the index
View Full Code Here

    // Is there an up-to-date, cached version on the client side?
    if (!ResourceUtils.hasChanged(request, scaledResourceFile)) {
      return Response.notModified().build();
    }

    ResourceURI resourceURI = resource.getURI();
    final ContentRepository contentRepository = getContentRepository(site, false);

    // When there is no scaling required, just return the original
    if (ImageScalingMode.None.equals(style.getScalingMode())) {
      return getResourceContent(request, resource, language);
    }

    // Find a serializer
    ResourceSerializer<?, ?> serializer = serializerService.getSerializerByType(resourceURI.getType());
    if (serializer == null)
      throw new WebApplicationException(Status.PRECONDITION_FAILED);

    // Does the serializer come with a preview generator?
    PreviewGenerator previewGenerator = serializer.getPreviewGenerator(resource);
View Full Code Here

      for (Module m : site.getModules()) {
        removeStyles.addAll(Arrays.asList(m.getImageStyles()));
      }
    }

    ResourceURI resourceURI = resource.getURI();
    final ContentRepository contentRepository = getContentRepository(site, false);

    // Load the resource versions from the repository
    ResourceURI[] versions = null;
    try {
View Full Code Here

      logger.warn("Attempt to write to read-only content repository {}", site);
      throw new WebApplicationException(Status.PRECONDITION_FAILED);
    }

    WritableContentRepository contentRepository = (WritableContentRepository) getContentRepository(site, true);
    ResourceURI workURI = new PageURIImpl(site, null, pageId, Resource.WORK);

    // Does the page exist?
    Page currentPage = null;
    try {
      currentPage = (Page) contentRepository.get(workURI);
      if (currentPage == null) {
        logger.warn("Attempt to update a page without creating a work version first");
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      }
      workURI.setPath(currentPage.getURI().getPath());
    } catch (ContentRepositoryException e) {
      logger.warn("Error lookup up page {} from repository: {}", workURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
View Full Code Here

      return Response.status(Status.BAD_REQUEST).build();

    Site site = getSite(request);
    WritableContentRepository contentRepository = (WritableContentRepository) getContentRepository(site, true);

    ResourceURI livePageURI = new PageURIImpl(site, null, pageId, Resource.LIVE);
    ResourceURI workPageURI = new PageURIImpl(site, null, pageId, Resource.WORK);

    try {
      if (!contentRepository.existsInAnyVersion(livePageURI)) {
        logger.warn("Tried to delete non existing page {} in site '{}'", livePageURI, site);
        throw new WebApplicationException(Status.NOT_FOUND);
      }
    } catch (ContentRepositoryException e) {
      logger.warn("Page lookup {} failed for site '{}'", livePageURI, site);
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }

    Page page = null;
    try {
      page = (Page) contentRepository.get(livePageURI);
      if (page != null) {
        livePageURI.setPath(page.getURI().getPath());
      } else {
        page = (Page) contentRepository.get(workPageURI);
        workPageURI.setPath(page.getURI().getPath());
      }
    } catch (ContentRepositoryException e) {
      logger.warn("Error lookup up page {} from repository: {}", livePageURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
View Full Code Here

      logger.warn("Attempt to lock a page in a read-only content repository {}", site);
      throw new WebApplicationException(Status.PRECONDITION_FAILED);
    }

    WritableContentRepository contentRepository = (WritableContentRepository) getContentRepository(site, true);
    ResourceURI workURI = new PageURIImpl(site, null, pageId, Resource.WORK);

    // Does the page exist at all?
    Page workPage = null;
    try {
      if (!contentRepository.existsInAnyVersion(workURI))
        throw new WebApplicationException(Status.NOT_FOUND);
    } catch (ContentRepositoryException e) {
      logger.warn("Error looking up page {} from repository: {}", workURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }

    // Make sure we have a work page. If it doesn't exist yet, it needs
    // to be created as a result of the lock operation
    ResourceURI liveURI = new PageURIImpl(site, null, pageId, Resource.LIVE);
    try {
      workPage = (Page) contentRepository.get(workURI);
      if (workPage == null) {
        logger.debug("Creating work version of {}", liveURI);
        PageReader reader = new PageReader();
View Full Code Here

      logger.warn("Attempt to unlock a page in a read-only content repository {}", site);
      throw new WebApplicationException(Status.PRECONDITION_FAILED);
    }

    WritableContentRepository contentRepository = (WritableContentRepository) getContentRepository(site, true);
    ResourceURI pageURI = new PageURIImpl(site, null, pageId, Resource.WORK);

    // Does the page exist?
    Page page = null;
    try {
      ResourceURI[] versions = contentRepository.getVersions(pageURI);
      if (versions.length == 0)
        throw new WebApplicationException(Status.NOT_FOUND);
      page = (Page) contentRepository.get(versions[0]);
      if (page == null)
        throw new WebApplicationException(Status.NOT_FOUND);
      pageURI.setPath(page.getURI().getPath());
    } catch (ContentRepositoryException e) {
      logger.warn("Error lookup up page {} from repository: {}", pageURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.ResourceURI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.