KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > bridge > EmbededExternalResourceSecurity


1 /*
2
3    Copyright 2002 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.bridge;
19
20 import org.apache.batik.util.ParsedURL;
21
22 /**
23  * This implementation of the <tt>ExternalResourceSecurity</tt> interface only
24  * allows external resources embeded in the document, i.e., externalResources
25  * embeded with the data protocol.
26  *
27  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
28  * @version $Id: EmbededExternalResourceSecurity.java,v 1.4 2004/08/18 07:12:31 vhardy Exp $
29  */

30 public class EmbededExternalResourceSecurity implements ExternalResourceSecurity {
31     public static final String JavaDoc DATA_PROTOCOL = "data";
32
33     /**
34      * Message when trying to load a external resource that is not embeded
35      * in the document.
36      */

37     public static final String JavaDoc ERROR_EXTERNAL_RESOURCE_NOT_EMBEDED
38         = "EmbededExternalResourceSecurity.error.external.esource.not.embeded";
39
40     /**
41      * The exception is built in the constructor and thrown if
42      * not null and the checkLoadExternalResource method is called.
43      */

44     protected SecurityException JavaDoc se;
45
46     /**
47      * Controls whether the externalResource should be loaded or not.
48      *
49      * @throws SecurityException if the externalResource should not be loaded.
50      */

51     public void checkLoadExternalResource(){
52         if (se != null) {
53             throw se;
54         }
55     }
56
57     /**
58      * @param externalResourceURL url for the externalResource, as defined in
59      * the externalResource's xlink:href attribute. If that
60      * attribute was empty, then this parameter should
61      * be null
62      */

63     public EmbededExternalResourceSecurity(ParsedURL externalResourceURL){
64         if ( externalResourceURL == null
65              ||
66              !DATA_PROTOCOL.equals(externalResourceURL.getProtocol()) ) {
67             se = new SecurityException JavaDoc
68                 (Messages.formatMessage(ERROR_EXTERNAL_RESOURCE_NOT_EMBEDED,
69                                         new Object JavaDoc[]{externalResourceURL}));
70             
71             
72         }
73     }
74 }
75
76
77     
78
Popular Tags