You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2022/12/08 13:04:53 UTC

svn commit: r1905858 - in /xmlgraphics/fop/trunk: fop-core/src/main/java/org/apache/fop/render/intermediate/ fop-core/src/test/java/org/apache/fop/intermediate/ fop/test/intermediate/

Author: ssteiner
Date: Thu Dec  8 13:04:53 2022
New Revision: 1905858

URL: http://svn.apache.org/viewvc?rev=1905858&view=rev
Log:
FOP-3110: NPE if link destination is missing with accessibility

Added:
    xmlgraphics/fop/trunk/fop/test/intermediate/basic-link_internal-desination-missing.xml   (with props)
Modified:
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
    xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1905858&r1=1905857&r2=1905858&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java Thu Dec  8 13:04:53 2022
@@ -914,8 +914,11 @@ implements IFConstants, IFPainter, IFDoc
         atts.addAttribute("", "rect", "rect",
                 XMLConstants.CDATA, IFUtil.toString(link.getTargetRect()));
         if (getUserAgent().isAccessibilityEnabled()) {
-            addStructRefAttribute(atts,
-                    ((IFStructureTreeElement) link.getAction().getStructureTreeElement()).getId());
+            IFStructureTreeElement structureTreeElement =
+                    (IFStructureTreeElement) link.getAction().getStructureTreeElement();
+            if (structureTreeElement != null) {
+                addStructRefAttribute(atts, structureTreeElement.getId());
+            }
         }
         try {
             handler.startElement(DocumentNavigationExtensionConstants.LINK, atts);

Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java?rev=1905858&r1=1905857&r2=1905858&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java Thu Dec  8 13:04:53 2022
@@ -32,6 +32,10 @@ import javax.xml.transform.sax.SAXResult
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
 
 import org.w3c.dom.Document;
 import org.xml.sax.ErrorHandler;
@@ -105,6 +109,7 @@ abstract class AbstractIFTest extends Ab
         DOMResult domResult = new DOMResult();
 
         FOUserAgent userAgent = createUserAgent();
+        userAgent.setAccessibility(isAccessibility(testDoc));
 
         //Create an instance of the target renderer so the XMLRenderer can use its font setup
         IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(
@@ -124,9 +129,23 @@ abstract class AbstractIFTest extends Ab
         return (Document) domResult.getNode();
     }
 
+    private boolean isAccessibility(Document testDoc) {
+        try {
+            String s = eval(testDoc, "/testcase/cfg/accessibility");
+            return "true".equals(s);
+        } catch (XPathExpressionException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private String eval(Document doc, String xpath) throws XPathExpressionException {
+        XPath xPath = XPathFactory.newInstance().newXPath();
+        return (String) xPath.compile(xpath).evaluate(doc, XPathConstants.STRING);
+    }
+
     @Override
     protected void validate(Document doc) throws SAXException, IOException {
-        if (IF_SCHEMA == null) {
+        if (IF_SCHEMA == null || isAccessibility(testDoc)) {
             return; //skip validation;
         }
         Validator validator = IF_SCHEMA.newValidator();

Added: xmlgraphics/fop/trunk/fop/test/intermediate/basic-link_internal-desination-missing.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/test/intermediate/basic-link_internal-desination-missing.xml?rev=1905858&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/fop/test/intermediate/basic-link_internal-desination-missing.xml (added)
+++ xmlgraphics/fop/trunk/fop/test/intermediate/basic-link_internal-desination-missing.xml Thu Dec  8 13:04:53 2022
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+  <info>
+    <p>
+      This test checks a fo:basic-link in a span
+    </p>
+  </info>
+  <cfg>
+    <accessibility>true</accessibility>
+  </cfg>  
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+      <fo:layout-master-set>
+        <fo:simple-page-master margin-top="0.3in" master-name="MBABase" page-width="8.5in" page-height="11in">
+          <fo:region-body region-name="LetterBody"/>
+        </fo:simple-page-master>
+        <fo:page-sequence-master master-name="MBALetterPages">
+          <fo:repeatable-page-master-alternatives>
+            <fo:conditional-page-master-reference master-reference="MBABase"/>
+          </fo:repeatable-page-master-alternatives>
+        </fo:page-sequence-master>
+      </fo:layout-master-set>
+      <fo:page-sequence format="1" id="th_default_sequence5" initial-page-number="auto" master-reference="MBALetterPages">
+        <fo:flow flow-name="LetterBody">
+          <fo:block>
+            <fo:basic-link internal-destination="Section1">SECTION 1 Introduction</fo:basic-link>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <if-checks xmlns:nav="http://xmlgraphics.apache.org/fop/intermediate/document-navigation">
+    <eval expected="-1" xpath="//nav:link/nav:goto-xy/@page-index"/>
+  </if-checks>
+</testcase>

Propchange: xmlgraphics/fop/trunk/fop/test/intermediate/basic-link_internal-desination-missing.xml
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org