View Javadoc

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