1:
31: package ;
32:
33: import ;
34: import ;
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46:
47:
52: public class StyleSheetReadHandler extends StringReadHandler
53: {
54: private StyleSheet styleSheet;
55:
56: public StyleSheetReadHandler()
57: {
58: }
59:
60:
66: protected void startParsing(final Attributes attrs) throws SAXException
67: {
68: super.startParsing(attrs);
69: final String href = attrs.getValue(getUri(), "href");
70: if (href != null)
71: {
72: final ResourceKey key = getRootHandler().getSource();
73: final ResourceManager manager = getRootHandler().getResourceManager();
74: try
75: {
76: final ResourceKey derivedKey = manager.deriveKey(key, href);
77: final Resource resource = manager.create(derivedKey, null,
78: StyleSheet.class);
79: getRootHandler().getDependencyCollector().add(resource);
80: styleSheet = (StyleSheet) resource.getResource();
81: }
82: catch (ResourceKeyCreationException e)
83: {
84: throw new ParseException
85: ("Unable to derive key for " + key + " and " + href, getLocator());
86: }
87: catch (ResourceCreationException e)
88: {
89: Log.warn("Unable to parse resource for " + key + " and " + href);
90: }
91: catch (ResourceLoadingException e)
92: {
93: Log.warn ("Unable to load resource data for " + key + " and " + href);
94: }
95: catch (ResourceException e)
96: {
97: Log.warn ("Unable to load resource for " + key + " and " + href);
98: }
99: }
100: }
101:
102:
107: protected void doneParsing() throws SAXException
108: {
109: super.doneParsing();
110: if (this.styleSheet != null)
111: {
112: return;
113: }
114:
115: final String styleText = getResult();
116: if (styleText.trim().length() == 0)
117: {
118: return;
119: }
120: try
121: {
122: final byte[] bytes = styleText.getBytes("UTF-8");
123:
124: final ResourceKey baseKey = getRootHandler().getSource();
125: final ResourceManager resourceManager = getRootHandler().getResourceManager();
126: final ResourceKey rawKey = resourceManager.createKey(bytes);
127:
128: final Resource resource = resourceManager.create
129: (rawKey, baseKey, StyleSheet.class);
130: this.styleSheet = (StyleSheet) resource.getResource();
131: }
132: catch (Exception e)
133: {
134: e.printStackTrace();
135: }
136: }
137:
138:
143: public Object getObject()
144: {
145: return styleSheet;
146: }
147:
148: public StyleSheet getStyleSheet()
149: {
150: return styleSheet;
151: }
152: }