List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl
public AttributesImpl()
From source file:org.apache.fop.render.svg.SVGPainter.java
private void startViewport(String transform, Dimension size, Rectangle clipRect) throws IFException { try {/*from ww w .j a v a2 s .co m*/ establish(MODE_NORMAL); AttributesImpl atts = new AttributesImpl(); if (transform != null && transform.length() > 0) { XMLUtil.addAttribute(atts, "transform", transform); } handler.startElement("g", atts); atts.clear(); XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(size.width)); XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(size.height)); if (clipRect != null) { int[] v = new int[] { clipRect.y, -clipRect.x + size.width - clipRect.width, -clipRect.y + size.height - clipRect.height, clipRect.x }; int sum = 0; for (int i = 0; i < 4; i++) { sum += Math.abs(v[i]); } if (sum != 0) { StringBuffer sb = new StringBuffer("rect("); sb.append(SVGUtil.formatMptToPt(v[0])).append(','); sb.append(SVGUtil.formatMptToPt(v[1])).append(','); sb.append(SVGUtil.formatMptToPt(v[2])).append(','); sb.append(SVGUtil.formatMptToPt(v[3])).append(')'); XMLUtil.addAttribute(atts, "clip", sb.toString()); } XMLUtil.addAttribute(atts, "overflow", "hidden"); } else { XMLUtil.addAttribute(atts, "overflow", "visible"); } handler.startElement("svg", atts); } catch (SAXException e) { throw new IFException("SAX error in startBox()", e); } }
From source file:org.apache.fop.render.svg.SVGPainter.java
private void startGroup(String transform) throws IFException { try {/*from w ww . ja v a 2s . c om*/ AttributesImpl atts = new AttributesImpl(); if (transform != null && transform.length() > 0) { XMLUtil.addAttribute(atts, "transform", transform); } handler.startElement("g", atts); } catch (SAXException e) { throw new IFException("SAX error in startGroup()", e); } }
From source file:org.apache.fop.render.svg.SVGPainter.java
/** {@inheritDoc} */ public void drawImage(String uri, Rectangle rect) throws IFException { try {//w w w . j a v a2s. c o m establish(MODE_NORMAL); ImageManager manager = getUserAgent().getFactory().getImageManager(); ImageInfo info = null; try { ImageSessionContext sessionContext = getUserAgent().getImageSessionContext(); info = manager.getImageInfo(uri, sessionContext); String mime = info.getMimeType(); Map foreignAttributes = getContext().getForeignAttributes(); String conversionMode = (String) foreignAttributes.get(ImageHandlerUtil.CONVERSION_MODE); if ("reference".equals(conversionMode) && (MimeConstants.MIME_GIF.equals(mime) || MimeConstants.MIME_JPEG.equals(mime) || MimeConstants.MIME_PNG.equals(mime) || MimeConstants.MIME_SVG.equals(mime))) { //Just reference the image //TODO Some additional URI rewriting might be necessary AttributesImpl atts = new AttributesImpl(); XMLUtil.addAttribute(atts, IFConstants.XLINK_HREF, uri); XMLUtil.addAttribute(atts, "x", SVGUtil.formatMptToPt(rect.x)); XMLUtil.addAttribute(atts, "y", SVGUtil.formatMptToPt(rect.y)); XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(rect.width)); XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(rect.height)); handler.element("image", atts); } else { drawImageUsingImageHandler(info, rect); } } catch (ImageException ie) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageError(this, (info != null ? info.toString() : uri), ie, null); } catch (FileNotFoundException fe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageNotFound(this, (info != null ? info.toString() : uri), fe, null); } catch (IOException ioe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageIOError(this, (info != null ? info.toString() : uri), ioe, null); } } catch (SAXException e) { throw new IFException("SAX error in drawImage()", e); } }
From source file:org.apache.fop.render.svg.SVGPainter.java
/** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return;//ww w . j a va2 s. co m } try { establish(MODE_NORMAL); AttributesImpl atts = new AttributesImpl(); XMLUtil.addAttribute(atts, "x", SVGUtil.formatMptToPt(rect.x)); XMLUtil.addAttribute(atts, "y", SVGUtil.formatMptToPt(rect.y)); XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(rect.width)); XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(rect.height)); if (fill != null) { XMLUtil.addAttribute(atts, "fill", toString(fill)); } /* disabled if (stroke != null) { XMLUtil.addAttribute(atts, "stroke", toString(stroke)); }*/ handler.element("rect", atts); } catch (SAXException e) { throw new IFException("SAX error in fillRect()", e); } }
From source file:org.apache.fop.render.svg.SVGPainter.java
/** {@inheritDoc} */ public void drawLine(Point start, Point end, int width, Color color, RuleStyle style) throws IFException { try {//from w w w.j ava 2 s.c o m establish(MODE_NORMAL); AttributesImpl atts = new AttributesImpl(); XMLUtil.addAttribute(atts, "x1", SVGUtil.formatMptToPt(start.x)); XMLUtil.addAttribute(atts, "y1", SVGUtil.formatMptToPt(start.y)); XMLUtil.addAttribute(atts, "x2", SVGUtil.formatMptToPt(end.x)); XMLUtil.addAttribute(atts, "y2", SVGUtil.formatMptToPt(end.y)); XMLUtil.addAttribute(atts, "stroke-width", toString(color)); XMLUtil.addAttribute(atts, "fill", toString(color)); //TODO Handle style parameter handler.element("line", atts); } catch (SAXException e) { throw new IFException("SAX error in drawLine()", e); } }
From source file:org.apache.fop.render.svg.SVGPainter.java
/** {@inheritDoc} */ public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text) throws IFException { try {//w w w.j av a 2s .co m establish(MODE_TEXT); AttributesImpl atts = new AttributesImpl(); XMLUtil.addAttribute(atts, XMLConstants.XML_SPACE, "preserve"); XMLUtil.addAttribute(atts, "x", SVGUtil.formatMptToPt(x)); XMLUtil.addAttribute(atts, "y", SVGUtil.formatMptToPt(y)); if (letterSpacing != 0) { XMLUtil.addAttribute(atts, "letter-spacing", SVGUtil.formatMptToPt(letterSpacing)); } if (wordSpacing != 0) { XMLUtil.addAttribute(atts, "word-spacing", SVGUtil.formatMptToPt(wordSpacing)); } if (dx != null) { XMLUtil.addAttribute(atts, "dx", SVGUtil.formatMptArrayToPt(dx)); } handler.startElement("text", atts); char[] chars = text.toCharArray(); handler.characters(chars, 0, chars.length); handler.endElement("text"); } catch (SAXException e) { throw new IFException("SAX error in setFont()", e); } }
From source file:org.apache.fop.render.svg.SVGPainter.java
private void startTextGroup() throws SAXException { AttributesImpl atts = new AttributesImpl(); XMLUtil.addAttribute(atts, "font-family", "'" + state.getFontFamily() + "'"); XMLUtil.addAttribute(atts, "font-style", state.getFontStyle()); XMLUtil.addAttribute(atts, "font-weight", Integer.toString(state.getFontWeight())); XMLUtil.addAttribute(atts, "font-variant", state.getFontVariant()); XMLUtil.addAttribute(atts, "font-size", SVGUtil.formatMptToPt(state.getFontSize())); XMLUtil.addAttribute(atts, "fill", toString(state.getTextColor())); handler.startElement("g", atts); state.resetFontChanged();/*from w ww.ja v a 2 s. c o m*/ }
From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java
public void outputToXml(ContentHandler contentHandler) throws SAXException { contentHandler.startElement("", "", "RECORD", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "OPCODE", opCode.toString()); contentHandler.startElement("", "", "DATA", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "TXID", "" + txid); toXml(contentHandler);/* w w w .j a va 2 s .c om*/ contentHandler.endElement("", "", "DATA"); contentHandler.endElement("", "", "RECORD"); }
From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java
public static void blockToXml(ContentHandler contentHandler, Block block) throws SAXException { contentHandler.startElement("", "", "BLOCK", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "BLOCK_ID", Long.toString(block.getBlockId())); XMLUtils.addSaxString(contentHandler, "NUM_BYTES", Long.toString(block.getNumBytes())); XMLUtils.addSaxString(contentHandler, "GENSTAMP", Long.toString(block.getGenerationStamp())); contentHandler.endElement("", "", "BLOCK"); }
From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java
public static void delegationTokenToXml(ContentHandler contentHandler, DelegationTokenIdentifier token) throws SAXException { contentHandler.startElement("", "", "DELEGATION_TOKEN_IDENTIFIER", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "KIND", token.getKind().toString()); XMLUtils.addSaxString(contentHandler, "SEQUENCE_NUMBER", Integer.toString(token.getSequenceNumber())); XMLUtils.addSaxString(contentHandler, "OWNER", token.getOwner().toString()); XMLUtils.addSaxString(contentHandler, "RENEWER", token.getRenewer().toString()); XMLUtils.addSaxString(contentHandler, "REALUSER", token.getRealUser().toString()); XMLUtils.addSaxString(contentHandler, "ISSUE_DATE", Long.toString(token.getIssueDate())); XMLUtils.addSaxString(contentHandler, "MAX_DATE", Long.toString(token.getMaxDate())); XMLUtils.addSaxString(contentHandler, "MASTER_KEY_ID", Integer.toString(token.getMasterKeyId())); contentHandler.endElement("", "", "DELEGATION_TOKEN_IDENTIFIER"); }