01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 org.springframework.webflow.engine.builder.xml;
17:
18: import java.io.IOException;
19:
20: import org.springframework.core.io.ClassPathResource;
21: import org.springframework.core.io.Resource;
22: import org.xml.sax.EntityResolver;
23: import org.xml.sax.InputSource;
24: import org.xml.sax.SAXException;
25:
26: /**
27: * EntityResolver implementation for the Spring Web Flow 1.0 XML Schema. This
28: * will load the XSD from the classpath.
29: * <p>
30: * The xmlns of the XSD expected to be resolved:
31: *
32: * <pre>
33: * <?xml version="1.0" encoding="UTF-8"?>
34: * <flow xmlns="http://www.springframework.org/schema/webflow"
35: * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
36: * xsi:schemaLocation="http://www.springframework.org/schema/webflow
37: * http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
38: * </pre>
39: *
40: * @author Erwin Vervaet
41: * @author Ben Hale
42: */
43: public class WebFlowEntityResolver implements EntityResolver {
44:
45: private static final String WEBFLOW_ELEMENT = "spring-webflow-1.0";
46:
47: public InputSource resolveEntity(String publicId, String systemId)
48: throws SAXException, IOException {
49: if (systemId != null
50: && systemId.indexOf(WEBFLOW_ELEMENT) > systemId
51: .lastIndexOf("/")) {
52: String filename = systemId.substring(systemId
53: .indexOf(WEBFLOW_ELEMENT));
54: try {
55: Resource resource = new ClassPathResource(filename,
56: getClass());
57: InputSource source = new InputSource(resource
58: .getInputStream());
59: source.setPublicId(publicId);
60: source.setSystemId(systemId);
61: return source;
62: } catch (IOException ex) {
63: // fall through below
64: }
65: }
66: // let the parser handle it
67: return null;
68: }
69: }
|