KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > rasterizer > SVGConverterFileSource


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.apps.rasterizer;
19
20 import java.io.File JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25
26 /**
27  * Describes a file source for the <tt>SVGConverter</tt>
28  *
29  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
30  * @version $Id: SVGConverterFileSource.java,v 1.5 2004/08/18 07:12:26 vhardy Exp $
31  */

32 public class SVGConverterFileSource implements SVGConverterSource {
33     File JavaDoc file;
34     String JavaDoc ref;
35
36     public SVGConverterFileSource(File JavaDoc file){
37         this.file = file;
38     }
39
40     public SVGConverterFileSource(File JavaDoc file, String JavaDoc ref){
41         this.file = file;
42         this.ref = ref;
43     }
44
45     public String JavaDoc getName(){
46         String JavaDoc name = file.getName();
47         if (ref != null && !"".equals(ref)){
48             name += "#" + ref;
49         }
50         return name;
51     }
52
53     public File JavaDoc getFile(){
54         return file;
55     }
56
57     public String JavaDoc toString(){
58         return getName();
59     }
60
61     public String JavaDoc getURI(){
62         try{
63             String JavaDoc uri = file.toURL().toString();
64             if (ref != null && !"".equals(ref)){
65                 uri += "#" + ref;
66             }
67             return uri;
68         } catch(MalformedURLException JavaDoc e){
69             throw new Error JavaDoc();
70         }
71     }
72
73     public boolean equals(Object JavaDoc o){
74         if (o == null || !(o instanceof SVGConverterFileSource)){
75             return false;
76         }
77         
78         return file.equals(((SVGConverterFileSource)o).file);
79     }
80
81     public InputStream JavaDoc openStream() throws FileNotFoundException JavaDoc{
82         return new FileInputStream JavaDoc(file);
83     }
84
85     public boolean isSameAs(String JavaDoc srcStr){
86         if (file.toString().equals(srcStr)){
87             return true;
88         }
89
90         return false;
91     }
92         
93     public boolean isReadable(){
94         return file.canRead();
95     }
96 }
97
98
Popular Tags