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; }
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; }
@Override protected void runTestForReal() throws Throwable { Query query = null; try { try { query = queryFromTestItem(testItem); } catch (QueryException qEx) { query = null; qEx.printStackTrace(System.err); fail("Parse failure: " + qEx.getMessage()); throw qEx; } Dataset dataset = setUpDataset(query, testItem); if (dataset == null && !doesQueryHaveDataset(query)) fail("No dataset for query"); QueryExecution qe = null; if (dataset == null) qe = QueryExecutionFactory.create(query, queryFileManager); else qe = QueryExecutionFactory.create(query, dataset); try { if (query.isSelectType()) runTestSelect(query, qe); else if (query.isConstructType()) runTestConstruct(query, qe); else if (query.isDescribeType()) runTestDescribe(query, qe); else if (query.isAskType()) runTestAsk(query, qe); } finally { qe.close(); } } catch (IOException ioEx) { // log.debug("IOException: ",ioEx) ; fail("IOException: " + ioEx.getMessage()); throw ioEx; } catch (NullPointerException ex) { throw ex; } catch (Exception ex) { ex.printStackTrace(System.err); fail("Exception: " + ex.getClass().getName() + ": " + ex.getMessage()); } }