コード例 #1
0
 protected String getParentFormName() {
   final AVMService avmService = this.getServiceRegistry().getAVMService();
   return avmService
       .getNodeProperty(
           AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
           AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
           WCMAppModel.PROP_PARENT_FORM_NAME)
       .getStringValue();
 }
コード例 #2
0
 public List<Rendition> getRenditions(boolean includeDeleted) {
   final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService();
   final PropertyValue pv =
       avmService.getNodeProperty(-1, this.getPath(), WCMAppModel.PROP_RENDITIONS);
   final Collection<Serializable> renditionPaths =
       (pv == null ? Collections.EMPTY_LIST : pv.getCollection(DataTypeDefinition.TEXT));
   final String storeName = AVMUtil.getStoreName(this.getPath());
   final List<Rendition> result = new ArrayList<Rendition>(renditionPaths.size());
   for (Serializable path : renditionPaths) {
     String avmRenditionPath = AVMUtil.buildAVMPath(storeName, (String) path);
     if (avmService.lookup(-1, avmRenditionPath, includeDeleted) == null) {
       if (logger.isDebugEnabled()) {
         logger.debug("ignoring dangling rendition at: " + avmRenditionPath);
       }
     } else {
       final Rendition r = new RenditionImpl(-1, avmRenditionPath, this.getFormsService());
       try {
         if (!this.equals(r.getPrimaryFormInstanceData(includeDeleted))) {
           if (logger.isDebugEnabled()) {
             logger.debug(
                 "rendition "
                     + r
                     + " points at form instance data "
                     + r.getPrimaryFormInstanceData(includeDeleted)
                     + " instead of "
                     + this
                     + ". Not including in renditions list.");
           }
           continue;
         }
       } catch (FileNotFoundException fnfe) {
         continue;
       }
       if (r.getRenderingEngineTemplate() != null) {
         result.add(r);
       }
     }
   }
   return result;
 }
コード例 #3
0
  public List<FormInstanceData.RegenerateResult> regenerateRenditions()
      throws FormNotFoundException {
    if (logger.isDebugEnabled()) {
      logger.debug("regenerating renditions of " + this);
    }

    AVMLockingService avmLockService = this.getServiceRegistry().getAVMLockingService();
    final AVMService avmService = this.getServiceRegistry().getAVMService();
    PropertyValue pv =
        avmService.getNodeProperty(
            AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
            AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
            WCMAppModel.PROP_ORIGINAL_PARENT_PATH);

    String originalParentAvmPath =
        (pv == null) ? AVMNodeConverter.SplitBase(this.getPath())[0] : pv.getStringValue();

    final HashSet<RenderingEngineTemplate> allRets =
        new HashSet<RenderingEngineTemplate>(this.getForm().getRenderingEngineTemplates());
    final List<RegenerateResult> result = new LinkedList<RegenerateResult>();
    // regenerate existing renditions
    boolean renditionLockedBefore = false;
    String path = null;

    for (final Rendition r : this.getRenditions()) {
      // Try to skip renditions without rendering engine template.
      if (r instanceof RenditionImpl) {
        RenditionImpl rImpl = (RenditionImpl) r;
        RenderingEngineTemplate ret = rImpl.getRenderingEngineTemplate();
        if ((ret != null) && (ret instanceof RenderingEngineTemplateImpl)) {
          RenderingEngineTemplateImpl retImpl = (RenderingEngineTemplateImpl) ret;
          if (!retImpl.isExists()) {
            continue;
          }
        }
      }
      final RenderingEngineTemplate ret = r.getRenderingEngineTemplate();
      if (ret == null || !allRets.contains(ret)) {
        continue;
      }
      try {
        if (logger.isDebugEnabled()) {
          logger.debug("regenerating rendition " + r + " using template " + ret);
        }

        renditionLockedBefore = false;
        path = r.getPath();
        AVMLock lock =
            avmLockService.getLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
        if (lock != null) {
          renditionLockedBefore = true;

          if (logger.isDebugEnabled()) {
            logger.debug("Lock already exists for " + path);
          }
        }

        ret.render(this, r);
        allRets.remove(ret);
        result.add(new RegenerateResult(ret, path, r));
      } catch (Exception e) {
        result.add(new RegenerateResult(ret, path, e));

        // remove lock if there wasn't one before
        if (renditionLockedBefore == false) {
          avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));

          if (logger.isDebugEnabled()) {
            logger.debug("Removed lock for " + path + " as it failed to generate");
          }
        }
      }
    }

    // render all renditions for newly added templates
    for (final RenderingEngineTemplate ret : allRets) {
      try {
        renditionLockedBefore = false;
        path = ret.getOutputPathForRendition(this, originalParentAvmPath, getName());

        if (logger.isDebugEnabled()) {
          logger.debug(
              "regenerating rendition of "
                  + this.getPath()
                  + " at "
                  + path
                  + " using template "
                  + ret);
        }

        AVMLock lock =
            avmLockService.getLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
        if (lock != null) {
          renditionLockedBefore = true;

          if (logger.isDebugEnabled()) {
            logger.debug("Lock already exists for " + path);
          }
        }

        result.add(new RegenerateResult(ret, path, ret.render(this, path)));
      } catch (Exception e) {
        result.add(new RegenerateResult(ret, path, e));

        // remove lock if there wasn't one before
        if (renditionLockedBefore == false) {
          avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));

          if (logger.isDebugEnabled()) {
            logger.debug("Removed lock for " + path + " as it failed to generate");
          }
        }
      }
    }
    return result;
  }