Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2013-10-04 12:17:31 +0000
committerCarsten Hiesserich2013-10-05 10:59:46 +0000
commite228d63c49ed12e51a6e345dd9039095003b56dd (patch)
tree7778703dd57c91f35705f265544b9797ac6ee675
parent544cb7e9d8a62a6a9720796d6239089aacef5099 (diff)
downloadorg.eclipse.mylyn.docs.vex-e228d63c49ed12e51a6e345dd9039095003b56dd.tar.gz
org.eclipse.mylyn.docs.vex-e228d63c49ed12e51a6e345dd9039095003b56dd.tar.xz
org.eclipse.mylyn.docs.vex-e228d63c49ed12e51a6e345dd9039095003b56dd.zip
fix NPE for documents with nested table row groups
Vex creates an anonymous TableBox for nested row groups. Vex tried to get pseudo elements for this anonymous boxes. This added a null key in the StyleSheet cache and caused a NPE on flushing the style sheet. Change-Id: I28f9f2bd69369ce0f579b87ad5f5d7a29c09feb5 Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java5
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.css4
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.xml32
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java10
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java9
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableBox.java19
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableRowBox.java4
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java10
8 files changed, 71 insertions, 22 deletions
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java
index 268483d2..0b829687 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java
@@ -191,11 +191,6 @@ public class TableLayoutTest {
}
@Test
- public void testInvalidNesting4() {
- test("trg", "trg");
- }
-
- @Test
public void testInvalidNesting5() {
test("tr", "tfg");
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.css b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.css
index ca4bc34e..bd997696 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.css
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.css
@@ -11,6 +11,10 @@ table {
display: table;
}
+tgroup {
+ display: table-row-group;
+}
+
tbody {
display: table-row-group;
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.xml b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.xml
index e19d2b1f..83842512 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.xml
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/tables.xml
@@ -571,5 +571,37 @@
</result>
</test>
+ <test id="Table w/ body in row group" layoutWidth="100">
+ <doc><![CDATA[ <root><table><tgroup><thead></thead><tbody><tr></tr></tbody></tgroup></table></root> ]]></doc>
+ <result>
+ <box class="RootBox">
+ <box class="BlockElementBox">
+ <box class="BlockElementBox" element="root">
+ <box class="TableBox" element="table">
+ <box class="TableBodyBox">
+ <box class="TableRowGroupBox" element="tgroup">
+ <box class="TableRowBox">
+ <box class="TableCellBox">
+ <box class="TableBox">
+ <box class="TableBodyBox">
+ <box class="TableRowGroupBox" element="thead">
+ </box>
+ <box class="TableRowGroupBox" element="tbody">
+ <box class="TableRowBox">
+
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </box>
+ </result>
+ </test>
</testcases>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java
index 657185b8..8058b870 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java
@@ -143,7 +143,10 @@ public class StyleSheet {
public void flushAllStyles(final IDocument document) {
for (final Iterator<Map.Entry<INode, Styles>> iter = styleMap.entrySet().iterator(); iter.hasNext();) {
final Map.Entry<INode, Styles> entry = iter.next();
- final IDocument nodeDoc = entry.getKey().getDocument();
+ IDocument nodeDoc = null;
+ if (entry.getKey() != null) {
+ nodeDoc = entry.getKey().getDocument();
+ }
if (nodeDoc == null || document.equals(nodeDoc)) {
// The style is also flushed if the node is not attached to an document any more.
iter.remove();
@@ -164,6 +167,11 @@ public class StyleSheet {
* @return
*/
public IElement getPseudoElement(final INode parent, final String pseudoElementName, final boolean hasContent) {
+ if (parent == null) {
+ System.out.println("Warning! StyleSheet#getPseudoElement Parent is null");
+ return null;
+ }
+
final String name = pseudoElementName.toLowerCase();
Styles styles = getStyles(parent);
if (!styles.hasPseudoElement(name)) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java
index f2468db3..5ddba71a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java
@@ -406,7 +406,7 @@ public abstract class AbstractBlockBox extends AbstractBox implements BlockBox {
@Override
public boolean hasContent() {
if (isAnonymous()) {
- return false;
+ return hasChildren();
}
return getNode().isAssociated();
}
@@ -973,9 +973,10 @@ public abstract class AbstractBlockBox extends AbstractBox implements BlockBox {
return true;
}
- // parent of 'table-row-group', table-header-group'
- // or 'table-footer-group': 'table'
- if ((style.equals(CSS.TABLE_ROW_GROUP) || style.equals(CSS.TABLE_HEADER_GROUP) || style.equals(CSS.TABLE_FOOTER_GROUP)) && !parentStyle.equals(CSS.TABLE)) {
+ // parent of 'table-row-group', table-header-group',
+ // or 'table-footer-group': 'table', 'table-row-group'
+ if ((style.equals(CSS.TABLE_ROW_GROUP) || style.equals(CSS.TABLE_HEADER_GROUP) || style.equals(CSS.TABLE_FOOTER_GROUP))
+ && !(parentStyle.equals(CSS.TABLE) || parentStyle.equals(CSS.TABLE_ROW_GROUP))) {
return true;
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableBox.java
index 55ad8fc3..e0933d1a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableBox.java
@@ -59,10 +59,13 @@ public class TableBox extends AbstractBlockBox {
final StyleSheet styleSheet = context.getStyleSheet();
// :before content
- final IElement before = styleSheet.getPseudoElement(node, CSS.PSEUDO_BEFORE, true);
- if (before != null) {
- // before element of tables is always displayed as block
- children.add(new BlockPseudoElementBox(context, before, this, width));
+ if (!isAnonymous()) {
+ // This might be an anonymous box if we have nested TABLE-ROW-GROUP's
+ final IElement before = styleSheet.getPseudoElement(node, CSS.PSEUDO_BEFORE, true);
+ if (before != null) {
+ // before element of tables is always displayed as block
+ children.add(new BlockPseudoElementBox(context, before, this, width));
+ }
}
iterateChildrenByDisplayStyle(context.getStyleSheet(), captionOrColumnStyles, new ElementOrRangeCallback() {
@@ -76,9 +79,11 @@ public class TableBox extends AbstractBlockBox {
});
// :after content
- final IElement after = styleSheet.getPseudoElement(node, CSS.PSEUDO_AFTER, true);
- if (after != null) {
- children.add(new BlockPseudoElementBox(context, after, this, width));
+ if (!isAnonymous()) {
+ final IElement after = styleSheet.getPseudoElement(node, CSS.PSEUDO_AFTER, true);
+ if (after != null) {
+ children.add(new BlockPseudoElementBox(context, after, this, width));
+ }
}
return children;
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableRowBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableRowBox.java
index 08c28523..dffdcc0c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableRowBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TableRowBox.java
@@ -95,7 +95,9 @@ public class TableRowBox extends AbstractBlockBox {
final Box child = children[i];
if (!child.hasContent()) {
- continue; // TODO can we really have generated table cells?
+ // We end here if the child is a generated TableCellBox with no childs
+ // This happens when there are nested TABLE-ROW-GROUP's
+ continue;
}
if (offset < child.getStartOffset()) {
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
index c09b77fd..51d50bb0 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
@@ -699,7 +699,7 @@ public class VexEditor extends EditorPart {
final IDocumentProvider provider = getDocumentProvider();
- IValidator validator;
+ IValidator validator = null;
VexDocumentContentModel documentContentModel;
try {
@@ -707,9 +707,13 @@ public class VexEditor extends EditorPart {
vexEditorListeners.fireEvent("documentUnloaded", new VexEditorEvent(this)); //$NON-NLS-1$
}
if (document != null) {
+ document.removeDocumentListener(documentListener);
validator = document.getValidator();
+ }
+
+ // Reuse the validator from current document
+ if (validator != null) {
documentContentModel = (VexDocumentContentModel) validator.getDocumentContentModel();
- document.removeDocumentListener(documentListener);
} else {
documentContentModel = new VexDocumentContentModel(getSite().getShell());
validator = new WTPVEXValidator(documentContentModel);
@@ -811,9 +815,7 @@ public class VexEditor extends EditorPart {
} catch (final Exception ex) {
final String msg = MessageFormat.format(Messages.getString("VexEditor.unexpectedError"), getEditorInput().getName()); //$NON-NLS-1$
-
VexPlugin.getDefault().log(IStatus.ERROR, msg, ex);
-
showLabel(msg, ex);
}

Back to the top