private void processFiles(String siteId, String root, List<String> fileList, boolean isDelete)
     throws IOException {
   for (String filePath : fileList) {
     if (logger.isDebugEnabled()) {
       logger.debug(String.format("Processing file %s for site %s", filePath, siteId));
     }
     File file = new File(root + filePath);
     String updateIndexPath = filePath;
     Map<String, String> externalProperties = null;
     boolean searchIndexUpdate = false;
     if (!isDelete) {
       if (isMetadataFile(filePath)) {
         if (logger.isDebugEnabled()) {
           logger.debug("Metadata processing started.");
         }
         SAXReader reader = new SAXReader();
         try {
           Document document = reader.read(file);
           updateIndexPath = getAttachmentPath(document);
           if (StringUtils.isNotBlank(updateIndexPath)) {
             if (logger.isDebugEnabled()) {
               logger.debug("Extracting properties.");
             }
             externalProperties = parseMetadataFile(document);
             file = new File(root + updateIndexPath);
             if (!file.exists()) {
               File dir = file.getParentFile();
               dir.mkdirs();
               file.createNewFile();
             }
             searchIndexUpdate = true;
           }
         } catch (DocumentException e) {
           logger.error(
               String.format("Error while opening xml file %s for site %s", filePath, siteId), e);
         }
         if (logger.isDebugEnabled()) {
           logger.debug("Metadata processing finished.");
         }
       } else if (isAttachmentFile(filePath)) {
         searchIndexUpdate = true;
       }
     }
     if (searchIndexUpdate) {
       if (isDelete) {
         searchService.delete(siteId, updateIndexPath);
       } else {
         if (logger.isDebugEnabled()) {
           logger.debug(
               String.format(
                   "Sending search update request for file %s [%s] for site %s",
                   updateIndexPath, filePath, siteId));
         }
         searchService.partialDocumentUpdate(siteId, updateIndexPath, file, externalProperties);
       }
     }
     searchService.commit();
   }
 }
Esempio n. 2
0
  protected void update(String siteId, String root, List<String> fileNames, boolean delete)
      throws PublishingException {
    for (String fileName : fileNames) {
      if (fileName.endsWith(".xml")) {
        try {
          if (delete) {
            searchService.delete(siteId, fileName);

            if (logger.isDebugEnabled()) {
              logger.debug(siteId + ":" + fileName + " deleted from search index");
            }
          } else {
            try {
              String xml = processXml(root, fileName);

              searchService.update(siteId, fileName, xml, true);

              if (logger.isDebugEnabled()) {
                logger.debug(siteId + ":" + fileName + " added to search index");
              }
            } catch (DocumentException e) {
              logger.warn(
                  "Cannot process XML file "
                      + siteId
                      + ":"
                      + fileName
                      + ". Continuing index "
                      + "update...",
                  e);
            }
          }
        } catch (Exception e) {
          throw new PublishingException(e);
        }
      }
    }
  }