Package ch.entwine.weblounge.common.repository

Examples of ch.entwine.weblounge.common.repository.ContentRepository


    SearchQuery q = new SearchQueryImpl(site);
    q.withTypes(Page.TYPE);
    q.withVersion(Resource.LIVE);
    q.withProperty("resourceid", pageId);

    ContentRepository repository = getContentRepository(site, false);
    SearchResult result = null;
    try {
      result = repository.find(q);
    } catch (ContentRepositoryException e) {
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }

    StringBuffer buf = new StringBuffer("<pages>");
View Full Code Here


   *           if the content repository is unavailable or if the content can't
   *           be loaded
   */
  private String loadResultSet(SearchQuery q, boolean details)
      throws WebApplicationException {
    ContentRepository repository = getContentRepository(q.getSite(), false);
    if (repository == null)
      throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);

    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);
      }
    } catch (ContentRepositoryException e) {
      throw new WebApplicationException(e);
    }

View Full Code Here

    } else if (!site.isOnline()) {
      return Response.status(Status.SERVICE_UNAVAILABLE).build();
    }

    // Load the content repository
    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
      return Response.status(Status.SERVICE_UNAVAILABLE).build();
    }

    // Create the search expression and the query
    SearchQuery query = new SearchQueryImpl(site);
    try {
      query.withFulltext(true, URLDecoder.decode(terms, "utf-8"));
      query.withVersion(Resource.LIVE);
      query.withOffset(offset);
      query.withLimit(limit);
    } catch (UnsupportedEncodingException e) {
      throw new WebApplicationException(e);
    }

    // Return the result
    try {
      SearchResult result = repository.find(query);
      return Response.ok(result.toXml()).build();
    } catch (ContentRepositoryException e) {
      logger.error("Error trying to access the content repository", e);
      throw new WebApplicationException(e);
    }
View Full Code Here

    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);
    if (previewGenerator == null)
      throw new WebApplicationException(Status.NOT_FOUND);

    // Load the resource contents from the repository
    InputStream resourceInputStream = null;
    long contentLength = -1;

    // Load the input stream from the scaled image
    InputStream contentRepositoryIs = null;
    FileOutputStream fos = null;
    try {
      long resourceLastModified = ResourceUtils.getModificationDate(resource, language).getTime();
      if (!scaledResourceFile.isFile() || scaledResourceFile.lastModified() < resourceLastModified) {
        if (!force)
          throw new WebApplicationException(Response.Status.NOT_FOUND);

        contentRepositoryIs = contentRepository.getContent(resourceURI, language);
        scaledResourceFile = ImageStyleUtils.createScaledFile(resource, language, style);
        scaledResourceFile.setLastModified(Math.max(new Date().getTime(), resourceLastModified));
        fos = new FileOutputStream(scaledResourceFile);
        logger.debug("Creating scaled image '{}' at {}", resource, scaledResourceFile);
View Full Code Here

   */
  @POST
  @Path("/")
  public Response createPreviews(@Context HttpServletRequest request) {
    Site site = super.getSite(request);
    final ContentRepository contentRepository = getContentRepository(site, false);
    new Thread(new Runnable() {
      public void run() {
        try {
          contentRepository.createPreviews();
        } catch (ContentRepositoryException e) {
          logger.warn("Preview generation returned with an error: {}", e.getMessage());
        }
      }
    }).start();
View Full Code Here

        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 {
      versions = contentRepository.getVersions(resourceURI);
    } catch (ContentRepositoryException e1) {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }

    // Remove the preview for all versions in the specified styles and languages
View Full Code Here

        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
      }
    }

    Site site = getSite(request);
    final ContentRepository contentRepository = getContentRepository(site, false);

    // Create the response
    final InputStream is;
    try {
      is = contentRepository.getContent(resource.getURI(), language);
    } catch (IOException e) {
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    } catch (ContentRepositoryException e) {
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
View Full Code Here

    // Extract the site
    Site site = getSite(request);

    // Look for the content repository
    ContentRepository contentRepository = site.getContentRepository();
    if (contentRepository == null) {
      logger.warn("No content repository found for site '{}'", site);
      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

    // Extract the site
    Site site = getSite(request);

    // Look for the content repository
    ContentRepository contentRepository = site.getContentRepository();
    if (contentRepository == null) {
      logger.warn("No content repository found for site '{}'", site);
      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

   * @throws WebApplicationException
   *           if the repository can't be located or if it's not writable
   */
  protected ContentRepository getContentRepository(Site site, boolean writable) {
    try {
      ContentRepository contentRepository = site.getContentRepository();

      // Make sure the content repository is ready to use
      if (contentRepository == null) {
        logger.debug("No content repository found for site '{}'", site);
        throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
      } else if (contentRepository.isIndexing()) {
        logger.debug("Content repository is being indexed '{}'", site);
        throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
      }

      // Is the client asking for a writable repository?
      if (writable) {
        if (contentRepository.isReadOnly()) {
          logger.warn("Content repository '{}' is not writable", site);
          throw new WebApplicationException(Status.PRECONDITION_FAILED);
        }
        WritableContentRepository wcr = (WritableContentRepository) contentRepository;
        return wcr;
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.repository.ContentRepository

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.