001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.batik.bridge;
019:
020: import org.apache.batik.test.TestReport;
021: import org.apache.batik.test.svg.SelfContainedSVGOnLoadTest;
022: import org.apache.batik.util.ApplicationSecurityEnforcer;
023: import org.apache.batik.util.ParsedURL;
024:
025: /**
026: * Helper class to simplify writing the unitTesting.xml file for
027: * the bridge.
028: *
029: * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
030: * @version $Id: ScriptSelfTest.java 475477 2006-11-15 22:44:28Z cam $
031: */
032:
033: public class ScriptSelfTest extends SelfContainedSVGOnLoadTest {
034: String scripts = "text/ecmascript, application/java-archive";
035: boolean secure = true;
036: String scriptOrigin = "any";
037: String fileName;
038:
039: TestUserAgent userAgent = new TestUserAgent();
040:
041: public void setId(String id) {
042: super .setId(id);
043:
044: if (id != null) {
045: int i = id.indexOf("(");
046: if (i != -1) {
047: id = id.substring(0, i);
048: }
049: fileName = "test-resources/org/apache/batik/bridge/" + id
050: + ".svg";
051: svgURL = resolveURL(fileName);
052: }
053: }
054:
055: public void setSecure(boolean secure) {
056: this .secure = secure;
057: }
058:
059: public boolean getSecure() {
060: return secure;
061: }
062:
063: public String getScriptOrigin() {
064: return scriptOrigin;
065: }
066:
067: public void setScriptOrigin(String scriptOrigin) {
068: this .scriptOrigin = scriptOrigin;
069: }
070:
071: public void setScripts(String scripts) {
072: this .scripts = scripts;
073: }
074:
075: public String getScripts() {
076: return scripts;
077: }
078:
079: public TestReport runImpl() throws Exception {
080: ApplicationSecurityEnforcer ase = new ApplicationSecurityEnforcer(
081: this .getClass(),
082: "org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy");
083:
084: if (secure) {
085: ase.enforceSecurity(true);
086: }
087:
088: try {
089: return super .runImpl();
090: } catch (ExceptionInInitializerError e) {
091: e.printStackTrace();
092: throw e;
093: } catch (NoClassDefFoundError e) {
094: // e.printStackTrace();
095: throw new Exception(e.getMessage());
096: } finally {
097: ase.enforceSecurity(false);
098: }
099: }
100:
101: protected UserAgent buildUserAgent() {
102: return userAgent;
103: }
104:
105: class TestUserAgent extends UserAgentAdapter {
106: public ScriptSecurity getScriptSecurity(String scriptType,
107: ParsedURL scriptPURL, ParsedURL docPURL) {
108: ScriptSecurity scriptSecurity = null;
109: if (scripts.indexOf(scriptType) == -1) {
110: scriptSecurity = new NoLoadScriptSecurity(scriptType);
111: } else {
112: if ("any".equals(scriptOrigin)) {
113: scriptSecurity = new RelaxedScriptSecurity(
114: scriptType, scriptPURL, docPURL);
115: } else if ("document".equals(scriptOrigin)) {
116: scriptSecurity = new DefaultScriptSecurity(
117: scriptType, scriptPURL, docPURL);
118: } else if ("embeded".equals(scriptOrigin)) {
119: scriptSecurity = new EmbededScriptSecurity(
120: scriptType, scriptPURL, docPURL);
121: } else if ("none".equals(scriptOrigin)) {
122: scriptSecurity = new NoLoadScriptSecurity(
123: scriptType);
124: } else {
125: throw new Error("Wrong scriptOrigin : "
126: + scriptOrigin);
127: }
128: }
129:
130: return scriptSecurity;
131: }
132: }
133:
134: }
|