KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > text > AbstractTextConnection


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.driver.text;
17
18 import scriptella.spi.AbstractConnection;
19 import scriptella.spi.ConnectionParameters;
20 import scriptella.spi.DialectIdentifier;
21
22 import java.net.URL JavaDoc;
23
24 /**
25  * Base class for Text/CSV connections.
26  *
27  * @author Fyodor Kupolov
28  * @version 1.0
29  */

30 public abstract class AbstractTextConnection extends AbstractConnection {
31     protected final String JavaDoc encoding;
32     protected final boolean trim;
33     protected final URL JavaDoc url;
34     protected final String JavaDoc eol;
35     /**
36      * Name of the <code>encoding</code> connection property.
37      * Specifies charset encoding in text files.
38      */

39     public static final String JavaDoc ENCODING = "encoding";
40     /**
41      * Name of the <code>eol</code> connection property.
42      * EOL suffix. Default value is \n.
43      */

44     public static final String JavaDoc EOL = "eol";
45
46     /**
47      * Name of the <code>trim</code> connection property.
48      * Value of <code>true</code> specifies that the leading and trailing
49      * whitespaces should be omitted.
50      */

51     public static final String JavaDoc TRIM = "trim";
52
53     /**
54      * For testing only.
55      */

56     protected AbstractTextConnection() {
57         encoding = null;
58         trim = false;
59         url = null;
60         eol = "\n";
61     }
62
63     /**
64      * Initializes a text connection using specified properties.
65      *
66      * @param dialectIdentifier
67      * @param parameters
68      */

69     protected AbstractTextConnection(DialectIdentifier dialectIdentifier, ConnectionParameters parameters) {
70         super(dialectIdentifier, parameters);
71         url = parameters.getResolvedUrl();
72         encoding = parameters.getCharsetProperty(ENCODING);
73         trim = parameters.getBooleanProperty("trim", true);
74         String JavaDoc eolStr = parameters.getStringProperty(TextConnection.EOL);
75         if (eolStr != null && eolStr.length() > 0) {
76             eol = eolStr;
77         } else {
78             eol = "\n"; //Default value
79
}
80
81     }
82
83     public String JavaDoc getEncoding() {
84         return encoding;
85     }
86
87     public boolean isTrim() {
88         return trim;
89     }
90
91     public URL JavaDoc getUrl() {
92         return url;
93     }
94
95     public String JavaDoc getEol() {
96         return eol;
97     }
98
99 }
100
Popular Tags