View Javadoc

1   /*
2    * Copyright 2005-2010 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  
17  package org.springframework.xml.transform;
18  
19  import java.io.IOException;
20  import javax.xml.transform.sax.SAXSource;
21  
22  import org.springframework.core.io.Resource;
23  import org.springframework.xml.sax.SaxUtils;
24  
25  import org.xml.sax.XMLReader;
26  
27  /**
28   * Convenient subclass of [email protected] SAXSource} that reads from a Spring [email protected] Resource}. The resource to be read can be
29   * set via the constructor.
30   *
31   * @author Arjen Poutsma
32   * @since 1.0.0
33   */
34  public class ResourceSource extends SAXSource {
35  
36      /**
37       * Initializes a new instance of the <code>ResourceSource</code> with the given resource.
38       *
39       * @param content the content
40       */
41      public ResourceSource(Resource content) throws IOException {
42          super(SaxUtils.createInputSource(content));
43      }
44  
45      /**
46       * Initializes a new instance of the <code>ResourceSource</code> with the given [email protected] XMLReader} and resource.
47       *
48       * @param content the content
49       */
50      public ResourceSource(XMLReader reader, Resource content) throws IOException {
51          super(reader, SaxUtils.createInputSource(content));
52      }
53  }