Package ch.entwine.weblounge.common.content

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


  @Before
  public void setUp() throws Exception {
    setUpPrerequisites();
    metadata = new ArrayList<ResourceMetadata<?>>();
    pageXml = IOUtils.toString(getClass().getResourceAsStream("/page.xml"));
    ResourceURI uri = new PageURIImpl(site, path, id, Resource.LIVE);
    pageItem = new PageSearchResultItemImpl(uri, url, relevance, source, metadata);
    item = pageItem;
    item.setTitle(title);
    item.setPreview(previewData);
    item.setPreviewRenderer(renderer);
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();
View Full Code Here

    // initial bundle contents to the filesystem. Otherwise, keep working with
    // what's there already.
    logger.info("Loading resources for '{}' from bundle '{}'", site, bundle.getSymbolicName());
    try {
      for (Iterator<ResourceURI> pi = getResourceURIsFromBundle(); pi.hasNext();) {
        ResourceURI uri = pi.next();

        try {
          Resource<?> resource = loadResourceFromBundle(uri);
          if (resource == null) {
            throw new ContentRepositoryException("Unable to load " + uri.getType() + " " + uri + " from bundle");
          }

          // Update the uri, it now contains the id in addition to just the path
          uri = resource.getURI();

          // Make sure we are not updating existing resources, since this is the
          // first time import.
          if (exists(uri)) {
            throw new ContentRepositoryException("Error adding resource " + uri + " to repository: a resource with id '" + uri.getIdentifier() + "' or path '" + uri.getPath() + "' already exists");
          }

          logger.info("Loading {} {}:{}", new Object[] {
              uri.getType(),
              site,
              uri });
          Set<? extends ResourceContent> content = resource.contents();
          if (content.size() == 0) {
            put(resource);
          } else {
            for (ResourceContent c : content)
              resource.removeContent(c.getLanguage());
            put(resource);
            for (ResourceContent c : content) {
              InputStream is = null;
              try {
                is = loadResourceContentFromBundle(uri, c);
                if (is == null && c.getExternalLocation() == null)
                  throw new ContentRepositoryException("Resource content " + c + " missing from repository");
                putContent(uri, c, is);
              } finally {
                IOUtils.closeQuietly(is);
              }
            }
          }
        } catch (IOException e) {
          logger.error("Error reading " + uri.getType() + " " + uri + ": " + e.getMessage(), e);
          throw new ContentRepositoryException(e);
        }
      }
    } catch (ContentRepositoryException e) {
      cleanupAfterFailure();
View Full Code Here

        while (entries.hasMoreElements()) {
          URL entry = entries.nextElement();
          String path = FilenameUtils.getPath(entry.getPath());
          path = path.substring(resourcePathPrefix.length() - 1);
          long v = ResourceUtils.getVersion(FilenameUtils.getBaseName(entry.getPath()));
          ResourceURI resourceURI = new ResourceURIImpl(serializer.getType(), site, path, v);
          resourceURIs.add(resourceURI);
          logger.trace("Found revision '{}' of {} {}", new Object[] {
              v,
              resourceURI.getType(),
              entry });
        }
      }
    }
View Full Code Here

   *           if adding to the index fails
   */
  public synchronized ResourceURI add(Resource<?> resource) throws IOException,
      ContentRepositoryException {

    ResourceURI uri = resource.getURI();
    String id = uri.getIdentifier();
    String path = StringUtils.trimToNull(uri.getPath());
    long version = uri.getVersion();

    // Make sure we are not asked to add a resource to the index that has the
    // same id as an existing one
    if (id != null) {
      SearchQuery q = new SearchQueryImpl(site).withIdentifier(id).withPreferredVersion(version).withLimit(1).withField(PATH);
      SearchResultItem[] items = searchIdx.getByQuery(q).getItems();
      if (items.length > 0) {
        long versionInIndex = (Long) ((ResourceSearchResultItem) items[0]).getMetadataByKey(VERSION).getValue();
        if (items.length == 1 && versionInIndex == version)
          throw new ContentRepositoryException("Resource '" + id + "' already exists in version " + version);
        if (path == null) {
          path = (String) ((ResourceSearchResultItem) items[0]).getMetadataByKey(PATH).getValue();
          resource.getURI().setPath(path);
        }
      }
    }

    // Make sure we are not asked to add a resource to the index that has the
    // same path as an existing one
    if (path != null) {
      SearchQuery q = new SearchQueryImpl(site).withPath(path).withPreferredVersion(version).withLimit(1).withField(RESOURCE_ID);
      SearchResultItem[] items = searchIdx.getByQuery(q).getItems();
      if (items.length > 0) {
        long versionInIndex = (Long) ((ResourceSearchResultItem) items[0]).getMetadataByKey(VERSION).getValue();
        if (items.length == 1 && versionInIndex == version)
          throw new ContentRepositoryException("Resource '" + id + "' already exists in version " + version);
        if (id == null) {
          id = (String) ((ResourceSearchResultItem) items[0]).getMetadataByKey(RESOURCE_ID).getValue();
          resource.getURI().setIdentifier(id);
        }
      }
    }

    // Create an id if necessary. A missing id indicates that the resource
    // has never been added to the index before
    if (id == null) {
      id = UUID.randomUUID().toString();
      resource.setIdentifier(id);
      uri.setIdentifier(id);
    }

    try {
      searchIdx.add(resource);
    } catch (ContentRepositoryException e) {
View Full Code Here

   * @throws ContentRepositoryException
   *           if updating the index fails
   */
  public synchronized void update(Resource<?> resource) throws IOException,
      ContentRepositoryException {
    ResourceURI uri = resource.getURI();

    // Make sure the uri has an identifier
    if (uri.getIdentifier() == null) {
      uri.setIdentifier(getIdentifier(uri));
    }

    searchIdx.update(resource);
  }
View Full Code Here

   */
  public synchronized void move(ResourceURI uri, String path)
      throws IOException, ContentRepositoryException, IllegalStateException {

    // Do it this way to make sure we have identical path trimming
    ResourceURI newURI = new ResourceURIImpl(uri.getType(), uri.getSite(), StringUtils.trimToNull(path), uri.getIdentifier(), uri.getVersion());
    path = newURI.getPath();

    searchIdx.move(uri, path);
  }
View Full Code Here

    } else {
      path = URI_PREFIX + "/" + id;
      url = new WebUrlImpl(site, path);
    }

    ResourceURI uri = new FileResourceURIImpl(site, path, id, version);
    FileResourceSearchResultItemImpl result = new FileResourceSearchResultItemImpl(uri, url, relevance, site, metadata);

    if (metadataMap.get(XML) != null)
      result.setFileXml((String) metadataMap.get(XML).getValues().get(0));
    if (metadataMap.get(HEADER_XML) != null)
View Full Code Here

      Enumeration<URL> entries = bundle.findEntries(prefix, "*.xml", true);
      if (entries != null) {
        while (entries.hasMoreElements()) {
          URL entry = entries.nextElement();

          ResourceURI uri = loadResourceURI(getSite(), entry);
          if (uri == null)
            throw new IllegalStateException("Resource " + entry + " has no uri");

          uris.add(uri);
        }
View Full Code Here

    try {
      logger.info("Populating temporary site index '{}'", site);
      long time = System.currentTimeMillis();
      long resourceCount = 0;
      long revisionCount = 0;
      ResourceURI previousURI = null;

      // Add all known resource types to the index
      for (ResourceSerializer<?, ?> serializer : getSerializers()) {
        ResourceSelector selector = new ResourceSelectorImpl(site).withTypes(serializer.getType());
        for (ResourceURI uri : list(selector)) {

          // Load the resource
          Resource<?> resource = null;
          InputStream is = null;
          try {
            ResourceReader<?, ?> reader = serializer.getReader();
            is = loadResource(uri);
            resource = reader.read(is, site);
            if (resource == null) {
              logger.warn("Unkown error loading resource {}", uri);
              continue;
            }
          } catch (Throwable t) {
            logger.error("Error loading resource '{}' from bundle: {}", uri, t.getMessage());
            continue;
          } finally {
            IOUtils.closeQuietly(is);
          }

          // Add it to the index
          index.add(resource);
          revisionCount++;
          if (previousURI != null && !previousURI.getPath().equals(uri.getPath())) {
            logger.info("Adding {}:{} to site index", site, uri.getPath());
            resourceCount++;
          }
          previousURI = 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.