1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.banking.ri.blzdirectory;
22
23 import java.io.IOException;
24 import java.text.NumberFormat;
25 import java.text.ParseException;
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28 import java.util.Properties;
29 import org.jdtaus.banking.util.BankleitzahlenDatei;
30
31
32
33
34
35
36
37
38
39 public abstract class AbstractPropertiesBankfileProvider implements BankfileProvider
40 {
41
42
43 private static final String BANKFILE_COUNT_PROPERTY = "BankleitzahlenVerzeichnis.bankfileCount";
44
45
46 private static final String BANKFILE_PREFIX = "BankleitzahlenDatei.";
47
48
49 private Properties properties;
50
51
52 public AbstractPropertiesBankfileProvider()
53 {
54 super();
55 }
56
57 public long getLastModifiedMillis() throws IOException
58 {
59 return 0L;
60 }
61
62 public final int getBankfileCount() throws IOException
63 {
64 try
65 {
66 final String value = this.getProperties().getProperty( BANKFILE_COUNT_PROPERTY, Integer.toString( 0 ) );
67 return NumberFormat.getIntegerInstance().parse( value ).intValue();
68 }
69 catch ( final ParseException e )
70 {
71 throw (IOException) new IOException( e.getMessage() ).initCause( e );
72 }
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86 public String getBankfileLocation( final int index ) throws IOException
87 {
88 if ( index < 0 || index >= this.getBankfileCount() )
89 {
90 throw new IndexOutOfBoundsException( Integer.toString( index ) );
91 }
92
93 final String propertyKey = BANKFILE_PREFIX + index + ".location";
94 final String location = this.getProperties().getProperty( propertyKey );
95 assert location != null : "Property '" + propertyKey + "' not found.";
96 return location;
97 }
98
99 public final Date getDateOfValidity( final int index ) throws IOException
100 {
101 if ( index < 0 || index >= this.getBankfileCount() )
102 {
103 throw new IndexOutOfBoundsException( Integer.toString( index ) );
104 }
105
106 try
107 {
108 final String propertyKey = BANKFILE_PREFIX + index + ".dateOfValidity";
109 final String value = this.getProperties().getProperty( propertyKey );
110 assert value != null : "Property '" + propertyKey + "' not found.";
111 return new SimpleDateFormat( "yyyyMMdd" ).parse( value );
112 }
113 catch ( final ParseException e )
114 {
115 throw (IOException) new IOException( e.getMessage() ).initCause( e );
116 }
117 }
118
119 public final Date getDateOfExpiration( final int index ) throws IOException
120 {
121 if ( index < 0 || index >= this.getBankfileCount() )
122 {
123 throw new IndexOutOfBoundsException( Integer.toString( index ) );
124 }
125
126 try
127 {
128 final String propertyKey = BANKFILE_PREFIX + index + ".dateOfExpiration";
129 final String value = this.getProperties().getProperty( propertyKey );
130 assert value != null : "Property '" + propertyKey + "' not found.";
131 return new SimpleDateFormat( "yyyyMMdd" ).parse( value );
132 }
133 catch ( final ParseException e )
134 {
135 throw (IOException) new IOException( e.getMessage() ).initCause( e );
136 }
137 }
138
139 public final int getFormat( final int index ) throws IOException
140 {
141 if ( index < 0 || index >= this.getBankfileCount() )
142 {
143 throw new IndexOutOfBoundsException( Integer.toString( index ) );
144 }
145
146 final String value =
147 this.getProperties().getProperty( BANKFILE_PREFIX + index + ".format" );
148
149 return value == null
150 ? BankleitzahlenDatei.JUNE_2006_FORMAT
151 : Integer.parseInt( value );
152
153 }
154
155
156
157
158
159
160
161
162 public Properties getProperties() throws IOException
163 {
164 if ( this.properties == null )
165 {
166 this.properties = new Properties();
167 }
168
169 return this.properties;
170 }
171
172
173
174
175
176
177 public void setProperties( final Properties value )
178 {
179 this.properties = value;
180 }
181
182 }