You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by de...@apache.org on 2003/08/28 01:33:22 UTC
cvs commit: xml-batik/test-sources/org/apache/batik/bridge ExternalResourcesTest.java
deweese 2003/08/27 16:33:22
Modified: samples/tests/spec/scripting eventAttrAdd.svg
sources/org/apache/batik/bridge FontFace.java
SVGAltGlyphHandler.java
test-resources/org/apache/batik/bridge
externalResourcesAccess.svg unitTesting.xml
test-sources/org/apache/batik/bridge
ExternalResourcesTest.java
Log:
1) Better user notification when fetching a font face fails for
security reasons.
2) Improved the external resource access test.
Revision Changes Path
1.2 +7 -2 xml-batik/samples/tests/spec/scripting/eventAttrAdd.svg
Index: eventAttrAdd.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/tests/spec/scripting/eventAttrAdd.svg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- eventAttrAdd.svg 14 Aug 2003 00:53:51 -0000 1.1
+++ eventAttrAdd.svg 27 Aug 2003 23:33:22 -0000 1.2
@@ -95,7 +95,12 @@
root.removeAttributeNS(null, "onzoom");
setRect('c', 'gold'); // It should stay gold.
root.currentScale = 1.0;
- if (inRegard)
+ if (inRegard) {
+ setTimeout(done, 500);
+ }
+ }
+
+ function done() {
regardTestInstance.scriptDone();
}
1.4 +36 -3 xml-batik/sources/org/apache/batik/bridge/FontFace.java
Index: FontFace.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/FontFace.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FontFace.java 9 Aug 2003 16:58:37 -0000 1.3
+++ FontFace.java 27 Aug 2003 23:33:22 -0000 1.4
@@ -75,7 +75,8 @@
* @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
* @version $Id$
*/
-public abstract class FontFace extends GVTFontFace {
+public abstract class FontFace extends GVTFontFace
+ implements ErrorConstants {
static Set fontSet;
static {
@@ -153,6 +154,14 @@
GVTFontFamily ff = getFontFamily(ctx, (ParsedURL)o);
if (ff != null)
return ff;
+ } catch (SecurityException ex) {
+ // Security violation notify the user but keep going.
+ ctx.getUserAgent().displayError(ex);
+ } catch (BridgeException ex) {
+ // If Security violation notify
+ // the user but keep going.
+ if (ERR_URI_UNSECURE.equals(ex.getCode()))
+ ctx.getUserAgent().displayError(ex);
} catch (Throwable t) {
// Do nothing couldn't get Referenced URL.
}
@@ -168,9 +177,33 @@
protected GVTFontFamily getFontFamily(BridgeContext ctx,
ParsedURL purl) {
String purlStr = purl.toString();
+
+ Element e = getBaseElement(ctx);
+ SVGDocument svgDoc = (SVGDocument)e.getOwnerDocument();
+ String docURL = svgDoc.getURL();
+ ParsedURL pDocURL = null;
+ if (docURL != null)
+ pDocURL = new ParsedURL(docURL);
+
+ // try to load an SVG document
+ String baseURI = XMLBaseSupport.getCascadedXMLBase(e);
+ purl = new ParsedURL(baseURI, purlStr);
+ UserAgent userAgent = ctx.getUserAgent();
+
+ try {
+ userAgent.checkLoadExternalResource(purl, pDocURL);
+ } catch (SecurityException ex) {
+ // Can't load font - Security violation.
+ // We should not throw the error that is for certain, just
+ // move down the font list, but do we display the error or not???
+ // I'll vote yes just because it is a security exception (other
+ // exceptions like font not available etc I would skip).
+ userAgent.displayError(ex);
+ return null;
+ }
+
if (purl.getRef() != null) {
// Reference must be to a SVGFont.
- Element e = getBaseElement(ctx);
Element ref = ctx.getReferencedElement(e, purlStr);
if (!ref.getNamespaceURI().equals(SVG_NAMESPACE_URI) ||
!ref.getLocalName().equals(SVG_FONT_TAG)) {
1.8 +6 -5 xml-batik/sources/org/apache/batik/bridge/SVGAltGlyphHandler.java
Index: SVGAltGlyphHandler.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGAltGlyphHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SVGAltGlyphHandler.java 8 Aug 2003 11:38:51 -0000 1.7
+++ SVGAltGlyphHandler.java 27 Aug 2003 23:33:22 -0000 1.8
@@ -93,14 +93,15 @@
* @return The GVTGlyphVector containing the alternate glyphs, or null if
* the alternate glyphs could not be found.
*/
- public GVTGlyphVector createGlyphVector(FontRenderContext frc, float fontSize,
- AttributedCharacterIterator aci) {
+ public GVTGlyphVector createGlyphVector
+ (FontRenderContext frc, float fontSize,
+ AttributedCharacterIterator aci) {
try {
if (textElement.getTagName().equals(SVG_ALT_GLYPH_TAG)) {
SVGAltGlyphElementBridge altGlyphBridge
= (SVGAltGlyphElementBridge)ctx.getBridge(textElement);
- Glyph[] glyphArray
- = altGlyphBridge.createAltGlyphArray(ctx, textElement, fontSize, aci);
+ Glyph[] glyphArray = altGlyphBridge.createAltGlyphArray
+ (ctx, textElement, fontSize, aci);
if (glyphArray != null) {
return new SVGGVTGlyphVector(null, glyphArray, frc);
}
1.3 +2 -2 xml-batik/test-resources/org/apache/batik/bridge/externalResourcesAccess.svg
Index: externalResourcesAccess.svg
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/bridge/externalResourcesAccess.svg,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- externalResourcesAccess.svg 8 Aug 2003 11:39:42 -0000 1.2
+++ externalResourcesAccess.svg 27 Aug 2003 23:33:22 -0000 1.3
@@ -65,7 +65,7 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:test="http://xml.apache.org/batik/test"
width="450" height="500" viewBox="0 0 450 500"
- test:targetids="use, image, feImage, tref, textPath, color-profile, linearGradientA, linearGradientB, radialGradientA, radialGradientB, patternA, patternB, filterA, filterB , font-face-uri">
+ test:targetids="use, image, feImage, tref, textPath, color-profile, linearGradientA, linearGradientB, radialGradientA, radialGradientB, patternA, patternB, filterA,filterB , font-face-uri, altGlyph, glyphRef">
<script><![CDATA[
1.8 +3 -3 xml-batik/test-resources/org/apache/batik/bridge/unitTesting.xml
Index: unitTesting.xml
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/bridge/unitTesting.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- unitTesting.xml 8 Aug 2003 11:39:42 -0000 1.7
+++ unitTesting.xml 27 Aug 2003 23:33:22 -0000 1.8
@@ -116,10 +116,10 @@
value="false" />
</test>
- <test id="externalResourcesAccess"
+ <test id="externalResourcesAccess.secure"
class="org.apache.batik.bridge.ExternalResourcesTest" />
- <test id="externalResourcesAccess"
+ <test id="externalResourcesAccess.unsecure"
class="org.apache.batik.bridge.ExternalResourcesTest" >
<property name="Secure" class="java.lang.Boolean"
value="false" />
1.5 +83 -37 xml-batik/test-sources/org/apache/batik/bridge/ExternalResourcesTest.java
Index: ExternalResourcesTest.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/bridge/ExternalResourcesTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExternalResourcesTest.java 9 Aug 2003 16:58:43 -0000 1.4
+++ ExternalResourcesTest.java 27 Aug 2003 23:33:22 -0000 1.5
@@ -62,6 +62,7 @@
import org.w3c.dom.Node;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
+import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.test.AbstractTest;
import org.apache.batik.test.DefaultTestReport;
import org.apache.batik.test.TestReport;
@@ -93,7 +94,8 @@
* @version $Id$
*/
-public class ExternalResourcesTest extends AbstractTest {
+public class ExternalResourcesTest extends AbstractTest
+ implements ErrorConstants {
/**
* Error when the input file cannot be loaded into a
* Document object
@@ -179,6 +181,11 @@
public static final String INSERTION_POINT_ID = "insertionPoint";
/**
+ * Location of test files in filesystem.
+ */
+ public static final String FILE_DIR =
+ "test-resources/org/apache/batik/bridge/";
+ /**
* Controls whether the test works in secure mode or not
*/
protected boolean secure = true;
@@ -187,7 +194,12 @@
public void setId(String id){
super.setId(id);
- svgURL = resolveURL("test-resources/org/apache/batik/bridge/" + id + ".svg");
+ String file = id;
+ int idx = file.indexOf('.');
+ if (idx != -1) {
+ file = file.substring(0,idx);
+ }
+ svgURL = resolveURL(FILE_DIR + file + ".svg");
}
public Boolean getSecure(){
@@ -267,32 +279,40 @@
// Do an initial processing to validate that the external
// stylesheet causes a SecurityException
//
- UserAgent userAgent = buildUserAgent();
+ MyUserAgent userAgent = buildUserAgent();
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
ctx.setDynamic(true);
// We expect either a SecurityException or a BridgeException
// with ERR_URI_UNSECURE.
+ Throwable th = null;
try {
- builder.build(ctx, doc);
- if (secure) {
- failures.addElement(EXTERNAL_STYLESHEET_ID);
- }
+ GraphicsNode gn = builder.build(ctx, doc);
+ gn.getBounds();
+ th = userAgent.getDisplayError();
} catch (BridgeException e){
- if (!secure
- ||
- (secure && !ErrorConstants.ERR_URI_UNSECURE.equals(e.getCode()))) {
+ th = e;
+ } catch (SecurityException e) {
+ th = e;
+ } catch (Throwable t) {
+ th = t;
+ }
+ if (th == null) {
+ if (secure)
+ failures.addElement(EXTERNAL_STYLESHEET_ID);
+ } else if (th instanceof SecurityException) {
+ if (!secure)
+ failures.addElement(EXTERNAL_STYLESHEET_ID);
+ } else if (th instanceof BridgeException) {
+ BridgeException be = (BridgeException)th;
+ if (!secure ||
+ (secure && !ERR_URI_UNSECURE.equals(be.getCode()))) {
report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
- e.getMessage());
+ be.getMessage());
report.setPassed(false);
return report;
- }
-
- } catch (SecurityException e) {
- if (!secure) {
- failures.addElement(EXTERNAL_STYLESHEET_ID);
}
}
@@ -355,29 +375,43 @@
}
insertionPoint.appendChild(target);
-
+ th = null;
try {
- builder.build(ctx, cloneDoc);
- if (secure) {
- // If we get here, it means that no SecurityException
- // was thrown, which is wrong.
- failures.addElement(id);
- }
+ GraphicsNode gn = builder.build(ctx, cloneDoc);
+ gn.getBounds();
+ th = userAgent.getDisplayError();
} catch (BridgeException e){
- if (!secure
- ||
- (secure && !ErrorConstants.ERR_URI_UNSECURE.equals(e.getCode()))) {
+ th = e;
+ } catch (SecurityException e) {
+ th = e;
+ } catch (Throwable t) {
+ th = t;
+ }
+ if (th == null) {
+ if (secure)
+ failures.addElement(id);
+ } else if (th instanceof SecurityException) {
+ if (!secure)
+ failures.addElement(id);
+ } else if (th instanceof BridgeException) {
+ BridgeException be = (BridgeException)th;
+ if (!secure ||
+ (secure && !ERR_URI_UNSECURE.equals(be.getCode()))) {
report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
- e.getMessage());
+ be.getMessage());
report.setPassed(false);
return report;
}
- } catch (SecurityException e) {
- if (!secure) {
- failures.addElement(id);
- }
+ } else {
+ // Some unknown exception was displayed...
+ report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
+ report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
+ th.getMessage());
+ report.setPassed(false);
+ return report;
}
+
}
if (failures.size() == 0) {
@@ -402,7 +436,11 @@
return report;
}
- protected UserAgent buildUserAgent(){
+ protected interface MyUserAgent extends UserAgent {
+ public Exception getDisplayError();
+ }
+
+ protected MyUserAgent buildUserAgent(){
if (secure) {
return new SecureUserAgent();
} else {
@@ -410,17 +448,26 @@
}
}
- class SecureUserAgent extends UserAgentAdapter {
+ class MyUserAgentAdapter extends UserAgentAdapter implements MyUserAgent {
+ Exception ex = null;
+ public void displayError(Exception ex) {
+ this.ex = ex;
+ super.displayError(ex);
+ }
+
+ public Exception getDisplayError() { return ex; }
+ }
+
+ class SecureUserAgent extends MyUserAgentAdapter {
public ExternalResourceSecurity
getExternalResourceSecurity(ParsedURL resourcePURL,
ParsedURL docPURL){
return new NoLoadExternalResourceSecurity();
}
-
}
- class RelaxedUserAgent extends UserAgentAdapter {
+ class RelaxedUserAgent extends MyUserAgentAdapter {
public ExternalResourceSecurity
getExternalResourceSecurity(ParsedURL resourcePURL,
ParsedURL docPURL){
@@ -428,7 +475,6 @@
docPURL);
}
-
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org