Example usage for org.dom4j Element addElement

List of usage examples for org.dom4j Element addElement

Introduction

In this page you can find the example usage for org.dom4j Element addElement.

Prototype

Element addElement(String name);

Source Link

Document

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Usage

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeEnhancedStrokeStyles(Element parentElement, byte jointStyle, byte startCapStyle,
        byte endCapStyle, double miterLimit, byte scaleStroke) {
    switch (jointStyle) {
    case EnhancedStrokeStyle.JOINT_ROUND:
        parentElement.addAttribute("joint", "round");
        break;/*from   w ww  .  jav  a  2  s  .  co m*/
    case EnhancedStrokeStyle.JOINT_MITER:
        parentElement.addAttribute("joint", "miter");
        parentElement.addAttribute("miterlimit", StringUtilities.doubleToString(miterLimit));
        break;
    case EnhancedStrokeStyle.JOINT_BEVEL:
        parentElement.addAttribute("joint", "bevel");
        break;
    }
    Element capStyleElement = parentElement.addElement("capstyle");
    switch (startCapStyle) {
    case EnhancedStrokeStyle.CAPS_NONE:
        capStyleElement.addAttribute("start", "none");
        break;
    case EnhancedStrokeStyle.CAPS_ROUND:
        capStyleElement.addAttribute("start", "round");
        break;
    case EnhancedStrokeStyle.CAPS_SQUARE:
        capStyleElement.addAttribute("start", "square");
        break;
    }
    switch (endCapStyle) {
    case EnhancedStrokeStyle.CAPS_NONE:
        capStyleElement.addAttribute("end", "none");
        break;
    case EnhancedStrokeStyle.CAPS_ROUND:
        capStyleElement.addAttribute("end", "round");
        break;
    case EnhancedStrokeStyle.CAPS_SQUARE:
        capStyleElement.addAttribute("end", "square");
        break;
    }
    switch (scaleStroke) {
    case EnhancedStrokeStyle.SCALE_NONE:
        parentElement.addAttribute("scalestroke", "none");
        break;
    case EnhancedStrokeStyle.SCALE_HORIZONTAL:
        parentElement.addAttribute("scalestroke", "horizontal");
        break;
    case EnhancedStrokeStyle.SCALE_VERTICAL:
        parentElement.addAttribute("scalestroke", "vertical");
        break;
    case EnhancedStrokeStyle.SCALE_BOTH:
        parentElement.addAttribute("scalestroke", "both");
        break;
    }
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeFillStyle(Element parentElement, FillStyle fillStyle) {
    Element fillStyleElement = parentElement.addElement("fillstyle");
    boolean isGradient = false;
    boolean isFocal = false;
    boolean isBitmap = false;
    switch (fillStyle.getType()) {
    case FillStyle.TYPE_SOLID:
        fillStyleElement.addAttribute("type", "solid");
        writeColor(fillStyleElement, "color", fillStyle.getColor());
        break;/*from  ww w. j  a  v a 2  s  .c om*/
    case FillStyle.TYPE_LINEAR_GRADIENT:
        fillStyleElement.addAttribute("type", "lineargradient");
        isGradient = true;
        break;
    case FillStyle.TYPE_FOCAL_RADIAL_GRADIENT:
        fillStyleElement.addAttribute("type", "focalradialgradient");
        isGradient = true;
        isFocal = true;
        break;
    case FillStyle.TYPE_RADIAL_GRADIENT:
        fillStyleElement.addAttribute("type", "radialgradient");
        isGradient = true;
        break;
    case FillStyle.TYPE_TILED_BITMAP:
        fillStyleElement.addAttribute("type", "tiledbitmap");
        isBitmap = true;
        break;
    case FillStyle.TYPE_CLIPPED_BITMAP:
        fillStyleElement.addAttribute("type", "clippedbitmap");
        isBitmap = true;
        break;
    case FillStyle.TYPE_NONSMOOTHED_TILED_BITMAP:
        fillStyleElement.addAttribute("type", "nonsmoothedtiledbitmap");
        isBitmap = true;
        break;
    case FillStyle.TYPE_NONSMOOTHED_CLIPPED_BITMAP:
        fillStyleElement.addAttribute("type", "nonsmoothedclippedbitmap");
        isBitmap = true;
        break;
    default:
        throw new IllegalArgumentException("Illegal fill type: " + fillStyle.getType());
    }
    if (isGradient) {
        if (isFocal) {
            writeFocalGradient(fillStyleElement.addElement("focalgradient"),
                    (FocalGradient) fillStyle.getGradient());
        } else {
            writeGradient(fillStyleElement.addElement("gradient"), fillStyle.getGradient());
        }
        writeMatrix(fillStyleElement, "gradientmatrix", fillStyle.getGradientMatrix());
    } else if (isBitmap) {
        fillStyleElement.addAttribute("bitmapid", Integer.toString(fillStyle.getBitmapId()));
        writeMatrix(fillStyleElement, "bitmapmatrix", fillStyle.getBitmapMatrix());
    }
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeFillStyles(Element parentElement, FillStyleArray fillStyles) {
    int size = fillStyles.getSize();
    Element fillStylesElement = parentElement.addElement("fillstyles");
    for (int i = 1; i <= size; i++) {
        FillStyle fillStyle = fillStyles.getStyle(i);
        writeFillStyle(fillStylesElement, fillStyle);
    }//from ww  w.j a  va  2 s.  c o  m
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeGradient(Element gradientElement, Gradient gradient) {
    switch (gradient.getInterpolationMethod()) {
    case Gradient.INTERPOLATION_LINEAR_RGB:
        gradientElement.addAttribute("interpolation", "linear-rgb");
        break;/* w ww  . ja va 2s  . c  om*/
    case Gradient.INTERPOLATION_RGB:
        gradientElement.addAttribute("interpolation", "rgb");
        break;
    }
    switch (gradient.getSpreadMethod()) {
    case Gradient.SPREAD_PAD:
        gradientElement.addAttribute("spread", "pad");
        break;
    case Gradient.SPREAD_REFLECT:
        gradientElement.addAttribute("spread", "reflect");
        break;
    case Gradient.SPREAD_REPEAT:
        gradientElement.addAttribute("spread", "repeat");
        break;
    }
    GradRecord[] records = gradient.getGradientRecords();
    for (int i = 0; i < records.length; i++) {
        GradRecord record = records[i];
        Element recordElement = gradientElement.addElement("gradrecord");
        recordElement.addAttribute("ratio", Short.toString(record.getRatio()));
        writeColor(recordElement, "color", record.getColor());
    }
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeLineStyles(Element parentElement, LineStyleArray lineStyles) {
    int size = lineStyles.getSize();
    Element lineStylesElement = parentElement.addElement("linestyles");
    for (int i = 1; i <= size; i++) {
        Object style = lineStyles.getStyle(i);
        if (style instanceof LineStyle) {
            LineStyle lineStyle = (LineStyle) style;
            Element lineStyleElement = lineStylesElement.addElement("linestyle");
            lineStyleElement.addAttribute("width", Integer.toString(lineStyle.getWidth()));
            writeColor(lineStyleElement, "color", lineStyle.getColor());
        } else {/*from  w  ww . j a va 2s . c  om*/
            LineStyle2 lineStyle2 = (LineStyle2) style;
            Element lineStyle2Element = lineStylesElement.addElement("linestyle2");
            lineStyle2Element.addAttribute("width", Integer.toString(lineStyle2.getWidth()));
            writeEnhancedStrokeStyles(lineStyle2Element, lineStyle2.getJointStyle(),
                    lineStyle2.getStartCapStyle(), lineStyle2.getEndCapStyle(), lineStyle2.getMiterLimit(),
                    lineStyle2.getScaleStroke());
            if (lineStyle2.isClose()) {
                parentElement.addAttribute("close", "true");
            }
            if (lineStyle2.isPixelHinting()) {
                parentElement.addAttribute("pixelhinting", "true");
            }
            FillStyle fillStyle = lineStyle2.getFillStyle();
            if (fillStyle == null) {
                writeColor(lineStyle2Element, "color", lineStyle2.getColor());
            } else {
                writeFillStyle(lineStyle2Element, fillStyle);
            }
        }
    }
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeMorphFillStyle(Element parentElement, MorphFillStyle fillStyle) {
    Element fillStyleElement = parentElement.addElement("morphfillstyle");
    Element start = fillStyleElement.addElement("start");
    Element end = fillStyleElement.addElement("end");
    boolean isGradient = false;
    boolean isFocal = false;
    boolean isBitmap = false;
    switch (fillStyle.getType()) {
    case FillStyle.TYPE_SOLID:
        fillStyleElement.addAttribute("type", "solid");
        writeRGBA(start, "color", fillStyle.getStartColor());
        writeRGBA(end, "color", fillStyle.getEndColor());
        break;/*from   w ww  . j a  v  a2  s  . co m*/
    case FillStyle.TYPE_LINEAR_GRADIENT:
        fillStyleElement.addAttribute("type", "lineargradient");
        isGradient = true;
        break;
    case FillStyle.TYPE_FOCAL_RADIAL_GRADIENT:
        fillStyleElement.addAttribute("type", "focalradialgradient");
        isGradient = true;
        isFocal = true;
        break;
    case FillStyle.TYPE_RADIAL_GRADIENT:
        fillStyleElement.addAttribute("type", "radialgradient");
        isGradient = true;
        break;
    case FillStyle.TYPE_TILED_BITMAP:
        fillStyleElement.addAttribute("type", "tiledbitmap");
        isBitmap = true;
        break;
    case FillStyle.TYPE_CLIPPED_BITMAP:
        fillStyleElement.addAttribute("type", "clippedbitmap");
        isBitmap = true;
        break;
    case FillStyle.TYPE_NONSMOOTHED_TILED_BITMAP:
        fillStyleElement.addAttribute("type", "nonsmoothedtiledbitmap");
        isBitmap = true;
        break;
    case FillStyle.TYPE_NONSMOOTHED_CLIPPED_BITMAP:
        fillStyleElement.addAttribute("type", "nonsmoothedclippedbitmap");
        isBitmap = true;
        break;
    default:
        throw new IllegalArgumentException("Illegal morph fill type: " + fillStyle.getType());
    }
    if (isGradient) {
        if (isFocal) {
            writeFocalMorphGradient(fillStyleElement.addElement("focalmorphgradient"),
                    (FocalMorphGradient) fillStyle.getGradient());
        } else {
            writeMorphGradient(fillStyleElement.addElement("morphgradient"), fillStyle.getGradient());
        }
        writeMatrix(start, "gradientmatrix", fillStyle.getStartGradientMatrix());
        writeMatrix(end, "gradientmatrix", fillStyle.getEndGradientMatrix());
    } else if (isBitmap) {
        fillStyleElement.addAttribute("bitmapid", Integer.toString(fillStyle.getBitmapId()));
        writeMatrix(start, "bitmapmatrix", fillStyle.getStartBitmapMatrix());
        writeMatrix(end, "bitmapmatrix", fillStyle.getEndBitmapMatrix());
    }
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeMorphGradient(Element gradientElement, MorphGradient gradient) {
    switch (gradient.getInterpolationMethod()) {
    case Gradient.INTERPOLATION_LINEAR_RGB:
        gradientElement.addAttribute("interpolation", "linear-rgb");
        break;/*from w  ww .j  a  va  2s .  c o  m*/
    case Gradient.INTERPOLATION_RGB:
        gradientElement.addAttribute("interpolation", "rgb");
        break;
    }
    switch (gradient.getSpreadMethod()) {
    case Gradient.SPREAD_PAD:
        gradientElement.addAttribute("spread", "pad");
        break;
    case Gradient.SPREAD_REFLECT:
        gradientElement.addAttribute("spread", "reflect");
        break;
    case Gradient.SPREAD_REPEAT:
        gradientElement.addAttribute("spread", "repeat");
        break;
    }
    MorphGradRecord[] records = gradient.getGradientRecords();
    for (int i = 0; i < records.length; i++) {
        MorphGradRecord record = records[i];
        Element recordElement = gradientElement.addElement("morphgradrecord");
        Element start = recordElement.addElement("start");
        start.addAttribute("ratio", Short.toString(record.getStartRatio()));
        writeRGBA(start, "color", record.getStartColor());
        Element end = recordElement.addElement("end");
        end.addAttribute("ratio", Short.toString(record.getEndRatio()));
        writeRGBA(end, "color", record.getEndColor());
    }
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writePix15Array(Element parentElement, Pix15[] data) {
    Element element = parentElement.addElement("pix15array");
    byte[] buffer = new byte[data.length * 3];
    for (int i = 0; i < data.length; i++) {
        Pix15 pix15 = data[i];/*from  w w w . j a  v  a 2s .  c  o m*/
        buffer[i * 3] = pix15.getRed();
        buffer[(i * 3) + 1] = pix15.getGreen();
        buffer[(i * 3) + 2] = pix15.getBlue();
    }
    element.addText(Base64.encode(buffer));
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writePix24Array(Element parentElement, Pix24[] data) {
    Element element = parentElement.addElement("pix24array");
    short[] buffer = new short[data.length * 3];
    for (int i = 0; i < data.length; i++) {
        Pix24 pix24 = data[i];/*from  w ww .j a  v a2s  .  c om*/
        buffer[i * 3] = pix24.getRed();
        buffer[(i * 3) + 1] = pix24.getGreen();
        buffer[(i * 3) + 2] = pix24.getBlue();
    }
    element.addText(Base64.encodeUnsigned(buffer));
}

From source file:com.jswiff.xml.RecordXMLWriter.java

License:Open Source License

private static void writeRGBAArray(Element parentElement, RGBA[] data) {
    Element element = parentElement.addElement("rgbaarray");
    short[] buffer = new short[data.length * 4];
    for (int i = 0; i < data.length; i++) {
        RGBA rgba = data[i];//from   w  ww.  j  a  v  a 2s .  com
        buffer[i * 4] = rgba.getRed();
        buffer[(i * 4) + 1] = rgba.getGreen();
        buffer[(i * 4) + 2] = rgba.getBlue();
        buffer[(i * 4) + 3] = rgba.getAlpha();
    }
    element.addText(Base64.encodeUnsigned(buffer));
}