Package net.sf.regain

Examples of net.sf.regain.RegainException


    mUrlRegexAsString = regex;

    try {
      mUrlRegex = Pattern.compile(regex);
    } catch (Exception ex) {
      throw new RegainException("Regular expression of URL matcher has a " +
          "wrong syntax: '" + regex + "'", ex);
    }
  }
View Full Code Here


      int exitCode;
      try {
        exitCode = proc.waitFor();
      } catch (InterruptedException exc) {
        throw new RegainException("Waiting for termination of process failed: "
          + commandArr[0], exc);
      }

      if (mLog.isDebugEnabled()) {
        double duration = (double) (System.currentTimeMillis() - startTime) / 1000.0;

        NumberFormat format = NumberFormat.getInstance();
        format.setMinimumFractionDigits(2);
        format.setMaximumFractionDigits(2);

        mLog.debug("..." + toCommand(commandArr) + " finished ("
            + format.format(duration) + " secs)");
      }

      if (exitCode != 0) {
        throw new RegainException("Native command exited with exit code "
            + exitCode + ": '" + toCommand(commandArr) + "'");
      }

      String[] asArr = new String[list.size()];
      list.toArray(asArr);
      return asArr;
    }
    catch (IOException exc) {
      throw new RegainException("Executing native command failed: '"
          + toCommand(commandArr) + "'", exc);
    }
    finally {
      if (in != null) {
        try { in.close(); } catch (IOException exc) {}
View Full Code Here

    }
    catch (RedirectException exc) {
      throw exc;
    }
    catch (IOException exc) {
      throw new RegainException("Could not load Document with HTTP", exc);
    }
    finally {
      if (in != null) {
        try { in.close(); } catch (Exception exc) {}
      }
View Full Code Here

   * @return byte[] The content of file
   * @throws RegainException in case of problems while loading
   */
  public static byte[] loadFile(File file) throws RegainException {
    if (file.isDirectory()) {
      throw new RegainException("Can't load a directory: "
        + file.getAbsolutePath());
    }

    FileInputStream in = null;
    ByteArrayOutputStream out = null;
    try {
      in = new FileInputStream(file);
      out = new ByteArrayOutputStream((int) file.length());

      RegainToolkit.pipe(in, out);

      return out.toByteArray();
    }
    catch (IOException exc) {
      throw new RegainException("Loading file failed " + file.getAbsolutePath(), exc);
    }
    finally {
      if (out != null) {
        try { out.close(); } catch (IOException exc) {}
      }
View Full Code Here

      RegainToolkit.pipe(inputStream, out);

      return out.toByteArray();
    }
    catch (IOException exc) {
      throw new RegainException("Loading inputstream failed ", exc);
    }
    finally {
      if (out != null) {
        try { out.close(); } catch (IOException exc) {}
      }
View Full Code Here

      } catch (IllegalStateException ex) {
        // No match found
        return "";
      }
    } else {
      throw new RegainException("URL is unparsable. url: " + completeUrl);
    }
  }
View Full Code Here

      } else {
        setCleanedContent("");
      }

    } catch (TagException ex) {
      throw new RegainException("Error handling audio file: " + rawDocument.getUrl(), ex);

    } catch (ReadOnlyFileException ex) {
      throw new RegainException("Error handling audio file: " + rawDocument.getUrl(), ex);

    } catch (InvalidAudioFrameException ex) {
      throw new RegainException("Error handling audio file: " + rawDocument.getUrl(), ex);

    } catch (IOException ex) {
      throw new RegainException("Error handling audio file: " + rawDocument.getUrl(), ex);
    }
  }
View Full Code Here

        StandardDecryptionMaterial sdm = new StandardDecryptionMaterial("");
        pdfDocument.openProtection(sdm);
        AccessPermission ap = pdfDocument.getCurrentAccessPermission();

        if (!ap.canExtractContent()) {
          throw new RegainException("Document is encrypted and can't be opened: " + url);
        }
      }

      // Extract the text with a utility class
      PDFTextStripper stripper = new PDFTextStripper();
      stripper.setSuppressDuplicateOverlappingText(false);
      stripper.setSortByPosition(true);
      stripper.setStartPage(1);
      stripper.setEndPage(Integer.MAX_VALUE);

      setCleanedContent(stripper.getText(pdfDocument).replaceAll("visiblespace", " "));

      // extract annotations
      StringBuilder annotsResult = new StringBuilder();
      List allPages = pdfDocument.getDocumentCatalog().getAllPages();
      for (int i = 0; i < allPages.size(); i++) {
        int pageNum = i + 1;
        PDPage page = (PDPage) allPages.get(i);
        List<PDAnnotation> annotations = page.getAnnotations();
        if (annotations.size() < 1) {
          continue;
        }
        mLog.debug("Total annotations = " + annotations.size());
        mLog.debug("\nProcess Page " + pageNum + "...");
        for (PDAnnotation annotation : annotations) {
          if (annotation.getContents() != null && annotation.getContents().length() > 0) {
            annotsResult.append(annotation.getContents());
            annotsResult.append(" ");
            mLog.debug("Text from annotation: " + annotation.getContents());
          }
        }
      }
      if (annotsResult.length() > 0) {
        setCleanedContent(getCleanedContent() + " Annotations " + annotsResult.toString());
      }

      // Get the meta data
      PDDocumentInformation info = pdfDocument.getDocumentInformation();
      StringBuilder metaData = new StringBuilder();
      metaData.append("p.");
      metaData.append(Integer.toString(pdfDocument.getNumberOfPages()));
      metaData.append(" ");

      // Check if fields are null
      if (info.getAuthor() != null) {
        metaData.append(info.getAuthor());
        metaData.append(" ");
      }
      if (info.getSubject() != null) {
        metaData.append(info.getSubject());
        metaData.append(" ");
      }
      if (info.getKeywords() != null) {
        metaData.append(info.getKeywords());
        metaData.append(" ");
      }

      if (info.getTitle() != null) {
        setTitle(info.getTitle());
      }

      setCleanedMetaData(metaData.toString());
      if (mLog.isDebugEnabled()) {
        mLog.debug("Extracted meta data ::" + getCleanedMetaData()
                + ":: from " + rawDocument.getUrl());
      }

    } catch (CryptographyException exc) {
      throw new RegainException("Error decrypting document: " + url, exc);

    } catch (BadSecurityHandlerException exc) {
      // They didn't supply a password and the default of "" was wrong.
      throw new RegainException("Document is encrypted: " + url, exc);

    } catch (IOException exc) {
      throw new RegainException("Error reading document: " + url, exc);

    } finally {
      if (stream != null) {
        try {
          stream.close();
View Full Code Here

      // Dokument schlie�en (ohne Speichern)
      doc.close(new Variant(false));
    }
    catch (ComFailException exc) {
      throw new RegainException("Using COM failed.", exc);
    }
  }
View Full Code Here

        // Word schlie�en
        mWordApplication.quit();
        mLog.info("Closed MS Word");
      }
      catch (Throwable thr) {
        throw new RegainException("Using COM failed.", thr);
      }
      finally {
        // Alle Ressourcen des COM-Threads freigeben
        ComThread.Release();
      }
View Full Code Here

TOP

Related Classes of net.sf.regain.RegainException

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.