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

19 package org.apache.batik.bridge;
20
21 import java.net.URL;
22
23 import org.apache.batik.script.ImportInfo;
24 import org.apache.batik.script.Interpreter;
25 import org.apache.batik.script.InterpreterFactory;
26
27 /**
28  * Allows to create instances of <code>RhinoInterpreter</code> class.
29  *
30  * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
31  * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
32  * @version $Id: RhinoInterpreterFactory.java 1733416 2016-03-03 07:07:13Z gadams $
33  */

34 public class RhinoInterpreterFactory implements InterpreterFactory {
35
36     /**
37      * The MIME types that Rhino can handle.
38      */

39     public static final String[] RHINO_MIMETYPES = {
40         "application/ecmascript",
41         "application/javascript",
42         "text/ecmascript",
43         "text/javascript",
44     };
45
46     /**
47      * Builds a <code>RhinoInterpreterFactory</code>.
48      */

49     public RhinoInterpreterFactory() {
50     }
51
52     /**
53      * Returns the mime-types to register this interpereter with.
54      */

55     public String[] getMimeTypes() {
56         return RHINO_MIMETYPES;
57     }
58
59     /**
60      * Creates an instance of <code>RhinoInterpreter</code> class.
61      *
62      * @param documentURL the url for the document which will be scripted
63      * @param svg12 whether the document is an SVG 1.2 document
64      */

65     public Interpreter createInterpreter(URL documentURL, boolean svg12) {
66         return createInterpreter(documentURL, svg12, null);
67     }
68
69     /**
70      * Creates an instance of <code>RhinoInterpreter</code> class.
71      *
72      * @param documentURL the url for the document which will be scripted
73      * @param svg12 whether the document is an SVG 1.2 document
74      * @param imports The set of classes/packages to import (if
75      *                the interpreter supports that), may be null.
76      */

77     public Interpreter createInterpreter(URL documentURL, boolean svg12,
78                                          ImportInfo imports) {
79         if (svg12) {
80             return new SVG12RhinoInterpreter(documentURL, imports);
81         }
82         return new RhinoInterpreter(documentURL, imports);
83     }
84 }
85