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 je...@apache.org on 2008/03/06 20:13:04 UTC
svn commit: r634381 - in
/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java:
META-INF/services/ org/apache/fop/events/ org/apache/fop/fo/
org/apache/fop/fo/flow/ org/apache/fop/util/text/
Author: jeremias
Date: Thu Mar 6 11:12:57 2008
New Revision: 634381
URL: http://svn.apache.org/viewvc?rev=634381&view=rev
Log:
Made the "invalidChild" event fully localizable by adding a "lookup" field for the optional rule to be displayed.
And a few switches to the event system.
Modified:
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.util.text.AdvancedMessageFormat$PartFactory
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FONode.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventProducer.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/AbstractListItemPart.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BasicLink.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BidiOverride.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Inline.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Marker.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/util/text/AdvancedMessageFormat.java
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.util.text.AdvancedMessageFormat$PartFactory
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.util.text.AdvancedMessageFormat%24PartFactory?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.util.text.AdvancedMessageFormat$PartFactory (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.util.text.AdvancedMessageFormat$PartFactory Thu Mar 6 11:12:57 2008
@@ -1,2 +1,3 @@
org.apache.fop.util.text.IfFieldPart$Factory
org.apache.fop.util.text.EqualsFieldPart$Factory
+org.apache.fop.events.EventFormatter$LookupFieldPartFactory
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.java Thu Mar 6 11:12:57 2008
@@ -27,6 +27,8 @@
import org.apache.fop.util.XMLResourceBundle;
import org.apache.fop.util.text.AdvancedMessageFormat;
+import org.apache.fop.util.text.AdvancedMessageFormat.Part;
+import org.apache.fop.util.text.AdvancedMessageFormat.PartFactory;
/**
* Converts events into human-readable, localized messages.
@@ -90,4 +92,46 @@
return format.format(params);
}
+ private static class LookupFieldPart implements Part {
+
+ private String fieldName;
+
+ public LookupFieldPart(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public boolean isGenerated(Map params) {
+ return getKey(params) != null;
+ }
+
+ public void write(StringBuffer sb, Map params) {
+ sb.append(defaultBundle.getString(getKey(params)));
+ }
+
+ private String getKey(Map params) {
+ return (String)params.get(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "{" + this.fieldName + ", lookup}";
+ }
+
+ }
+
+ /** PartFactory for lookups. */
+ public static class LookupFieldPartFactory implements PartFactory {
+
+ /** {@inheritDoc} */
+ public Part newPart(String fieldName, String values) {
+ return new LookupFieldPart(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ public String getFormat() {
+ return "lookup";
+ }
+
+ }
+
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml Thu Mar 6 11:12:57 2008
@@ -18,9 +18,13 @@
<!-- $Id$ -->
<catalogue xml:lang="en">
<message key="locator">[ (See position {loc})| (See {#gatherContextInfo})| (No context info available)]</message>
+ <message key="rule.markerDescendantOfFlow">An fo:marker is permitted only as the descendant of an fo:flow.</message>
+ <message key="rule.retrieveMarkerDescendatOfStaticContent">An fo:retrieve-marker is permitted only as the descendant of an fo:static-content.</message>
+ <message key="rule.bidiOverrideContent">An fo:bidi-override that is a descendant of an fo:leader or of the fo:inline child of an fo:footnote may not have block-level children, unless it has a nearer ancestor that is an fo:inline-container.</message>
+ <message key="rule.inlineContent">An fo:inline that is a descendant of an fo:leader or fo:footnote may not have block-level children, unless it has a nearer ancestor that is an fo:inline-container.</message>
<message key="org.apache.fop.fo.FOValidationEventProducer.tooManyNodes">For "{elementName}", only one "{offendingNode}" may be declared.{{locator}}</message>
<message key="org.apache.fop.fo.FOValidationEventProducer.nodeOutOfOrder">For "{elementName}", "{tooLateNode}" must be declared before "{tooEarlyNode}"!{{locator}}</message>
- <message key="org.apache.fop.fo.FOValidationEventProducer.invalidChild">"{offendingNode}" is not a valid child element of "{elementName}"![ {ruleViolated}]{{locator}}</message>
+ <message key="org.apache.fop.fo.FOValidationEventProducer.invalidChild">"{offendingNode}" is not a valid child element of "{elementName}"![ {ruleViolated,lookup}]{{locator}}</message>
<message key="org.apache.fop.fo.FOValidationEventProducer.missingChildElement">"{elementName}" is missing child elements.
Required content model: {contentModel}{{locator}}</message>
<message key="org.apache.fop.fo.FOValidationEventProducer.missingProperty">Element "{elementName}" is missing required property "{propertyName}"!{{locator}}</message>
@@ -41,4 +45,5 @@
<message key="org.apache.fop.fo.flow.table.TableEventProducer.warnImplicitColumns">table-layout=\"fixed\" and column-width unspecified => falling back to proportional-column-width(1){{locator}}</message>
<message key="org.apache.fop.fo.flow.table.TableEventProducer.paddingNotApplicable">padding-* properties are not applicable to {elementName}, but a non-zero value for padding was found.{{locator}}</message>
<message key="org.apache.fop.fo.flow.table.TableEventProducer.cellOverlap">{elementName} overlaps in column {column}.<!-- no locator here, exception will be wrapped --></message>
+ <message key="org.apache.fop.fo.FOValidationEventProducer.missingLinkDestination">Missing attribute on {elementName}: Either external-destination or internal-destination must be specified.{{locator}}</message>
</catalogue>
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FONode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FONode.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FONode.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FONode.java Thu Mar 6 11:12:57 2008
@@ -460,7 +460,7 @@
*/
protected void invalidChildError(Locator loc, String nsURI, String lName)
throws ValidationException {
- invalidChildError(loc, nsURI, lName, null);
+ invalidChildError(loc, getName(), nsURI, lName, null);
}
/**
@@ -469,14 +469,13 @@
* @param loc org.xml.sax.Locator object of the error (*not* parent node)
* @param nsURI namespace URI of incoming invalid node
* @param lName local name (i.e., no prefix) of incoming node
- * @param ruleViolated text explanation of problem
+ * @param ruleViolated name of the rule violated (used to lookup a resource in a bundle)
* @throws ValidationException the validation error provoked by the method call
*/
- protected void invalidChildError(Locator loc, String nsURI, String lName,
+ protected void invalidChildError(Locator loc, String parentName, String nsURI, String lName,
String ruleViolated)
throws ValidationException {
- //TODO Localize ruleViolated somehow!
- getFOValidationEventProducer().invalidChild(this, getName(),
+ getFOValidationEventProducer().invalidChild(this, parentName,
new QName(nsURI, lName), ruleViolated, loc);
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventProducer.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventProducer.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventProducer.java Thu Mar 6 11:12:57 2008
@@ -184,4 +184,15 @@
void unimplementedFeature(Object source, String elementName, String feature,
Locator loc);
+ /**
+ * Missing internal-/external-destination on basic-link.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method call
+ * @event.severity FATAL
+ */
+ void missingLinkDestination(Object source, String elementName, Locator loc)
+ throws ValidationException;
+
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/AbstractListItemPart.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/AbstractListItemPart.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/AbstractListItemPart.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/AbstractListItemPart.java Thu Mar 6 11:12:57 2008
@@ -79,17 +79,8 @@
protected void endOfNode() throws FOPException {
if (!this.blockItemFound) {
String contentModel = "marker* (%block;)+";
- if (getUserAgent().validateStrictly()) {
- missingChildElementError(contentModel);
- } else {
- StringBuffer message = new StringBuffer(
- errorText(getLocator()));
- message.append(getName())
- .append(" is missing child elements. ")
- .append("Required Content Model: ")
- .append(contentModel);
- log.warn(message.toString());
- }
+ getFOValidationEventProducer().missingChildElement(this, getName(),
+ contentModel, true, getLocator());
}
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BasicLink.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BasicLink.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BasicLink.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BasicLink.java Thu Mar 6 11:12:57 2008
@@ -76,8 +76,7 @@
externalDestination = null;
} else if (externalDestination.length() == 0) {
// slightly stronger than spec "should be specified"
- attributeError("Missing attribute: Either external-destination or " +
- "internal-destination must be specified.");
+ getFOValidationEventProducer().missingLinkDestination(this, getName(), locator);
}
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BidiOverride.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BidiOverride.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BidiOverride.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/BidiOverride.java Thu Mar 6 11:12:57 2008
@@ -19,13 +19,14 @@
package org.apache.fop.fo.flow;
+import org.xml.sax.Locator;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObjMixed;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.ValidationException;
import org.apache.fop.fo.properties.SpaceProperty;
-import org.xml.sax.Locator;
/**
* Class modelling the fo:bidi-override object.
@@ -105,11 +106,8 @@
} else if (!isBlockOrInlineItem(nsURI, localName)) {
invalidChildError(loc, nsURI, localName);
} else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) {
- String ruleViolated = "An fo:bidi-override"
- + " that is a descendant of an fo:leader or of the fo:inline child"
- + " of an fo:footnote may not have block-level children, unless it"
- + " has a nearer ancestor that is an fo:inline-container.";
- invalidChildError(loc, nsURI, localName, ruleViolated);
+ invalidChildError(loc, getParent().getName(), nsURI, getName(),
+ "rule.bidiOverrideContent");
} else {
blockOrInlineItemFound = true;
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Inline.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Inline.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Inline.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Inline.java Thu Mar 6 11:12:57 2008
@@ -81,8 +81,8 @@
int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
if (lvlLeader > 0) {
- if (lvlInCntr < 0 ||
- (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
+ if (lvlInCntr < 0
+ || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
canHaveBlockLevelChildren = false;
}
} else if (lvlFootnote > 0) {
@@ -119,12 +119,7 @@
} else if (!isBlockOrInlineItem(nsURI, localName)) {
invalidChildError(loc, nsURI, localName);
} else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) {
- String ruleViolated =
- " An fo:inline that is a descendant of an fo:leader" +
- " or fo:footnote may not have block-level children," +
- " unless it has a nearer ancestor that is an" +
- " fo:inline-container.";
- invalidChildError(loc, nsURI, localName, ruleViolated);
+ invalidChildError(loc, getParent().getName(), nsURI, getName(), "rule.inlineContent");
} else {
blockOrInlineItemFound = true;
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Marker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Marker.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Marker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/Marker.java Thu Mar 6 11:12:57 2008
@@ -59,9 +59,8 @@
*/
public void bind(PropertyList pList) throws FOPException {
if (findAncestor(FO_FLOW) < 0) {
- invalidChildError(locator, FO_URI, "marker",
- "An fo:marker is permitted only as the descendant "
- + "of an fo:flow");
+ invalidChildError(locator, getParent().getName(), FO_URI, getName(),
+ "rule.markerDescendantOfFlow");
}
markerClassName = pList.get(PR_MARKER_CLASS_NAME).getString();
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/RetrieveMarker.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/RetrieveMarker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/RetrieveMarker.java Thu Mar 6 11:12:57 2008
@@ -21,6 +21,8 @@
import java.util.Iterator;
+import org.xml.sax.Locator;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FOText;
@@ -30,7 +32,6 @@
import org.apache.fop.fo.ValidationException;
import org.apache.fop.fo.flow.table.Table;
import org.apache.fop.fo.flow.table.TableFObj;
-import org.xml.sax.Locator;
/**
* Class modelling the fo:retrieve-marker object.
@@ -60,9 +61,8 @@
*/
public void bind(PropertyList pList) throws FOPException {
if (findAncestor(FO_STATIC_CONTENT) < 0) {
- invalidChildError(locator, FO_URI, "retrieve-marker",
- "An fo:retrieve-marker is permitted only as the " +
- " descendant of an fo:static-content.");
+ invalidChildError(locator, getParent().getName(), FO_URI, getName(),
+ "rule.retrieveMarkerDescendatOfStaticContent");
}
retrieveClassName = pList.get(PR_RETRIEVE_CLASS_NAME).getString();
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/util/text/AdvancedMessageFormat.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/util/text/AdvancedMessageFormat.java?rev=634381&r1=634380&r2=634381&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/util/text/AdvancedMessageFormat.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/util/text/AdvancedMessageFormat.java Thu Mar 6 11:12:57 2008
@@ -160,15 +160,16 @@
}
} else {
String format = parts[1];
- if (parts.length == 2) {
- throw new IllegalArgumentException("Pattern must have three parts!");
- }
PartFactory factory = (PartFactory)PART_FACTORIES.get(format);
if (factory == null) {
throw new IllegalArgumentException(
"No PartFactory available under the name: " + format);
}
- return factory.newPart(fieldName, parts[2]);
+ if (parts.length == 2) {
+ return factory.newPart(fieldName, null);
+ } else {
+ return factory.newPart(fieldName, parts[2]);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org