Package ch.entwine.weblounge.common.content.page

Examples of ch.entwine.weblounge.common.content.page.Page


  /**
   * Test method for {@link ch.entwine.weblounge.common.impl.content.page.PageImpl#compareTo(ch.entwine.weblounge.common.language.Localizable, ch.entwine.weblounge.common.language.Language)}.
   */
  @Test
  public void testCompareTo() {
    Page p2 = new PageImpl(new PageURIImpl(site, "/test/2", Resource.LIVE));
    p2.setTitle(germanTitle, german);
    assertEquals(0, page.compareTo(p2, german));
  }
View Full Code Here


  public void testGetRevisions() {
    ResourceURI uri1 = new PageURIImpl(site, "/weblounge");
    ResourceURI uri2Live = new PageURIImpl(site, "/etc/weblounge");
    ResourceURI uri2Work = new PageURIImpl(site, "/etc/weblounge", Resource.WORK);

    Page page1 = new PageImpl(uri1);
    page1.setTemplate(template.getIdentifier());

    Page page2Live = new PageImpl(uri2Live);
    page2Live.setTemplate(template.getIdentifier());

    Page page2Work = new PageImpl(uri2Work);
    page2Work.setTemplate(template.getIdentifier());

    try {
      idx.add(page1);
      idx.add(page2Live);
      idx.add(page2Work);
View Full Code Here

        b.append(UUID.randomUUID().toString());
        b.append("/");
      }
      String path = b.toString();
      String id = UUID.randomUUID().toString();
      Page p = new PageImpl(new PageURIImpl(site, path, id));
      p.setTemplate("home");
      p.setTitle("title", english);
      pages.add(p);
      ResourceURI uri = idx.add(p);
      assertEquals(id, uri.getIdentifier());
      assertEquals(path, uri.getPath());
      assertEquals(i + 1, idx.getResourceCount());
    }

    // Test if everything can be found
    for (Page p : pages) {
      assertTrue(idx.exists(p.getURI()));
      assertEquals(p.getURI().getIdentifier(), idx.getIdentifier(p.getURI()));
      assertEquals(p.getURI().getPath(), idx.getPath(p.getURI()));
      assertEquals(1, idx.getRevisions(p.getURI()).length);
    }

  }
View Full Code Here

    // Add 10 sub pages
    for (int i = 0; i < 10; i++) {
      String id = UUID.randomUUID().toString();
      String path = PathUtils.concat(path1, id);
      ResourceURI uri = new PageURIImpl(site, path, id);
      Page p = new PageImpl(uri);
      p.setTemplate(template.getIdentifier());
      idx.add(p);

      String subPageId = UUID.randomUUID().toString();
      String subPath = PathUtils.concat(path, subPageId);
      uri = new PageURIImpl(site, subPath, subPageId);
      p = new PageImpl(uri);
      p.setTemplate(template.getIdentifier());
      idx.add(p);
    }

    SearchQuery q = new SearchQueryImpl(site).withTypes(Page.TYPE).withPathPrefix(path1);
    q.withLimit(100);
View Full Code Here

   */
  @Test
  public void testUpdate() throws Exception {
    populateIndex();
    String subject = "testsubject";
    Page page = pages[0];
    page.addSubject(subject);

    // Post the update
    idx.update(page);

    // Check if the index actually reflects the updated data
View Full Code Here

    if ("docs".equals(pageId)) {
      return Response.ok(getDocumentation(request)).type(MediaType.TEXT_HTML).build();
    }

    // Load the page
    Page page = (Page) loadResource(request, pageId, Page.TYPE, version);
    if (page == null) {
      return Response.status(Status.NOT_FOUND).build();
    }

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

    // Create the response
    ResponseBuilder response = Response.ok(page.toXml());
    response.tag(ResourceUtils.getETagValue(page));
    response.lastModified(ResourceUtils.getModificationDate(page));
    return response.build();
  }
View Full Code Here

    // Check the parameters
    if (pageId == null)
      return Response.status(Status.BAD_REQUEST).build();

    // Load the page
    Page page = (Page) loadResource(request, pageId, Page.TYPE);
    if (page == null) {
      return Response.status(Status.NOT_FOUND).build();
    }

    Site site = getSite(request);
    SearchQuery q = new SearchQueryImpl(site);
    q.withVersion(Resource.LIVE);
    q.withTypes(Page.TYPE);
    q.withPathPrefix(page.getURI().getPath());

    ContentRepository repository = getContentRepository(site, false);
    SearchResult result = null;
    try {
      result = repository.find(q);
View Full Code Here

    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);
    }

    // Check the value of the If-Match header against the etag
    if (ifMatchHeader != null) {
      String etag = ResourceUtils.getETagValue(currentPage);
      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 editing rights
    if (!SecurityUtils.userHasRole(user, SystemRole.EDITOR))
      throw new WebApplicationException(Status.UNAUTHORIZED);

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

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

    // Parse the page and update it in the repository
    Page page = null;
    try {
      PageReader pageReader = new PageReader();
      page = pageReader.read(IOUtils.toInputStream(pageXml, "utf-8"), site);
      if (StringUtils.isBlank(page.getURI().getPath()))
        throw new WebApplicationException(Status.PRECONDITION_FAILED);
      page.setModified(user, new Date());
      page.setVersion(Resource.WORK);

      // TODO: Preview generation disabled due to performance problems
      contentRepository.putAsynchronously(page, false);

      // Check if the page has been moved
      String currentPath = currentPage.getURI().getPath();
      String newPath = page.getURI().getPath();
      if ((currentPath != null && !currentPath.equals(newPath) || (currentPath == null && newPath != null))) {
        contentRepository.moveAsynchronously(currentPage.getURI(), newPath, true);
      }
    } catch (SecurityException e) {
      logger.warn("Tried to update page {} of site '{}' without permission", workURI, site);
View Full Code Here

    } 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);
    }

    // Get the 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);

    // If the page is published, the user needs publishing rights
    if (page.isPublished() && !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 (page.isLocked() && (!page.getLockOwner().equals(user) && !isAdmin)) {
      return Response.status(Status.FORBIDDEN).build();
    }

    // Delete the page
    try {
      contentRepository.delete(page.getURI(), true);
    } catch (SecurityException e) {
      logger.warn("Tried to delete page {} of site '{}' without permission", livePageURI, site);
      throw new WebApplicationException(Status.FORBIDDEN);
    } catch (ReferentialIntegrityException e) {
      logger.warn("Tried to delete referenced page {} of site '{}'", livePageURI, site);
View Full Code Here

      return Response.status(Status.BAD_REQUEST).build();
    else if (composerId == null)
      return Response.status(Status.BAD_REQUEST).build();

    // Load the page
    Page page = (Page) loadResource(request, pageId, Page.TYPE, version);
    if (page == null) {
      return Response.status(Status.NOT_FOUND).build();
    }

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

    // Load the composer
    Composer composer = page.getComposer(composerId);
    if (composer == null) {
      return Response.status(Status.NOT_FOUND).build();
    }

    // Return the composer
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.page.Page

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.