protected String generateCacheKey() {
   boolean isVisitor = true;
   String role = "V";
   String principalName = ctx.getPrincipal().getName();
   try {
     if (getPage().isAdministrator(principalName)) {
       role = "A";
     } else if (getPage().isContributor(principalName)) {
       role = "C";
     }
   } catch (ClientException e) {
     LOG.warn(
         "Unable to get site adapter while generating cache key so cached page is used: "
             + e.getMessage());
   }
   if (isVisitor) {
     String dateStr = "";
     try {
       dateStr =
           Long.toString(
               ((Calendar) getDocument().getPropertyValue("dc:modified")).getTime().getTime());
     } catch (PropertyException e) {
       LOG.warn("Unable to get property 'dc:modified': " + e.getMessage());
     } catch (ClientException e) {
       LOG.warn("Unable to get property 'dc:modified': " + e.getMessage());
     }
     return generateCacheName() + "-" + getPath() + "-" + role + "-" + dateStr;
   } else {
     return CacheBlock.NO_CACHE_KEY;
   }
 }
예제 #2
0
 protected Mailer.Message createMessage(DocumentModel doc, String message, Map<String, Object> map)
     throws MessagingException, TemplateException, RenderingException, IOException {
   if (blobXpath == null) {
     if (asHtml) {
       return COMPOSER.newHtmlMessage(message, map);
     } else {
       return COMPOSER.newTextMessage(message, map);
     }
   } else {
     ArrayList<Blob> blobs = new ArrayList<Blob>();
     for (String xpath : blobXpath) {
       try {
         Property p = doc.getProperty(xpath);
         if (p instanceof BlobProperty) {
           getBlob(p.getValue(), blobs);
         } else if (p instanceof ListProperty) {
           for (Property pp : p) {
             getBlob(pp.getValue(), blobs);
           }
         } else if (p instanceof MapProperty) {
           for (Property sp : ((MapProperty) p).values()) {
             getBlob(sp.getValue(), blobs);
           }
         } else {
           Object o = p.getValue();
           if (o instanceof Blob) {
             blobs.add((Blob) o);
           }
         }
       } catch (PropertyException pe) {
         log.error("Error while fetching blobs: " + pe.getMessage());
         log.debug(pe, pe);
         continue;
       }
     }
     return COMPOSER.newMixedMessage(message, map, asHtml ? "html" : "plain", blobs);
   }
 }