comparison dwtx/jface/text/templates/persistence/TemplateReaderWriter.d @ 136:6dcb0baaa031

Regex removal of throws decls, some instanceof
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 02:20:40 +0200
parents 51e6e63f930e
children b6bad70d540a
comparison
equal deleted inserted replaced
135:65801ad2b265 136:6dcb0baaa031
90 * 90 *
91 * @param reader the reader to read templates from 91 * @param reader the reader to read templates from
92 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code> 92 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
93 * @throws IOException if reading from the stream fails 93 * @throws IOException if reading from the stream fails
94 */ 94 */
95 public TemplatePersistenceData[] read(Reader reader) throws IOException { 95 public TemplatePersistenceData[] read(Reader reader) {
96 return read(reader, null); 96 return read(reader, null);
97 } 97 }
98 98
99 /** 99 /**
100 * Reads the template with identifier <code>id</code> from a reader and 100 * Reads the template with identifier <code>id</code> from a reader and
106 * @return the read template, encapsulated in an instances of 106 * @return the read template, encapsulated in an instances of
107 * <code>TemplatePersistenceData</code> 107 * <code>TemplatePersistenceData</code>
108 * @throws IOException if reading from the stream fails 108 * @throws IOException if reading from the stream fails
109 * @since 3.1 109 * @since 3.1
110 */ 110 */
111 public TemplatePersistenceData readSingle(Reader reader, String id) throws IOException { 111 public TemplatePersistenceData readSingle(Reader reader, String id) {
112 TemplatePersistenceData[] datas= read(new InputSource(reader), null, id); 112 TemplatePersistenceData[] datas= read(new InputSource(reader), null, id);
113 if (datas.length > 0) 113 if (datas.length > 0)
114 return datas[0]; 114 return datas[0];
115 return null; 115 return null;
116 } 116 }
121 * @param reader the reader to read templates from 121 * @param reader the reader to read templates from
122 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur 122 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
123 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code> 123 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
124 * @throws IOException if reading from the stream fails 124 * @throws IOException if reading from the stream fails
125 */ 125 */
126 public TemplatePersistenceData[] read(Reader reader, ResourceBundle bundle) throws IOException { 126 public TemplatePersistenceData[] read(Reader reader, ResourceBundle bundle) {
127 return read(new InputSource(reader), bundle, null); 127 return read(new InputSource(reader), bundle, null);
128 } 128 }
129 129
130 /** 130 /**
131 * Reads templates from a stream and adds them to the templates. 131 * Reads templates from a stream and adds them to the templates.
133 * @param stream the byte stream to read templates from 133 * @param stream the byte stream to read templates from
134 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur 134 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
135 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code> 135 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
136 * @throws IOException if reading from the stream fails 136 * @throws IOException if reading from the stream fails
137 */ 137 */
138 public TemplatePersistenceData[] read(InputStream stream, ResourceBundle bundle) throws IOException { 138 public TemplatePersistenceData[] read(InputStream stream, ResourceBundle bundle) {
139 return read(new InputSource(stream), bundle, null); 139 return read(new InputSource(stream), bundle, null);
140 } 140 }
141 141
142 /** 142 /**
143 * Reads templates from an <code>InputSource</code> and adds them to the templates. 143 * Reads templates from an <code>InputSource</code> and adds them to the templates.
146 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur 146 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
147 * @param singleId the template id to extract, or <code>null</code> to read in all templates 147 * @param singleId the template id to extract, or <code>null</code> to read in all templates
148 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code> 148 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
149 * @throws IOException if reading from the stream fails 149 * @throws IOException if reading from the stream fails
150 */ 150 */
151 private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle, String singleId) throws IOException { 151 private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle, String singleId) {
152 try { 152 try {
153 Collection templates= new ArrayList(); 153 Collection templates= new ArrayList();
154 Set ids= new HashSet(); 154 Set ids= new HashSet();
155 155
156 DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); 156 DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
232 * 232 *
233 * @param templates the templates to save 233 * @param templates the templates to save
234 * @param stream the byte output to write the templates to in XML 234 * @param stream the byte output to write the templates to in XML
235 * @throws IOException if writing the templates fails 235 * @throws IOException if writing the templates fails
236 */ 236 */
237 public void save(TemplatePersistenceData[] templates, OutputStream stream) throws IOException { 237 public void save(TemplatePersistenceData[] templates, OutputStream stream) {
238 save(templates, new StreamResult(stream)); 238 save(templates, new StreamResult(stream));
239 } 239 }
240 240
241 /** 241 /**
242 * Saves the templates as XML. 242 * Saves the templates as XML.
243 * 243 *
244 * @param templates the templates to save 244 * @param templates the templates to save
245 * @param writer the writer to write the templates to in XML 245 * @param writer the writer to write the templates to in XML
246 * @throws IOException if writing the templates fails 246 * @throws IOException if writing the templates fails
247 */ 247 */
248 public void save(TemplatePersistenceData[] templates, Writer writer) throws IOException { 248 public void save(TemplatePersistenceData[] templates, Writer writer) {
249 save(templates, new StreamResult(writer)); 249 save(templates, new StreamResult(writer));
250 } 250 }
251 251
252 /** 252 /**
253 * Saves the templates as XML. 253 * Saves the templates as XML.
254 * 254 *
255 * @param templates the templates to save 255 * @param templates the templates to save
256 * @param result the stream result to write to 256 * @param result the stream result to write to
257 * @throws IOException if writing the templates fails 257 * @throws IOException if writing the templates fails
258 */ 258 */
259 private void save(TemplatePersistenceData[] templates, StreamResult result) throws IOException { 259 private void save(TemplatePersistenceData[] templates, StreamResult result) {
260 try { 260 try {
261 DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); 261 DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
262 DocumentBuilder builder= factory.newDocumentBuilder(); 262 DocumentBuilder builder= factory.newDocumentBuilder();
263 Document document= builder.newDocument(); 263 Document document= builder.newDocument();
264 264
334 throw cast(IOException) e.getException(); 334 throw cast(IOException) e.getException();
335 Assert.isTrue(false); 335 Assert.isTrue(false);
336 } 336 }
337 } 337 }
338 338
339 private bool getBooleanValue(NamedNodeMap attributes, String attribute, bool defaultValue) throws SAXException { 339 private bool getBooleanValue(NamedNodeMap attributes, String attribute, bool defaultValue) {
340 Node enabledNode= attributes.getNamedItem(attribute); 340 Node enabledNode= attributes.getNamedItem(attribute);
341 if (enabledNode is null) 341 if (enabledNode is null)
342 return defaultValue; 342 return defaultValue;
343 else if (enabledNode.getNodeValue().equals(Boolean.toString(true))) 343 else if (enabledNode.getNodeValue().equals(Boolean.toString(true)))
344 return true; 344 return true;
346 return false; 346 return false;
347 else 347 else
348 throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.illegal_boolean_attribute")); //$NON-NLS-1$ 348 throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.illegal_boolean_attribute")); //$NON-NLS-1$
349 } 349 }
350 350
351 private String getStringValue(NamedNodeMap attributes, String name) throws SAXException { 351 private String getStringValue(NamedNodeMap attributes, String name) {
352 String val= getStringValue(attributes, name, null); 352 String val= getStringValue(attributes, name, null);
353 if (val is null) 353 if (val is null)
354 throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$ 354 throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$
355 return val; 355 return val;
356 } 356 }