Author: jeremias
Date: Thu Feb 7 01:31:00 2008
New Revision: 619320
URL: http://svn.apache.org/viewvc?rev=619320&view=rev
Log:
FObj hooked into the event system.
Code reduction using a protected method on FONode to acquire a
FOValidationEventProducer.
Modified:
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/FObj.java
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=619320&r1=619319&r2=619320&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 Feb 7 01:31:00 2008
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
+<?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.
@@ -23,4 +22,9 @@
<message
key="org.apache.fop.fo.FOValidationEventProducer.missingChildElement">"{elementName}"
is missing child elements.
Required content model: {contentModel}[ See position {loc}.]</message>
<message
key="org.apache.fop.fo.FOValidationEventProducer.missingProperty">Element
"{elementName}" is missing required property "{propertyName}"![ See position
{loc}.]</message>
+ <message
key="org.apache.fop.fo.FOValidationEventProducer.idNotUnique">Property ID
"{id}" (found on "{elementName}") previously used; ID values must be unique
within a document![ See position {loc}.]</message>
+ <message
key="org.apache.fop.fo.FOValidationEventProducer.idNotUniqueWarning">Found
non-unique ID "{id}" on "{elementName}".
+Any reference to it will be considered a reference to the first occurrence in
the document.[ See position {loc}.]</message>
+ <message
key="org.apache.fop.fo.FOValidationEventProducer.markerNotInitialChild">fo:marker
must be an initial child: {mcname}[ (See position {loc}.)]</message>
+ <message
key="org.apache.fop.fo.FOValidationEventProducer.markerNotUniqueForSameParent">fo:marker
"marker-class-name" must be unique for same parent: {mcname}[ (See position
{loc}.)]</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=619320&r1=619319&r2=619320&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 Feb 7 01:31:00 2008
@@ -346,6 +346,15 @@
}
/**
+ * Returns an instance of the FOValidationEventProducer.
+ * @return an event producer for FO validation
+ */
+ protected FOValidationEventProducer getFOValidationEventProducer() {
+ return FOValidationEventProducer.Factory.create(
+ getUserAgent().getEventBroadcaster());
+ }
+
+ /**
* Helper function to standardize property error exceptions
* (e.g., not specifying either an internal- or an external-destination
* property for an FO:link)
@@ -389,9 +398,7 @@
*/
protected void tooManyNodesError(Locator loc, QName offendingNode)
throws ValidationException {
- FOValidationEventProducer producer =
FOValidationEventProducer.Factory.create(
- getUserAgent().getEventBroadcaster());
- producer.tooManyNodes(this, getName(), offendingNode, loc);
+ getFOValidationEventProducer().tooManyNodes(this, getName(),
offendingNode, loc);
}
/**
@@ -417,9 +424,7 @@
*/
protected void nodesOutOfOrderError(Locator loc, String tooLateNode,
String tooEarlyNode) throws ValidationException {
- FOValidationEventProducer producer =
FOValidationEventProducer.Factory.create(
- getUserAgent().getEventBroadcaster());
- producer.nodeOutOfOrder(this, getName(), tooLateNode, tooEarlyNode,
loc);
+ getFOValidationEventProducer().nodeOutOfOrder(this, getName(),
tooLateNode, tooEarlyNode, loc);
}
/**
@@ -447,10 +452,9 @@
protected void invalidChildError(Locator loc, String nsURI, String lName,
String ruleViolated)
throws ValidationException {
- FOValidationEventProducer producer =
FOValidationEventProducer.Factory.create(
- getUserAgent().getEventBroadcaster());
//TODO Localize ruleViolated somehow!
- producer.invalidChild(this, getName(), new QName(nsURI, lName),
ruleViolated, loc);
+ getFOValidationEventProducer().invalidChild(this, getName(),
+ new QName(nsURI, lName), ruleViolated, loc);
}
/**
@@ -462,9 +466,7 @@
*/
protected void missingChildElementError(String contentModel)
throws ValidationException {
- FOValidationEventProducer producer =
FOValidationEventProducer.Factory.create(
- getUserAgent().getEventBroadcaster());
- producer.missingChildElement(this, getName(), contentModel, locator);
+ getFOValidationEventProducer().missingChildElement(this, getName(),
contentModel, locator);
}
/**
@@ -474,9 +476,7 @@
*/
protected void missingPropertyError(String propertyName)
throws ValidationException {
- FOValidationEventProducer producer =
FOValidationEventProducer.Factory.create(
- getUserAgent().getEventBroadcaster());
- producer.missingProperty(this, getName(), propertyName, locator);
+ getFOValidationEventProducer().missingProperty(this, getName(),
propertyName, locator);
}
/**
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=619320&r1=619319&r2=619320&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 Feb 7 01:31:00 2008
@@ -26,55 +26,127 @@
import org.apache.fop.events.EventBroadcaster;
import org.apache.fop.events.EventProducer;
+/**
+ * Event producer interface for XSL-FO validation messages.
+ */
public interface FOValidationEventProducer extends EventProducer {
/**
+ * Factory class for the event producer.
+ */
+ class Factory {
+
+ /**
+ * Creates a new event producer.
+ * @param broadcaster the event broadcaster to use
+ * @return the new event producer
+ */
+ public static FOValidationEventProducer create(EventBroadcaster
broadcaster) {
+ return (FOValidationEventProducer)broadcaster.getEventProducerFor(
+ FOValidationEventProducer.class);
+ }
+ }
+
+ /**
* Too many child nodes.
- * @param source
* @param source the event source
* @param elementName the name of the context node
* @param offendingNode the offending node
* @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method
call
* @event.severity FATAL
*/
void tooManyNodes(Object source, String elementName, QName offendingNode,
Locator loc) throws ValidationException;
+ /**
+ * The node order is wrong.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param tooLateNode string name of node that should be earlier in
document
+ * @param tooEarlyNode string name of node that should be later in document
+ * @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method
call
+ */
void nodeOutOfOrder(Object source, String elementName, String tooLateNode,
String tooEarlyNode,
Locator loc) throws ValidationException;
+ /**
+ * An invalid child was encountered.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param offendingNode the offending node
+ * @param ruleViolated the rule that was violated or null
+ * @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method
call
+ */
void invalidChild(Object source, String elementName, QName offendingNode,
String ruleViolated,
Locator loc) throws ValidationException;
+ /**
+ * A required child element is missing.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param contentModel the expected content model
+ * @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method
call
+ */
void missingChildElement(Object source, String elementName, String
contentModel,
- Locator locator) throws ValidationException;
+ Locator loc) throws ValidationException;
/**
* An element is missing a required property.
* @param source the event source
* @param elementName the name of the context node
* @param propertyName the name of the missing property
+ * @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method
call
* @event.severity FATAL
*/
void missingProperty(Object source, String elementName, String
propertyName,
Locator loc) throws ValidationException;
/**
- * Factory class for the event producer.
+ * An id was used twice in a document.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param id the id that was reused
+ * @param loc the location of the error or null
+ * @throws ValidationException the validation error provoked by the method
call
+ * @event.severity FATAL
*/
- public class Factory {
-
- /**
- * Creates a new event producer.
- * @param broadcaster the event broadcaster to use
- * @return the new event producer
- */
- public static FOValidationEventProducer create(EventBroadcaster
broadcaster) {
- return (FOValidationEventProducer)broadcaster.getEventProducerFor(
- FOValidationEventProducer.class);
- }
- }
+ void idNotUnique(Object source, String elementName, String id,
+ Locator loc) throws ValidationException;
+
+ /**
+ * An id was used twice in a document.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param id the id that was reused
+ * @param loc the location of the error or null
+ * @event.severity WARN
+ */
+ void idNotUniqueWarning(Object source, String elementName, String id,
Locator loc);
+ /**
+ * A marker is not an initial child on a node.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param mcname the marker class name
+ * @param loc the location of the error or null
+ * @event.severity ERROR
+ */
+ void markerNotInitialChild(Object source, String elementName, String
mcname, Locator loc);
+
+ /**
+ * A marker class name is not unique within the same parent.
+ * @param source the event source
+ * @param elementName the name of the context node
+ * @param mcname the marker class name
+ * @param loc the location of the error or null
+ * @event.severity ERROR
+ */
+ void markerNotUniqueForSameParent(Object source, String elementName,
+ String mcname, Locator loc);
-
}
Modified:
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FObj.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FObj.java?rev=619320&r1=619319&r2=619320&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FObj.java
(original)
+++
xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FObj.java
Thu Feb 7 01:31:00 2008
@@ -27,13 +27,14 @@
import java.util.NoSuchElementException;
import java.util.Set;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.extensions.ExtensionAttachment;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.properties.PropertyMaker;
import org.apache.fop.util.QName;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
/**
* Base class for representation of formatting objects and their processing.
@@ -172,23 +173,9 @@
idrefs.add(id);
} else {
if (getUserAgent().validateStrictly()) {
- throw new ValidationException("Property id \"" + id
- + "\" previously used; id values must be unique"
- + " in document.", locator);
+ getFOValidationEventProducer().idNotUnique(this,
getName(), id, locator);
} else {
- if (log.isWarnEnabled()) {
- StringBuffer msg = new StringBuffer();
- msg.append("Found non-unique id on
").append(getName());
- if (locator.getLineNumber() != -1) {
- msg.append(" (at ").append(locator.getLineNumber())
- .append("/").append(locator.getColumnNumber())
- .append(")");
- }
- msg.append("\nAny reference to it will be considered "
- + "a reference to the first occurrence "
- + "in the document.");
- log.warn(msg);
- }
+ getFOValidationEventProducer().idNotUniqueWarning(this,
getName(), id, locator);
}
}
}
@@ -348,8 +335,8 @@
if (node instanceof FObj
|| (node instanceof FOText
&& ((FOText) node).willCreateArea())) {
- log.error(
- "fo:marker must be an initial child: " + mcname);
+ getFOValidationEventProducer().markerNotInitialChild(this,
getName(),
+ mcname, locator);
return;
} else if (node instanceof FOText) {
iter.remove();
@@ -363,8 +350,8 @@
if (!markers.containsKey(mcname)) {
markers.put(mcname, marker);
} else {
- log.error("fo:marker 'marker-class-name' "
- + "must be unique for same parent: " + mcname);
+ getFOValidationEventProducer().markerNotUniqueForSameParent(this,
getName(),
+ mcname, locator);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]