Java XMLStreamWriter writePath(XMLStreamWriter w, Supplier cssClass, Supplier fill, Supplier stroke, Supplier path)

Here you can find the source of writePath(XMLStreamWriter w, Supplier cssClass, Supplier fill, Supplier stroke, Supplier path)

Description

Write an SVG Path element

License

Apache License

Parameter

Parameter Description
w XMLStreamWriter
cssClass Supplier of css class or null if none
fill Supplier of fill or null if none
stroke Supplier of stroke or null if none
path Supplier of the path. Must not be null

Declaration

public static void writePath(XMLStreamWriter w, Supplier<String> cssClass, Supplier<String> fill,
        Supplier<String> stroke, Supplier<String> path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.function.Supplier;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

public class Main {
    /**/*from   ww w . ja v  a 2 s .  com*/
     * Write an SVG Path element
     * <p>
     * @param w        XMLStreamWriter
     * @param cssClass Supplier of css class or null if none
     * @param fill     Supplier of fill or null if none
     * @param stroke   Supplier of stroke or null if none
     * @param path     Supplier of the path. Must not be null
     */
    public static void writePath(XMLStreamWriter w, Supplier<String> cssClass, Supplier<String> fill,
            Supplier<String> stroke, Supplier<String> path) {
        try {
            w.writeStartElement("path");
            writeSvgAttributes(w, cssClass, fill, stroke);
            w.writeAttribute("d", path.get());
            w.writeEndElement();
        } catch (XMLStreamException ex) {
            throw new RuntimeException(ex);
        }
    }

    /**
     * Write common attributes to the {@link XMLStreamWriter}
     * <p>
     * @param w        XMLStreamWriter
     * @param cssClass Supplier of css class or null if none
     * @param fill     Supplier of fill or null if none
     * @param stroke   Supplier of stroke or null if none
     * <p>
     * @throws XMLStreamException on failure
     */
    public static void writeSvgAttributes(XMLStreamWriter w, Supplier<String> cssClass, Supplier<String> fill,
            Supplier<String> stroke) throws XMLStreamException {

        if (cssClass != null) {
            w.writeAttribute("class", cssClass.get());
        }

        if (fill != null) {
            w.writeAttribute("fill", fill.get());
        }

        if (stroke != null) {
            w.writeAttribute("stroke", stroke.get());
        }
    }
}

Related

  1. writeEndElement(XMLStreamWriter out, QName name)
  2. writeFloat(String name, float value, XMLStreamWriter writer)
  3. writeFooter(XMLStreamWriter w)
  4. writeIndent(XMLStreamWriter xmlsw, String indent)
  5. writeInsertPos(XMLStreamWriter w, boolean isBefore, int[] pos)
  6. writeSimpleTag(XMLStreamWriter writer, String tag, Object value, boolean asCData)
  7. writeStartElement(XMLStreamWriter writer, QName name)
  8. writeTag(XMLStreamWriter xmlWriter, String tag, Object value)
  9. writeWithCharacters(XMLStreamWriter w, String localName, String text)