1
2
3
4
5
6
7
8
9
10
11 package org.mule.config;
12
13 import org.mule.MuleManager;
14 import org.mule.util.IOUtils;
15 import org.mule.util.StringUtils;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.io.InputStreamReader;
20 import java.io.Reader;
21
22
23
24
25
26
27 public class ReaderResource
28 {
29
30 private String description;
31 private Reader reader;
32
33 public ReaderResource(String description, Reader reader)
34 {
35 this.description = description;
36 this.reader = reader;
37 }
38
39 public String getDescription()
40 {
41 return description;
42 }
43
44 public Reader getReader()
45 {
46 return reader;
47 }
48
49 public static ReaderResource[] parseResources(String configResources, String encoding) throws IOException
50 {
51 String[] resources = StringUtils.splitAndTrim(configResources, ",");
52 MuleManager.getConfiguration().setConfigResources(resources);
53 ReaderResource[] readers = new ReaderResource[resources.length];
54 for (int i = 0; i < resources.length; i++)
55 {
56 InputStream is = IOUtils.getResourceAsStream(resources[i].trim(), ReaderResource.class);
57 if (is == null)
58 {
59 throw new IOException("could not load resource: " + resources[i].trim());
60 }
61 readers[i] = new ReaderResource(resources[i].trim(), new InputStreamReader(is, encoding));
62 }
63 return readers;
64 }
65
66 public static ReaderResource[] parseResources(String configResources) throws IOException
67 {
68 return parseResources(configResources, MuleManager.getConfiguration().getEncoding());
69 }
70 }