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

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


      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 || composer.size() < pageletIndex) {
      return Response.status(Status.NOT_FOUND).build();
    }

    // Return the pagelet
View Full Code Here


    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();
        Page livePage = (Page) contentRepository.get(liveURI);
        workPage = reader.read(IOUtils.toInputStream(livePage.toXml(), "utf-8"), site);
        workPage.setVersion(Resource.WORK);
        contentRepository.putAsynchronously(workPage, false);
      } else {
        workURI.setPath(workPage.getURI().getPath());
      }
View Full Code Here

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

    // Check the value of the If-Match header against the etag
    if (ifMatchHeader != null) {
      String etag = ResourceUtils.getETagValue(page);
      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 (page.isLocked() && (!page.getLockOwner().equals(user) && !isAdmin)) {
      return Response.status(Status.FORBIDDEN).build();
    }

    // Finally, perform the lock operation (on all resource versions)
    try {
View Full Code Here

    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);
        }
      }
    } catch (ContentRepositoryException e) {
      logger.warn("Error looking up referenced resources", e);
      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 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 (workPage.isLocked() && (!workPage.getLockOwner().equals(user) && !isAdmin)) {
      return Response.status(Status.FORBIDDEN).build();
    }

    // Fix the dates
    Date startDate = null;
    Date endDate = null;
    DateFormat df = new SimpleDateFormat();

    // Parse the start date
    if (StringUtils.isNotBlank(startDateText)) {
      try {
        startDate = df.parse(startDateText);
      } catch (ParseException e) {
        try {
          startDate = WebloungeDateFormat.parseStatic(startDateText);
        } catch (ParseException e2) {
          throw new WebApplicationException(Status.BAD_REQUEST);
        }
      }
    } else {
      startDate = new Date();
    }

    // Parse the end date
    if (StringUtils.isNotBlank(endDateText)) {
      try {
        endDate = df.parse(endDateText);
      } catch (ParseException e) {
        try {
          endDate = WebloungeDateFormat.parseStatic(endDateText);
        } catch (ParseException e2) {
          throw new WebApplicationException(Status.BAD_REQUEST);
        }
      }
    }

    // Finally, perform the publish operation
    try {
      PageReader reader = new PageReader();
      Page livePage = reader.read(IOUtils.toInputStream(workPage.toXml(), "utf-8"), site);
      livePage.setVersion(Resource.LIVE);
      if (setModified)
        livePage.setModified(user, new Date());
      if (!livePage.isPublished())
        livePage.setPublished(user, startDate, endDate);
      contentRepository.putAsynchronously(livePage);
      contentRepository.deleteAsynchronously(workURI);
      logger.info("Page {} has been published by {}", workURI, user);
    } catch (SecurityException e) {
      logger.warn("Tried to publish page {} of site '{}' without permission", workURI, site);
View Full Code Here

    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);
        workPage.setPublished(null, null, null);
        contentRepository.putAsynchronously(workPage);
      }
      logger.info("Page {} has been unpublished by {}", liveURI, user);
    } catch (SecurityException e) {
      logger.warn("Tried to unpublish page {} of site '{}' without permission", liveURI, site);
View Full Code Here

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

    StringBuffer buf = new StringBuffer("<pages ");
    buf.append("hits=\"").append(result.getHitCount()).append("\" ");
    buf.append("offset=\"").append(result.getOffset()).append("\" ");
    if (q.getLimit() > 0)
      buf.append("limit=\"").append(result.getLimit()).append("\" ");
    buf.append("page=\"").append(result.getPage()).append("\" ");
    buf.append("pagesize=\"").append(result.getPageSize()).append("\"");
    buf.append(">");
    if (pageByPath != null) {
      String xml = pageByPath.toXml();
      if (!details) {
        xml = xml.replaceAll("<body>.*</body>", "");
        xml = xml.replaceAll("<body/>", "");
      }
      buf.append(xml);
View Full Code Here

    for (ResourceMetadata<?> metadataItem : metadata) {
      if (XML.equals(metadataItem.getName())) {
        String resourceXml = (String) metadataItem.getValues().get(0);
        try {
          ResourceReader<ResourceContent, Page> reader = getReader();
          Page page = reader.read(IOUtils.toInputStream(resourceXml, "UTF-8"), site);
          return page;
        } catch (SAXException e) {
          logger.warn("Error parsing page from metadata", e);
          return null;
        } catch (IOException e) {
View Full Code Here

      ContentRepositoryException {
    // Make sure there is a home page
    ResourceURI homeURI = new ResourceURIImpl(Page.TYPE, site, "/");
    if (!existsInAnyVersion(homeURI)) {
      try {
        Page page = new PageImpl(homeURI);
        User siteAdmininstrator = new UserImpl(site.getAdministrator());
        page.setTemplate(site.getDefaultTemplate().getIdentifier());
        page.setCreated(siteAdmininstrator, new Date());
        page.setPublished(siteAdmininstrator, new Date(), null);
        put(page, true);
        logger.info("Created homepage for {}", site.getIdentifier());
      } catch (IOException e) {
        logger.warn("Error creating home page in empty site '{}': {}", site.getIdentifier(), e.getMessage());
      }
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.