scriptella.driver.text

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » scriptella » scriptella.driver.text 
scriptella.driver.text

Text Driver for Scriptella.

It allows querying a text file based on regular expressions, the text driver can also be used as a lightweight replacement for Velocity to produce simple output with properties substitution.

Text driver does depends on additional libraries and is generally faster than CSV or Velocity driver.

Note: The driver doesn't use SQL syntax

General information

Driver class:scriptella.driver.text.Driver
URL:Text file URL. URIs are resolved relative to a script file directory. If url has no value the output is read from/printed to the console (System.out).
Runtime dependencies:None

Driver Specific Properties

Name Description Required
encoding Specifies charset encoding of Text files. No, the system default encoding is used.
eol End-Of-Line suffix.

Only valid for <script> elements.

No, the default value is \n.
trim Value of true specifies that the leading and trailing whitespaces in text file lines should be omitted. No, the default value is true.
flush Value of true specifies that the outputted content should flushed immediately when the <script> element completes. No, the default value is false.
skip_lines The number of lines to skip before start reading. No, the default value is 0 (no lines are skipped).

Query Syntax

Text driver supports Regular expressions syntax to query text files. The file is read line-by-line from the location specified by the URL connection property and each line is matched against the regex pattern.

If a line or a part of it matches the pattern this match produces a virtual row in a result set. The column names in a virtual result set correspond to matched regex group names. For example query foo(.*) matches foobar line and the produced result set row contains two columns(groups): 0-foobar, 1-bar. These columns can be referenced in child script or query elements by a numeric name or by a string name columnN.

It also possible to specify more than one regular expressions to match file content. Specify each regular expression on a separate line to match them using OR condition.

The Text driver uses java.util.regex implementation for pattern matching. See java.util.Pattern for supported syntax Javadoc.

Additional notes:

  • Regular expressions matching is case-insensitive
  • Empty query selects all lines from the input file.
  • The 0(zero) column name in the produced result set contains the matched line.
  • Leading and trailing whitespaces in query element and input file lines are trimmed by default.
  • Use ^ and $ boundary matchers to match the whole line.


Example:
<query>
  ^ERROR: (.*)
  WARNING: (.*Failed.*)
  ([\d]+) errors?
</query>
    
This query consists of 3 regular expressions:
  1. selects lines starting with ERROR: prefix
  2. selects WARNING lines having Failed substring
  3. selects lines containg a number of errors, e.g. "Found 5 errors".
The query selects any line satisfying one of these 3 regular expressions. Suppose input file has the following content:
Log file started...
INFO: INIT
WARNING: CPU is slow
WARNING: Failed to increase heap size
ERROR: Process interrupted
Operation completed with 1 error.
As the result of query execution the following set of rows is produced:
0 1
WARNING: Failed to increase heap size Failed to increase heap size
ERROR: Process interrupted Process interrupted
1 error 1

Script Syntax

The <script> element content is read line-by-line, for each line properties are expanded and the output is sent to the file specifed by a url connection attribute.

Additional notes:

  • Lines in the outputted file are separated by a EOL string specified by eol connection property.
  • Leading and trailing whitespaces in the output file lines are trimmed by default.
  • No escaping is performed when properties are expanded. Use String.replace or other escaping techniques to achieve output similar to CSV etc.
  • If a script is executed multiple times (e.g. inside a parent query) the output is appended to the file content.


Example:
<script>
    Inserted a record with ID=$id. Table=${table}
</script>
    
For id=1 and table=system this script produces the following output:
Inserted a record with ID=1. Table=system
    

Properties substitution

In text script and query elements ${property} or $property syntax is used for properties/variables substition.

Examples

<connection id="in" driver="text" url="data.csv">
</connection>
<connection id="out" driver="text" url="report.csv">
</connection>

<script connection-id="out">
    ID;Priority;Summary;Status
</script>

<query connection-id="in">
    <script connection-id="out">
        $rownum;$column0;$column1;$column2
    </script>
</query>

Copies rows from data.csv file to report.csv, additionally the ID column is added. The result file is semicolon separated.
Java Source File NameTypeComment
AbstractTextConnection.javaClass Base class for Text/CSV connections.
ConsoleAdapters.javaClass Pre Java SE 6 adapters for System.in and System.out

TODO: Move this class to a spi.support.text package.

Driver.javaClass Represents a Text file driver.
TextConnection.javaClass Represents a connection to a Text file.
TextConnectionPerfTest.javaClass Tests for scriptella.driver.text.TextConnection .
TextConnectionTest.javaClass Tests for scriptella.driver.text.TextConnection .
TextProviderException.javaClass Thrown to indicate a problem with Text file processing.
TextQueryExecutor.javaClass This class executes a regex query over a text file content.
TextQueryExecutorTest.javaClass Tests for TextQueryExecutor .
TextScriptExecutor.javaClass Writes a text content to the output and performs properties expansion.

This class is a simplified template engine similar to Velocity, but of course less powerful.

TextScriptExecutorTest.javaClass Tests for scriptella.driver.text.TextQueryExecutor .
TextScriptITest.javaClass
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.