예제 #1
0
파일: Document.java 프로젝트: limves/Cognos
  public static String Extract(String sPattern, int iOffset, String sText) {

    String sResult = "";
    try {
      Scanner document_scanner = new Scanner(sText);

      int iCountOcurr = 0;
      int iFirstLine = 0;
      String sLine = "";
      Boolean bReading = false;
      Boolean bIsEmpty = true;

      while (document_scanner.hasNext()) {
        sLine = document_scanner.next();

        /// Pattern detected
        if (sLine.indexOf(sPattern) > -1) {
          iCountOcurr++;
        }

        /// Number of pattern has been reached
        if (iCountOcurr == iOffset) {
          bReading = true;
        }

        if (bReading && bIsEmpty) {

          if (iFirstLine != 0) {
            /// Stop
            if (sLine.indexOf(sStop) > -1) {
              bReading = false;
              bIsEmpty = false;
            } else {
              sResult += " " + sLine;
            }
          } else {
            sResult += " " + sLine;
          }

          System.out.println("sResult:" + sResult + "\n");
          iFirstLine++;
        }
      }

      document_scanner.close();
      // Print number of times the search pattern was found
      // System.out.println("Found Input "+ iCountOcurr + " times");
    } catch (Exception e) {
      sResult = "Error buscar parrafo: " + e.getMessage();
    }

    return sResult;
  }
예제 #2
0
파일: Document.java 프로젝트: limves/Cognos
  public static String GetText(String sUrl) {

    String sRet = "";
    try {
      System.out.print(" Connecting to: " + sUrl + "... \n");
      InputStream inputStream = new URL(sUrl).openStream();
      System.out.print(" Stream readed from: " + sUrl + "\n");

      HWPFDocument docx = new HWPFDocument(inputStream);
      WordExtractor we = new WordExtractor(docx);
      sRet = we.getText();

      we.close();

    } catch (Exception e) {
      sRet = "Error al leer el archivo" + e.getMessage();
    }

    return sRet;
  }