KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > builder > xml > WebFlowEntityResolver


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19
20 import org.springframework.core.io.ClassPathResource;
21 import org.springframework.core.io.Resource;
22 import org.xml.sax.EntityResolver JavaDoc;
23 import org.xml.sax.InputSource JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
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  * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
34  * &lt;flow xmlns=&quot;http://www.springframework.org/schema/webflow&quot;
35  * xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
36  * xsi:schemaLocation=&quot;http://www.springframework.org/schema/webflow
37  * http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd&quot;&gt;
38  * </pre>
39  *
40  * @author Erwin Vervaet
41  * @author Ben Hale
42  */

43 public class WebFlowEntityResolver implements EntityResolver JavaDoc {
44
45     private static final String JavaDoc WEBFLOW_ELEMENT = "spring-webflow-1.0";
46
47     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc, IOException JavaDoc {
48         if (systemId != null && systemId.indexOf(WEBFLOW_ELEMENT) > systemId.lastIndexOf("/")) {
49             String JavaDoc filename = systemId.substring(systemId.indexOf(WEBFLOW_ELEMENT));
50             try {
51                 Resource resource = new ClassPathResource(filename, getClass());
52                 InputSource JavaDoc source = new InputSource JavaDoc(resource.getInputStream());
53                 source.setPublicId(publicId);
54                 source.setSystemId(systemId);
55                 return source;
56             }
57             catch (IOException JavaDoc ex) {
58                 // fall through below
59
}
60         }
61         // let the parser handle it
62
return null;
63     }
64 }
Popular Tags