Package ch.entwine.weblounge.common.content

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


      logger.warn("Attempt to publish 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 work page exist?
    Page workPage = null;
    try {
      if (!contentRepository.existsInAnyVersion(workURI))
        throw new WebApplicationException(Status.NOT_FOUND);
      workPage = (Page) contentRepository.get(workURI);
      if (workPage == null)
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      workURI.setPath(workPage.getURI().getPath());
    } catch (ContentRepositoryException e) {
      logger.warn("Error looking up page {} from repository: {}", workURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }

    // Check the value of the If-Match header against the etag
    if (ifMatchHeader != null) {
      String etag = ResourceUtils.getETagValue(workPage);
      if (!etag.equals(ifMatchHeader)) {
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      }
    }

    // Make sure the page does not contain references to resources that don't
    // exist anymore.
    logger.debug("Checking referenced resources on {}", workPage);
    try {
      for (Pagelet pagelet : workPage.getPagelets()) {
        String resourceId = pagelet.getProperty("resourceid");
        if (StringUtils.isEmpty(resourceId))
          continue;
        ResourceURI resourceURI = contentRepository.getResourceURI(resourceId);
        if (resourceURI == null) {
          logger.warn("Page {} references non existing resource '{}'", workPage, resourceId);
          throw new WebApplicationException(Status.PRECONDITION_FAILED);
        }
        resourceURI.setVersion(Resource.LIVE);
        if (!contentRepository.exists(resourceURI)) {
          logger.warn("Page {} references unpublished resource '{}'", workPage, resourceURI);
          throw new WebApplicationException(Status.PRECONDITION_FAILED);
        }
      }
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 liveURI = new PageURIImpl(site, null, pageId, Resource.LIVE);

    // Does the page exist?
    Page livePage = null;
    try {
      if (!contentRepository.existsInAnyVersion(liveURI))
        throw new WebApplicationException(Status.NOT_FOUND);
      livePage = (Page) contentRepository.get(liveURI);
      if (livePage == null)
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      liveURI.setPath(livePage.getURI().getPath());
    } catch (ContentRepositoryException e) {
      logger.warn("Error lookup up page {} from repository: {}", liveURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    } catch (IllegalStateException e) {
      logger.warn("Error unpublishing page {}: {}", liveURI, e.getMessage());
      throw new WebApplicationException(Status.PRECONDITION_FAILED);
    }

    // Check the value of the If-Match header against the etag
    if (ifMatchHeader != null) {
      String etag = ResourceUtils.getETagValue(livePage);
      if (!etag.equals(ifMatchHeader)) {
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      }
    }

    // Get the user
    User user = securityService.getUser();
    if (user == null)
      throw new WebApplicationException(Status.UNAUTHORIZED);

    // Make sure the user has publishing rights
    if (!SecurityUtils.userHasRole(user, SystemRole.PUBLISHER))
      throw new WebApplicationException(Status.UNAUTHORIZED);

    boolean isAdmin = SecurityUtils.userHasRole(user, SystemRole.SITEADMIN);

    // If the page is locked by a different user, refuse
    if (livePage.isLocked() && (!livePage.getLockOwner().equals(user) && !isAdmin)) {
      return Response.status(Status.FORBIDDEN).build();
    }

    // Finally, perform the unpublish operation, including saving the current
    // live version of the page as the new work version.
    try {
      contentRepository.delete(liveURI);
      ResourceURI workURI = new ResourceURIImpl(liveURI, Resource.WORK);
      if (!contentRepository.exists(workURI)) {
        logger.debug("Creating work version of {}", workURI);
        PageReader reader = new PageReader();
        Page workPage = reader.read(IOUtils.toInputStream(livePage.toXml(), "utf-8"), site);
        workPage.setVersion(Resource.WORK);
View Full Code Here

    SearchResult result = null;
    Page pageByPath = null;
    try {
      if (q.getVersion() == Resource.WORK && q.getPath() != null) {
        ResourceURI uri = new PageURIImpl(q.getSite(), q.getPath(), q.getVersion());
        pageByPath = (Page) repository.get(uri);
        int count = pageByPath != null ? 1 : 0;
        result = new SearchResultImpl(q, count, count);
      } else {
        result = repository.find(q);
View Full Code Here

    ResourceContent content = resource.getContent(language);
    if (content == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    ResourceURI uri = resource.getURI();
    Site site = getSite(request);

    // Get the current user
    User user = securityService.getUser();
    if (user == null)
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 resourceURI = null;

    // Does the resource exist?
    try {
      resourceURI = contentRepository.getResourceURI(resourceId);
      if (resourceURI == null) {
        throw new WebApplicationException(Status.NOT_FOUND);
      }
    } catch (ContentRepositoryException e) {
      logger.warn("Error lookup up resource {} from repository: {}", resourceURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }

    Resource<?> currentResource;
    try {
      currentResource = contentRepository.get(resourceURI);
    } catch (ContentRepositoryException e) {
      logger.warn("Error reading current resource {} from repository: {}", resourceURI, e.getMessage());
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }

    // Check the value of the If-Match header against the etag
    if (ifMatchHeader != null) {
      String etag = Long.toString(ResourceUtils.getModificationDate(currentResource).getTime());
      if (!etag.equals(ifMatchHeader)) {
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      }
    }

    // Get the current user
    User user = securityService.getUser();
    if (user == null)
      throw new WebApplicationException(Status.UNAUTHORIZED);

    // Make sure the user has editing rights
    if (!SecurityUtils.userHasRole(user, SystemRole.EDITOR))
      throw new WebApplicationException(Status.UNAUTHORIZED);

    // Parse the resource and update it in the repository
    Resource<?> resource = null;
    // TOOD: Extract resource type
    String resourceType = resourceURI.getType();
    try {
      ResourceSerializer<?, ?> serializer = serializerService.getSerializerByType(resourceType);
      ResourceReader<?, ?> resourceReader = serializer.getReader();
      resource = resourceReader.read(IOUtils.toInputStream(resourceXml, "utf-8"), site);
      resource.setModified(user, new Date());
View Full Code Here

    // Make sure the user has editing rights
    if (!SecurityUtils.userHasRole(user, SystemRole.EDITOR))
      throw new WebApplicationException(Status.UNAUTHORIZED);

    ResourceURI resourceURI = null;

    // Make sure the resource exists
    try {
      resourceURI = contentRepository.getResourceURI(resourceId);
      if (resourceURI == null) {
View Full Code Here

      // Create the resource uri
      URI uri = null;
      InputStream is = null;
      Resource<?> resource = null;
      ResourceURI resourceURI = null;
      logger.debug("Adding resource to {}", resourceURI);
      ResourceSerializer<?, ?> serializer = serializerService.getSerializerByMimeType(mimeType);
      if (serializer == null) {
        logger.debug("No specialized resource serializer found, using regular file serializer");
        serializer = serializerService.getSerializerByType(FileResource.TYPE);
      }

      // Create the resource
      try {
        is = new FileInputStream(uploadedFile);
        resource = serializer.newResource(site, is, user, language);
        resourceURI = resource.getURI();
      } catch (FileNotFoundException e) {
        logger.warn("Error creating resource at {} from image: {}", uri, e.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
      } finally {
        IOUtils.closeQuietly(is);
      }

      // If a path has been specified, set it
      if (path != null && StringUtils.isNotBlank(path)) {
        try {
          if (!path.startsWith("/"))
            path = "/" + path;
          WebUrl url = new WebUrlImpl(site, path);
          resourceURI.setPath(url.getPath());

          // Make sure the resource doesn't exist
          if (contentRepository.exists(new GeneralResourceURIImpl(site, url.getPath()))) {
            logger.warn("Tried to create already existing resource {} in site '{}'", resourceURI, site);
            throw new WebApplicationException(Status.CONFLICT);
          }
        } catch (IllegalArgumentException e) {
          logger.warn("Tried to create a resource with an invalid path '{}': {}", path, e.getMessage());
          throw new WebApplicationException(Status.BAD_REQUEST);
        } catch (ContentRepositoryException e) {
          logger.warn("Resource lookup {} failed for site '{}'", resourceURI, site);
          throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
        }
      }

      // Store the new resource
      try {
        uri = new URI(resourceURI.getIdentifier());
        contentRepository.put(resource, true);
      } catch (URISyntaxException e) {
        logger.warn("Error creating a uri for resource {}: {}", resourceURI, e.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
      } catch (IOException e) {
View Full Code Here

      throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
    }

    // Load the resource and return it
    try {
      ResourceURI resourceURI = new ResourceURIImpl(resourceType, site, null, resourceId, version);
      Resource<?> resource = contentRepository.get(resourceURI);
      if (resource == null)
        return null;
      if (resourceType != null && !resourceType.equals(resource.getURI().getType())) {
        return null;
View Full Code Here

      throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
    }

    // Load the resource and return it
    try {
      ResourceURI resourceURI = new ResourceURIImpl(resourceType, site, resourcePath);
      Resource<?> resource = contentRepository.get(resourceURI);
      if (resource == null)
        return null;
      if (resourceType != null && !resourceType.equals(resource.getURI().getType())) {
        return null;
View Full Code Here

            if (f.isDirectory()) {
              u.push(f);
            } else {
              long version = Long.parseLong(f.getParentFile().getName());
              String id = f.getParentFile().getParentFile().getName();
              ResourceURI uri = new ResourceURIImpl(resourceType, getSite(), null, id, version);

              uris.add(uri);
            }
          }
        }
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.