KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > svgbrowser > SVGInputHandler


1 /*
2
3    Copyright 2002-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.svgbrowser;
19
20 import java.io.File JavaDoc;
21
22 import org.apache.batik.util.ParsedURL;
23
24 /**
25  * This implementation of the <tt>SquiggleInputHandler</tt> class
26  * simply displays an SVG file into the JSVGCanvas.
27  *
28  * @author <a mailto="vincent.hardy@sun.com">Vincent Hardy</a>
29  * @version $Id: SVGInputHandler.java,v 1.5 2004/08/18 07:12:27 vhardy Exp $
30  */

31 public class SVGInputHandler implements SquiggleInputHandler {
32     public static final String JavaDoc[] SVG_MIME_TYPES =
33     { "image/svg+xml" };
34
35     public static final String JavaDoc[] SVG_FILE_EXTENSIONS =
36     { ".svg", ".svgz" };
37
38     /**
39      * Returns the list of mime types handled by this handler.
40      */

41     public String JavaDoc[] getHandledMimeTypes() {
42         return SVG_MIME_TYPES;
43     }
44     
45     /**
46      * Returns the list of file extensions handled by this handler
47      */

48     public String JavaDoc[] getHandledExtensions() {
49         return SVG_FILE_EXTENSIONS;
50     }
51
52     /**
53      * Returns a description for this handler.
54      */

55     public String JavaDoc getDescription() {
56         return "";
57     }
58
59     /**
60      * Handles the given input for the given JSVGViewerFrame
61      */

62     public void handle(ParsedURL purl, JSVGViewerFrame svgViewerFrame) {
63         svgViewerFrame.getJSVGCanvas().loadSVGDocument(purl.toString());
64     }
65
66     /**
67      * Returns true if the input file can be handled.
68      */

69     public boolean accept(File JavaDoc f) {
70         return f != null && f.isFile() && accept(f.getPath());
71     }
72
73     /**
74      * Returns true if the input URI can be handled by the handler
75      */

76     public boolean accept(ParsedURL purl) {
77         // <!> Note: this should be improved to rely on Mime Type
78
// when the http protocol is used. This will use the
79
// ParsedURL.getContentType method.
80
if (purl == null) {
81             return false;
82         }
83
84         String JavaDoc path = purl.getPath();
85         if (path == null) return false;
86
87         return accept(path);
88     }
89
90     /**
91      * Returns true if the resource at the given path can be handled
92      */

93     public boolean accept(String JavaDoc path) {
94         if (path == null) return false;
95         for (int i=0; i<SVG_FILE_EXTENSIONS.length; i++) {
96             if (path.endsWith(SVG_FILE_EXTENSIONS[i])) {
97                 return true;
98             }
99         }
100
101         return false;
102     }
103 }
104
Popular Tags