import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.util.QName;
+
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.Trait.Background;
import org.apache.fop.area.Trait.InternalLink;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
import org.apache.fop.util.ConversionUtils;
import org.apache.fop.util.DefaultErrorListener;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.ImageManager;
-import org.apache.xmlgraphics.image.loader.ImageSessionContext;
-import org.apache.xmlgraphics.util.QName;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
+import org.apache.fop.util.XMLUtil;
/**
* This is a parser for the area tree XML (intermediate format) which is used to reread an area
if (currentPageViewport != null) {
throw new IllegalStateException("currentPageViewport must be null");
}
- Rectangle2D viewArea = getAttributeAsRectangle2D(attributes, "bounds");
- int pageNumber = getAttributeAsInteger(attributes, "nr", -1);
+ Rectangle2D viewArea = XMLUtil.getAttributeAsRectangle2D(attributes, "bounds");
+ int pageNumber = XMLUtil.getAttributeAsInt(attributes, "nr", -1);
String key = attributes.getValue("key");
String pageNumberString = attributes.getValue("formatted-nr");
String pageMaster = attributes.getValue("simple-page-master-name");
- boolean blank = getAttributeAsBoolean(attributes, "blank", false);
+ boolean blank = XMLUtil.getAttributeAsBoolean(attributes, "blank", false);
currentPageViewport = new PageViewport(viewArea,
pageNumber, pageNumberString,
pageMaster, blank);
if (rv != null) {
throw new IllegalStateException("Current RegionViewport must be null");
}
- Rectangle2D viewArea = getAttributeAsRectangle2D(attributes, "rect");
+ Rectangle2D viewArea = XMLUtil.getAttributeAsRectangle2D(attributes, "rect");
rv = new RegionViewport(viewArea);
transferForeignObjects(attributes, rv);
- rv.setClip(getAttributeAsBoolean(attributes, "clipped", false));
+ rv.setClip(XMLUtil.getAttributeAsBoolean(attributes, "clipped", false));
setAreaAttributes(attributes, rv);
setTraits(attributes, rv, SUBSET_COMMON);
setTraits(attributes, rv, SUBSET_BOX);
throw new IllegalStateException("Current BodyRegion must be null");
}
String regionName = attributes.getValue("name");
- int columnCount = getAttributeAsInteger(attributes, "columnCount", 1);
- int columnGap = getAttributeAsInteger(attributes, "columnGap", 0);
+ int columnCount = XMLUtil.getAttributeAsInt(attributes, "columnCount", 1);
+ int columnGap = XMLUtil.getAttributeAsInt(attributes, "columnGap", 0);
RegionViewport rv = getCurrentRegionViewport();
body = new BodyRegion(Constants.FO_REGION_BODY,
regionName, rv, columnCount, columnGap);
private class SpanMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- int ipd = getAttributeAsInteger(attributes, "ipd", 0);
- int columnCount = getAttributeAsInteger(attributes, "columnCount", 1);
+ int ipd = XMLUtil.getAttributeAsInt(attributes, "ipd", 0);
+ int columnCount = XMLUtil.getAttributeAsInt(attributes, "columnCount", 1);
BodyRegion body = getCurrentBodyRegion();
Span span = new Span(columnCount,
body.getColumnGap(), ipd);
public void startElement(Attributes attributes) {
Footnote fn = getCurrentBodyRegion().getFootnote();
transferForeignObjects(attributes, fn);
- fn.setTop(getAttributeAsInteger(attributes, "top-offset", 0));
+ fn.setTop(XMLUtil.getAttributeAsInt(attributes, "top-offset", 0));
areaStack.push(fn);
}
private class BlockMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- boolean isViewport = getAttributeAsBoolean(attributes,
+ boolean isViewport = XMLUtil.getAttributeAsBoolean(attributes,
"is-viewport-area", false);
Block block;
if (isViewport) {
BlockViewport bv = new BlockViewport();
- bv.setClip(getAttributeAsBoolean(attributes, "clipped", false));
+ bv.setClip(XMLUtil.getAttributeAsBoolean(attributes, "clipped", false));
bv.setCTM(getAttributeAsCTM(attributes, "ctm"));
if (bv.getPositioning() != BlockViewport.RELATIVE) {
bv.setXOffset(
- getAttributeAsInteger(attributes, "left-position", 0));
+ XMLUtil.getAttributeAsInt(attributes, "left-position", 0));
bv.setYOffset(
- getAttributeAsInteger(attributes, "top-position", 0));
+ XMLUtil.getAttributeAsInt(attributes, "top-position", 0));
}
block = bv;
} else {
block.setPositioning(Block.STACK);
}
if (attributes.getValue("left-offset") != null) {
- block.setXOffset(getAttributeAsInteger(attributes, "left-offset", 0));
+ block.setXOffset(XMLUtil.getAttributeAsInt(attributes, "left-offset", 0));
}
if (attributes.getValue("top-offset") != null) {
- block.setYOffset(getAttributeAsInteger(attributes, "top-offset", 0));
+ block.setYOffset(XMLUtil.getAttributeAsInt(attributes, "top-offset", 0));
}
transferForeignObjects(attributes, block);
setAreaAttributes(attributes, block);
public void startElement(Attributes attributes) {
InlineArea inl = new InlineArea();
transferForeignObjects(attributes, inl);
- inl.setOffset(getAttributeAsInteger(attributes, "offset", 0));
+ inl.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0));
setAreaAttributes(attributes, inl);
setTraits(attributes, inl, SUBSET_COMMON);
setTraits(attributes, inl, SUBSET_BOX);
public void startElement(Attributes attributes) {
InlineParent ip = new InlineParent();
transferForeignObjects(attributes, ip);
- ip.setOffset(getAttributeAsInteger(attributes, "offset", 0));
+ ip.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0));
setAreaAttributes(attributes, ip);
setTraits(attributes, ip, SUBSET_COMMON);
setTraits(attributes, ip, SUBSET_BOX);
public void startElement(Attributes attributes) {
InlineBlockParent ibp = new InlineBlockParent();
transferForeignObjects(attributes, ibp);
- ibp.setOffset(getAttributeAsInteger(attributes, "offset", 0));
+ ibp.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0));
setAreaAttributes(attributes, ibp);
setTraits(attributes, ibp, SUBSET_COMMON);
setTraits(attributes, ibp, SUBSET_BOX);
setTraits(attributes, text, SUBSET_BOX);
setTraits(attributes, text, SUBSET_COLOR);
setTraits(attributes, text, SUBSET_FONT);
- text.setBaselineOffset(getAttributeAsInteger(attributes, "baseline", 0));
- text.setOffset(getAttributeAsInteger(attributes, "offset", 0));
- text.setTextLetterSpaceAdjust(getAttributeAsInteger(attributes,
+ text.setBaselineOffset(XMLUtil.getAttributeAsInt(attributes, "baseline", 0));
+ text.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0));
+ text.setTextLetterSpaceAdjust(XMLUtil.getAttributeAsInt(attributes,
"tlsadjust", 0));
- text.setTextWordSpaceAdjust(getAttributeAsInteger(attributes,
+ text.setTextWordSpaceAdjust(XMLUtil.getAttributeAsInt(attributes,
"twsadjust", 0));
Area parent = (Area)areaStack.peek();
parent.addChildArea(text);
private class WordMaker extends AbstractMaker {
public void endElement() {
- int offset = getAttributeAsInteger(lastAttributes, "offset", 0);
+ int offset = XMLUtil.getAttributeAsInt(lastAttributes, "offset", 0);
int[] letterAdjust
= ConversionUtils.toIntArray(
lastAttributes.getValue("letter-adjust"), "\\s");
private class SpaceMaker extends AbstractMaker {
public void endElement() {
- int offset = getAttributeAsInteger(lastAttributes, "offset", 0);
+ int offset = XMLUtil.getAttributeAsInt(lastAttributes, "offset", 0);
//TODO the isAdjustable parameter is currently not used/implemented
if (content.position() > 0) {
content.flip();
- boolean adjustable = getAttributeAsBoolean(lastAttributes, "adj", true);
+ boolean adjustable = XMLUtil.getAttributeAsBoolean(lastAttributes, "adj", true);
SpaceArea space = new SpaceArea(content.charAt(0), offset, adjustable);
AbstractTextArea text = getCurrentText();
space.setParentArea(text);
setTraits(attributes, leader, SUBSET_BOX);
setTraits(attributes, leader, SUBSET_COLOR);
setTraits(attributes, leader, SUBSET_FONT);
- leader.setOffset(getAttributeAsInteger(attributes, "offset", 0));
+ leader.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0));
String ruleStyle = attributes.getValue("ruleStyle");
if (ruleStyle != null) {
leader.setRuleStyle(ruleStyle);
}
leader.setRuleThickness(
- getAttributeAsInteger(attributes, "ruleThickness", 0));
+ XMLUtil.getAttributeAsInt(attributes, "ruleThickness", 0));
Area parent = (Area)areaStack.peek();
parent.addChildArea(leader);
}
setTraits(attributes, viewport, SUBSET_COMMON);
setTraits(attributes, viewport, SUBSET_BOX);
setTraits(attributes, viewport, SUBSET_COLOR);
- viewport.setContentPosition(getAttributeAsRectangle2D(attributes, "pos"));
- viewport.setClip(getAttributeAsBoolean(attributes, "clip", false));
- viewport.setOffset(getAttributeAsInteger(attributes, "offset", 0));
+ viewport.setContentPosition(XMLUtil.getAttributeAsRectangle2D(attributes, "pos"));
+ viewport.setClip(XMLUtil.getAttributeAsBoolean(attributes, "clip", false));
+ viewport.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0));
Area parent = (Area)areaStack.peek();
parent.addChildArea(viewport);
areaStack.push(viewport);
public void startElement(Attributes attributes) {
String title = attributes.getValue("title");
- boolean showChildren = getAttributeAsBoolean(attributes, "show-children", false);
+ boolean showChildren = XMLUtil.getAttributeAsBoolean(
+ attributes, "show-children", false);
String[] linkdata
= InternalLink.parseXMLAttribute(attributes.getValue("internal-link"));
PageViewport pv = (PageViewport) pageViewportsByKey.get(linkdata[0]);
if (repeat != null) {
bkg.setRepeat(repeat);
}
- bkg.setHoriz(getAttributeAsInteger(attributes,
+ bkg.setHoriz(XMLUtil.getAttributeAsInt(attributes,
"bkg-horz-offset", 0));
- bkg.setVertical(getAttributeAsInteger(attributes,
+ bkg.setVertical(XMLUtil.getAttributeAsInt(attributes,
"bkg-vert-offset", 0));
}
area.addTrait(trait, bkg);
String fontName = attributes.getValue("font-name");
if (fontName != null) {
String fontStyle = attributes.getValue("font-style");
- int fontWeight = getAttributeAsInteger(
+ int fontWeight = XMLUtil.getAttributeAsInt(
attributes, "font-weight", Font.WEIGHT_NORMAL);
area.addTrait(trait,
FontInfo.createFontKey(fontName, fontStyle, fontWeight));
}
}
- private static boolean getAttributeAsBoolean(Attributes attributes, String name,
- boolean defaultValue) {
- String s = attributes.getValue(name);
- if (s == null) {
- return defaultValue;
- } else {
- return Boolean.valueOf(s).booleanValue();
- }
- }
-
- private static int getAttributeAsInteger(Attributes attributes, String name,
- int defaultValue) {
- String s = attributes.getValue(name);
- if (s == null) {
- return defaultValue;
- } else {
- return Integer.parseInt(s);
- }
- }
-
private static CTM getAttributeAsCTM(Attributes attributes, String name) {
String s = attributes.getValue(name).trim();
if (s.startsWith("[") && s.endsWith("]")) {
}
}
- private static Rectangle2D getAttributeAsRectangle2D(Attributes attributes, String name) {
- String s = attributes.getValue(name).trim();
- double[] values = ConversionUtils.toDoubleArray(s, "\\s");
- if (values.length != 4) {
- throw new IllegalArgumentException("Rectangle must consist of 4 double values!");
- }
- return new Rectangle2D.Double(values[0], values[1], values[2], values[3]);
- }
-
private static void transferForeignObjects(Attributes atts, AreaTreeObject ato) {
for (int i = 0, c = atts.getLength(); i < c; i++) {
String ns = atts.getURI(i);
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.Length;
+import org.apache.fop.util.XMLConstants;
import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener;
/**
*/
public abstract class XMLObj extends FONode implements ObjectBuiltListener {
- private static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
-
// temp reference for attributes
private Attributes attr = null;
private static HashMap ns = new HashMap();
static {
- ns.put("xlink", "http://www.w3.org/1999/xlink");
+ ns.put(XMLConstants.XLINK_PREFIX, XMLConstants.XLINK_NAMESPACE);
}
/**
} else {
String pref = qname.substring(0, idx);
String tail = qname.substring(idx + 1);
- if (pref.equals("xmlns")) {
+ if (pref.equals(XMLConstants.XMLNS_PREFIX)) {
ns.put(tail, rf);
} else {
element.setAttributeNS((String)ns.get(pref), tail, rf);
element = doc.getDocumentElement();
buildTopLevel(doc, element);
- if (!element.hasAttributeNS(XMLNS_NAMESPACE_URI, "xmlns")) {
- element.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns",
+ if (!element.hasAttributeNS(
+ XMLConstants.XMLNS_NAMESPACE_URI, XMLConstants.XMLNS_PREFIX)) {
+ element.setAttributeNS(XMLConstants.XMLNS_NAMESPACE_URI, XMLConstants.XMLNS_PREFIX,
getNamespaceURI());
}
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.util.DecimalFormatCache;
+import org.apache.fop.util.XMLUtil;
/**
* Abstract base class for XML-writing IFPainter implementations.
private static final Attributes EMPTY_ATTS = new AttributesImpl();
- /** Constant for the "CDATA" attribute type. */
- protected static final String CDATA = "CDATA";
-
/**
* Default SAXTransformerFactory that can be used by subclasses.
*/
*/
protected void addAttribute(AttributesImpl atts, QName attribute, String value) {
atts.addAttribute(attribute.getNamespaceURI(),
- attribute.getLocalName(), attribute.getQName(), CDATA, value);
+ attribute.getLocalName(), attribute.getQName(), XMLUtil.CDATA, value);
+ }
+
+ /**
+ * Adds an attribute to a given {@code AttributesImpl} instance. The attribute will be
+ * added in the default namespace.
+ * @param atts the attributes collection
+ * @param localName the local name of the attribute
+ * @param value the attribute's CDATA value
+ */
+ protected void addAttribute(AttributesImpl atts, String localName, String value) {
+ atts.addAttribute("", localName, localName, XMLUtil.CDATA, value);
}
/**
package org.apache.fop.render.intermediate;
-import org.apache.xmlgraphics.util.QName;
-
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.util.XMLConstants;
/**
* Constants for the intermediate format.
*/
-public interface IFConstants {
+public interface IFConstants extends XMLConstants {
/** MIME type of the intermediate format. */
String MIME_TYPE = MimeConstants.MIME_FOP_IF;
/** XML namespace of the intermediate format. */
String NAMESPACE = "http://xmlgraphics.apache.org/fop/intermediate";
- /** XML namespace. */
- String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
-
- /** Namespace prefix for XLink */
- String XLINK_PREFIX = "xlink";
- /** XML namespace for XLink */
- String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
- /** xlink:href attribute */
- QName XLINK_HREF = new QName(XLINK_NAMESPACE, XLINK_PREFIX, "href");
-
String EL_DOCUMENT = "document";
String EL_HEADER = "header";
String EL_PAGE_SEQUENCE = "page-sequence";
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
import java.util.Map;
import javax.xml.transform.Source;
import org.apache.xmlgraphics.util.QName;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.ContentHandlerFactory;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
-import org.apache.fop.util.ConversionUtils;
import org.apache.fop.util.DOMBuilderContentHandlerFactory;
import org.apache.fop.util.DefaultErrorListener;
+import org.apache.fop.util.XMLUtil;
/**
* This is a parser for the intermediate format XML which converts the intermediate file into
DOMImplementation domImplementation
= elementMappingRegistry.getDOMImplementationForNamespace(uri);
if (domImplementation == null) {
+ domImplementation = ElementMapping.getDefaultDOMImplementation();
+ /*
throw new SAXException("No DOMImplementation could be"
+ " identified to handle namespace: " + uri);
+ */
}
factory = new DOMBuilderContentHandlerFactory(uri, domImplementation);
}
= AffineTransformArrayParser.createAffineTransform(transform);
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
- Rectangle clipRect = getAttributeAsRectangle(attributes, "clip-rect");
+ Rectangle clipRect = XMLUtil.getAttributeAsRectangle(attributes, "clip-rect");
painter.startViewport(transforms, new Dimension(width, height), clipRect);
}
public void startElement(Attributes attributes) throws IFException {
String family = attributes.getValue("family");
String style = attributes.getValue("style");
- Integer weight = getAttributeAsInteger(attributes, "weight");
+ Integer weight = XMLUtil.getAttributeAsInteger(attributes, "weight");
String variant = attributes.getValue("variant");
- Integer size = getAttributeAsInteger(attributes, "size");
+ Integer size = XMLUtil.getAttributeAsInteger(attributes, "size");
Color color;
try {
color = getAttributeAsColor(attributes, "color");
public void endElement() throws IFException {
int x = Integer.parseInt(lastAttributes.getValue("x"));
int y = Integer.parseInt(lastAttributes.getValue("y"));
- int[] dx = getAttributeAsIntArray(lastAttributes, "dx");
- int[] dy = getAttributeAsIntArray(lastAttributes, "dy");
+ int[] dx = XMLUtil.getAttributeAsIntArray(lastAttributes, "dx");
+ int[] dy = XMLUtil.getAttributeAsIntArray(lastAttributes, "dy");
painter.drawText(x, y, dx, dy, content.toString());
}
}
}
- private static boolean getAttributeAsBoolean(Attributes attributes, String name,
- boolean defaultValue) {
- String s = attributes.getValue(name);
- if (s == null) {
- return defaultValue;
- } else {
- return Boolean.valueOf(s).booleanValue();
- }
- }
-
- private static int getAttributeAsInteger(Attributes attributes, String name,
- int defaultValue) {
- String s = attributes.getValue(name);
- if (s == null) {
- return defaultValue;
- } else {
- return Integer.parseInt(s);
- }
- }
-
- private static Integer getAttributeAsInteger(Attributes attributes, String name) {
- String s = attributes.getValue(name);
- if (s == null) {
- return null;
- } else {
- return new Integer(s);
- }
- }
-
private Color getAttributeAsColor(Attributes attributes, String name)
- throws PropertyException {
+ throws PropertyException {
String s = attributes.getValue(name);
if (s == null) {
return null;
}
}
- private static Rectangle2D getAttributeAsRectangle2D(Attributes attributes, String name) {
- String s = attributes.getValue(name).trim();
- double[] values = ConversionUtils.toDoubleArray(s, "\\s");
- if (values.length != 4) {
- throw new IllegalArgumentException("Rectangle must consist of 4 double values!");
- }
- return new Rectangle2D.Double(values[0], values[1], values[2], values[3]);
- }
-
- private static Rectangle getAttributeAsRectangle(Attributes attributes, String name) {
- String s = attributes.getValue(name);
- if (s == null) {
- return null;
- }
- int[] values = ConversionUtils.toIntArray(s.trim(), "\\s");
- if (values.length != 4) {
- throw new IllegalArgumentException("Rectangle must consist of 4 int values!");
- }
- return new Rectangle(values[0], values[1], values[2], values[3]);
- }
-
- private static int[] getAttributeAsIntArray(Attributes attributes, String name) {
- String s = attributes.getValue(name);
- if (s == null) {
- return null;
- } else {
- return ConversionUtils.toIntArray(s.trim(), "\\s");
- }
- }
-
private static Map getForeignAttributes(Attributes atts) {
Map foreignAttributes = null;
for (int i = 0, c = atts.getLength(); i < c; i++) {
import org.apache.fop.render.RenderingContext;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.DOM2SAX;
+import org.apache.fop.util.XMLUtil;
/**
* IFPainter implementation that serializes the intermediate format to XML.
try {
AttributesImpl atts = new AttributesImpl();
if (id != null) {
- atts.addAttribute(XML_NAMESPACE, "id", "xml:id", CDATA, id);
+ atts.addAttribute(XML_NAMESPACE, "id", "xml:id", XMLUtil.CDATA, id);
}
startElement(EL_PAGE_SEQUENCE, atts);
} catch (SAXException e) {
public void startPage(int index, String name, Dimension size) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
- atts.addAttribute("", "index", "index", CDATA, Integer.toString(index));
- atts.addAttribute("", "name", "name", CDATA, name);
- atts.addAttribute("", "width", "width", CDATA, Integer.toString(size.width));
- atts.addAttribute("", "height", "height", CDATA, Integer.toString(size.height));
+ addAttribute(atts, "index", Integer.toString(index));
+ addAttribute(atts, "name", name);
+ addAttribute(atts, "width", Integer.toString(size.width));
+ addAttribute(atts, "height", Integer.toString(size.height));
startElement(EL_PAGE, atts);
} catch (SAXException e) {
throw new IFException("SAX error in startPage()", e);
try {
AttributesImpl atts = new AttributesImpl();
if (transform != null && transform.length() > 0) {
- atts.addAttribute("", "transform", "transform", CDATA, transform);
+ addAttribute(atts,"transform", transform);
}
- atts.addAttribute("", "width", "width", CDATA, Integer.toString(size.width));
- atts.addAttribute("", "height", "height", CDATA, Integer.toString(size.height));
+ addAttribute(atts, "width", Integer.toString(size.width));
+ addAttribute(atts, "height", Integer.toString(size.height));
if (clipRect != null) {
- atts.addAttribute("", "clip-rect", "clip-rect", CDATA, toString(clipRect));
+ addAttribute(atts, "clip-rect", toString(clipRect));
}
startElement(EL_VIEWPORT, atts);
} catch (SAXException e) {
try {
AttributesImpl atts = new AttributesImpl();
if (transform != null && transform.length() > 0) {
- atts.addAttribute("", "transform", "transform", CDATA, transform);
+ addAttribute(atts, "transform", transform);
}
startElement(EL_GROUP, atts);
} catch (SAXException e) {
try {
AttributesImpl atts = new AttributesImpl();
addAttribute(atts, XLINK_HREF, uri);
- atts.addAttribute("", "x", "x", CDATA, Integer.toString(rect.x));
- atts.addAttribute("", "y", "y", CDATA, Integer.toString(rect.y));
- atts.addAttribute("", "width", "width", CDATA, Integer.toString(rect.width));
- atts.addAttribute("", "height", "height", CDATA, Integer.toString(rect.height));
+ addAttribute(atts, "x", Integer.toString(rect.x));
+ addAttribute(atts, "y", Integer.toString(rect.y));
+ addAttribute(atts, "width", Integer.toString(rect.width));
+ addAttribute(atts, "height", Integer.toString(rect.height));
if (foreignAttributes != null) {
Iterator iter = foreignAttributes.entrySet().iterator();
while (iter.hasNext()) {
public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
- atts.addAttribute("", "x", "x", CDATA, Integer.toString(rect.x));
- atts.addAttribute("", "y", "y", CDATA, Integer.toString(rect.y));
- atts.addAttribute("", "width", "width", CDATA, Integer.toString(rect.width));
- atts.addAttribute("", "height", "height", CDATA, Integer.toString(rect.height));
+ addAttribute(atts, "x", Integer.toString(rect.x));
+ addAttribute(atts, "y", Integer.toString(rect.y));
+ addAttribute(atts, "width", Integer.toString(rect.width));
+ addAttribute(atts, "height", Integer.toString(rect.height));
if (foreignAttributes != null) {
Iterator iter = foreignAttributes.entrySet().iterator();
while (iter.hasNext()) {
}
try {
AttributesImpl atts = new AttributesImpl();
- atts.addAttribute("", "x", "x", CDATA, Integer.toString(rect.x));
- atts.addAttribute("", "y", "y", CDATA, Integer.toString(rect.y));
- atts.addAttribute("", "width", "width", CDATA, Integer.toString(rect.width));
- atts.addAttribute("", "height", "height", CDATA, Integer.toString(rect.height));
+ addAttribute(atts, "x", Integer.toString(rect.x));
+ addAttribute(atts, "y", Integer.toString(rect.y));
+ addAttribute(atts, "width", Integer.toString(rect.width));
+ addAttribute(atts, "height", Integer.toString(rect.height));
if (fill != null) {
- atts.addAttribute("", "fill", "fill", CDATA, toString(fill));
+ addAttribute(atts, "fill", toString(fill));
}
if (stroke != null) {
- atts.addAttribute("", "stroke", "sroke", CDATA, toString(stroke));
+ addAttribute(atts, "sroke", toString(stroke));
}
element("rect", atts);
} catch (SAXException e) {
public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
- atts.addAttribute("", "x", "x", CDATA, Integer.toString(x));
- atts.addAttribute("", "y", "y", CDATA, Integer.toString(y));
+ addAttribute(atts, "x", Integer.toString(x));
+ addAttribute(atts, "y", Integer.toString(y));
if (dx != null) {
- atts.addAttribute("", "dx", "dx", CDATA, toString(dx));
+ addAttribute(atts, "dx", toString(dx));
}
if (dy != null) {
- atts.addAttribute("", "dy", "dy", CDATA, toString(dy));
+ addAttribute(atts, "dy", toString(dy));
}
startElement("text", atts);
char[] chars = text.toCharArray();
try {
AttributesImpl atts = new AttributesImpl();
if (family != null) {
- atts.addAttribute("", "family", "family", CDATA, family);
+ addAttribute(atts, "family", family);
}
if (style != null) {
- atts.addAttribute("", "style", "style", CDATA, style);
+ addAttribute(atts, "style", style);
}
if (weight != null) {
- atts.addAttribute("", "weight", "weight", CDATA, weight.toString());
+ addAttribute(atts, "weight", weight.toString());
}
if (variant != null) {
- atts.addAttribute("", "variant", "variant", CDATA, variant);
+ addAttribute(atts, "variant", variant);
}
if (size != null) {
- atts.addAttribute("", "size", "size", CDATA, size.toString());
+ addAttribute(atts, "size", size.toString());
}
if (color != null) {
- atts.addAttribute("", "color", "color", CDATA, toString(color));
+ addAttribute(atts, "color", toString(color));
}
element("font", atts);
} catch (SAXException e) {
}
} else {
throw new UnsupportedOperationException(
- "Don't know how to handle extension object: " + extension);
+ "Don't know how to handle extension object: "
+ + extension + " (" + extension.getClass().getName() + ")");
}
}
package org.apache.fop.svg;
-import java.util.StringTokenizer;
+import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-import java.awt.font.FontRenderContext;
+import java.util.StringTokenizer;
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.batik.util.XMLConstants;
/**
* Some utilities for creating svg DOM documents and elements.
public static final Element createImage(Document doc, String ref,
float width, float height) {
Element border = doc.createElementNS(SVG_NS, "image");
- border.setAttributeNS("http://www.w3.org/1999/xlink", "href",
+ border.setAttributeNS(XMLConstants.XLINK_NAMESPACE_URI, "href",
ref);
border.setAttributeNS(null, "width", "" + width);
border.setAttributeNS(null, "height", "" + height);
// Add attribute to list
attrs.addAttribute(attr.getNamespaceURI(),
- getLocalName(attr), qnameAttr, "CDATA", attr
+ getLocalName(attr), qnameAttr, XMLUtil.CDATA, attr
.getNodeValue());
}
}
--- /dev/null
+/*
+ * 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$ */
+
+package org.apache.fop.util;
+
+
+/**
+ * A collection of constants for XML handling.
+ */
+public interface XMLConstants {
+
+ /** "CDATA" constant */
+ String CDATA = "CDATA";
+
+ /** XML namespace prefix */
+ String XML_PREFIX = "xml";
+ /** XML namespace URI */
+ String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
+
+ /** XMLNS namespace prefix */
+ String XMLNS_PREFIX = "xmlns";
+ /** XMLNS namespace URI */
+ String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
+
+ /** Namespace prefix for XLink */
+ String XLINK_PREFIX = "xlink";
+ /** XML namespace for XLink */
+ String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
+ /** xlink:href attribute */
+ org.apache.xmlgraphics.util.QName XLINK_HREF = new org.apache.xmlgraphics.util.QName(
+ XLINK_NAMESPACE, XLINK_PREFIX, "href");
+
+}
--- /dev/null
+/*
+ * 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$ */
+
+package org.apache.fop.util;
+
+import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * A collection of utility method for XML handling.
+ */
+public class XMLUtil implements XMLConstants {
+
+ /**
+ * Returns an attribute value as a boolean value.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @param defaultValue the default value if the attribute is not specified
+ * @return the attribute value as a boolean
+ */
+ public static boolean getAttributeAsBoolean(Attributes attributes, String name,
+ boolean defaultValue) {
+ String s = attributes.getValue(name);
+ if (s == null) {
+ return defaultValue;
+ } else {
+ return Boolean.valueOf(s).booleanValue();
+ }
+ }
+
+ /**
+ * Returns an attribute value as a int value.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @param defaultValue the default value if the attribute is not specified
+ * @return the attribute value as an int
+ */
+ public static int getAttributeAsInt(Attributes attributes, String name,
+ int defaultValue) {
+ String s = attributes.getValue(name);
+ if (s == null) {
+ return defaultValue;
+ } else {
+ return Integer.parseInt(s);
+ }
+ }
+
+ /**
+ * Returns an attribute value as a int value.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @return the attribute value as an int
+ * @throws SAXException if the attribute is missing
+ */
+ public static int getAttributeAsInt(Attributes attributes, String name) throws SAXException {
+ String s = attributes.getValue(name);
+ if (s == null) {
+ throw new SAXException("Attribute '" + name + "' is missing");
+ } else {
+ return Integer.parseInt(s);
+ }
+ }
+
+ /**
+ * Returns an attribute value as a Integer value.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @return the attribute value as an Integer or null if the attribute is missing
+ */
+ public static Integer getAttributeAsInteger(Attributes attributes, String name) {
+ String s = attributes.getValue(name);
+ if (s == null) {
+ return null;
+ } else {
+ return new Integer(s);
+ }
+ }
+
+ /**
+ * Returns an attribute value as a Rectangle2D value. The string value is expected as 4
+ * double-precision numbers separated by whitespace.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @return the attribute value as an Rectangle2D
+ */
+ public static Rectangle2D getAttributeAsRectangle2D(Attributes attributes, String name) {
+ String s = attributes.getValue(name).trim();
+ double[] values = ConversionUtils.toDoubleArray(s, "\\s");
+ if (values.length != 4) {
+ throw new IllegalArgumentException("Rectangle must consist of 4 double values!");
+ }
+ return new Rectangle2D.Double(values[0], values[1], values[2], values[3]);
+ }
+
+ /**
+ * Returns an attribute value as a Rectangle value. The string value is expected as 4
+ * integer numbers separated by whitespace.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @return the attribute value as an Rectangle
+ */
+ public static Rectangle getAttributeAsRectangle(Attributes attributes, String name) {
+ String s = attributes.getValue(name);
+ if (s == null) {
+ return null;
+ }
+ int[] values = ConversionUtils.toIntArray(s.trim(), "\\s");
+ if (values.length != 4) {
+ throw new IllegalArgumentException("Rectangle must consist of 4 int values!");
+ }
+ return new Rectangle(values[0], values[1], values[2], values[3]);
+ }
+
+ /**
+ * Returns an attribute value as a integer array. The string value is expected as 4
+ * integer numbers separated by whitespace.
+ * @param attributes the Attributes object
+ * @param name the name of the attribute
+ * @return the attribute value as an int array
+ */
+ public static int[] getAttributeAsIntArray(Attributes attributes, String name) {
+ String s = attributes.getValue(name);
+ if (s == null) {
+ return null;
+ } else {
+ return ConversionUtils.toIntArray(s.trim(), "\\s");
+ }
+ }
+
+}
import org.apache.xmlgraphics.util.QName;
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.util.XMLConstants;
/**
* Constants for the intermediate format.
*/
-public interface SVGConstants {
+public interface SVGConstants extends XMLConstants {
/** MIME type for SVG. */
String MIME_TYPE = MimeConstants.MIME_SVG;
/** XML namespace for SVG. */
String NAMESPACE = "http://www.w3.org/2000/svg";
- /** XML namespace. */
- String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
-
- /** Namespace prefix for XLink */
- String XLINK_PREFIX = "xlink";
- /** XML namespace for XLink */
- String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
-
/** the SVG element */
QName SVG_ELEMENT = new QName(NAMESPACE, null, "svg");