Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

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

License:Open Source License

static byte[] getDataElement(String elementName, Element parentElement) {
    Element element = parentElement.element(elementName);
    if (element == null) {
        throw new MissingElementException(elementName, parentElement.getPath());
    }//from ww w  .  ja  v a  2 s.  c o m
    return Base64.decode(element.getText());
}

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

License:Open Source License

static List readFilters(Element element) {
    List filterElements = element.elements();
    int filterCount = filterElements.size();
    List filters = new ArrayList(filterCount);
    for (int j = 0; j < filterCount; j++) {
        Element filterElement = (Element) filterElements.get(j);
        if (filterElement.getName().equals("colormatrix")) {
            List valElements = filterElement.elements("val");
            int valCount = valElements.size();
            if (valCount != 20) {
                throw new MalformedElementException("colormatrix must contain 20 values!");
            }//from  ww  w . j  a  v  a  2  s .c om
            float[] matrix = new float[20];
            for (int i = 0; i < 20; i++) {
                Element valElement = (Element) valElements.get(i);
                matrix[i] = Float.parseFloat(valElement.getText());
            }
            ColorMatrixFilter colorMatrixFilter = new ColorMatrixFilter(matrix);
            filters.add(colorMatrixFilter);
        } else if (filterElement.getName().equals("convolution")) {
            Element matrixElement = filterElement.element("matrix");
            List valElements = matrixElement.elements("val");
            float[] matrix = new float[valElements.size()];
            for (int i = 0; i < matrix.length; i++) {
                Element valElement = (Element) valElements.get(i);
                matrix[i] = Float.parseFloat(valElement.getText());
            }
            int matrixRows = getIntAttribute("rows", matrixElement);
            ConvolutionFilter convolutionFilter = new ConvolutionFilter(matrix, matrixRows);
            convolutionFilter.setColor(readRGBA(getElement("color", filterElement)));
            convolutionFilter.setDivisor(getFloatAttribute("divisor", filterElement));
            convolutionFilter.setBias(getFloatAttribute("bias", filterElement));
            convolutionFilter.setClamp(getBooleanAttribute("clamp", filterElement));
            convolutionFilter.setPreserveAlpha(getBooleanAttribute("preservealpha", filterElement));
            filters.add(convolutionFilter);
        } else if (filterElement.getName().equals("blur")) {
            BlurFilter blurFilter = new BlurFilter(getDoubleAttribute("x", filterElement),
                    getDoubleAttribute("y", filterElement));
            blurFilter.setQuality(getIntAttribute("quality", filterElement));
            filters.add(blurFilter);
        } else if (filterElement.getName().equals("dropshadow")) {
            DropShadowFilter dropShadowFilter = new DropShadowFilter();
            dropShadowFilter.setColor(readRGBA(getElement("color", filterElement)));
            dropShadowFilter.setX(getDoubleAttribute("x", filterElement));
            dropShadowFilter.setY(getDoubleAttribute("y", filterElement));
            dropShadowFilter.setAngle(getDoubleAttribute("angle", filterElement));
            dropShadowFilter.setDistance(getDoubleAttribute("distance", filterElement));
            dropShadowFilter.setStrength(getDoubleAttribute("strength", filterElement));
            dropShadowFilter.setQuality(getIntAttribute("quality", filterElement));
            dropShadowFilter.setInner(getBooleanAttribute("inner", filterElement));
            dropShadowFilter.setKnockout(getBooleanAttribute("knockout", filterElement));
            dropShadowFilter.setHideObject(getBooleanAttribute("hideobject", filterElement));
            filters.add(dropShadowFilter);
        } else if (filterElement.getName().equals("glow")) {
            GlowFilter glowFilter = new GlowFilter();
            glowFilter.setColor(readRGBA(getElement("color", filterElement)));
            glowFilter.setX(getDoubleAttribute("x", filterElement));
            glowFilter.setY(getDoubleAttribute("y", filterElement));
            glowFilter.setStrength(getDoubleAttribute("strength", filterElement));
            glowFilter.setQuality(getIntAttribute("quality", filterElement));
            glowFilter.setInner(getBooleanAttribute("inner", filterElement));
            glowFilter.setKnockout(getBooleanAttribute("knockout", filterElement));
            filters.add(glowFilter);
        } else if (filterElement.getName().equals("bevel")) {
            BevelFilter bevelFilter = new BevelFilter();
            bevelFilter.setHighlightColor(readRGBA(getElement("highlightcolor", filterElement)));
            bevelFilter.setShadowColor(readRGBA(getElement("shadowcolor", filterElement)));
            bevelFilter.setX(getDoubleAttribute("x", filterElement));
            bevelFilter.setY(getDoubleAttribute("y", filterElement));
            bevelFilter.setAngle(getDoubleAttribute("angle", filterElement));
            bevelFilter.setDistance(getDoubleAttribute("distance", filterElement));
            bevelFilter.setStrength(getDoubleAttribute("strength", filterElement));
            bevelFilter.setQuality(getIntAttribute("quality", filterElement));
            bevelFilter.setInner(getBooleanAttribute("inner", filterElement));
            bevelFilter.setKnockout(getBooleanAttribute("knockout", filterElement));
            bevelFilter.setOnTop(getBooleanAttribute("ontop", filterElement));
            filters.add(bevelFilter);
        } else if (filterElement.getName().equals("gradientglow")) {
            Element pointsElement = getElement("controlpoints", filterElement);
            List pointElements = pointsElement.elements("controlpoint");
            int controlPointsCount = pointElements.size();
            RGBA[] colors = new RGBA[controlPointsCount];
            short[] ratios = new short[controlPointsCount];
            for (int i = 0; i < controlPointsCount; i++) {
                Element pointElement = (Element) pointElements.get(i);
                colors[i] = readRGBA(getElement("color", pointElement));
                ratios[i] = getShortAttribute("ratio", pointElement);
            }
            GradientGlowFilter gradientGlowFilter = new GradientGlowFilter(colors, ratios);
            gradientGlowFilter.setX(getDoubleAttribute("x", filterElement));
            gradientGlowFilter.setY(getDoubleAttribute("y", filterElement));
            gradientGlowFilter.setAngle(getDoubleAttribute("angle", filterElement));
            gradientGlowFilter.setDistance(getDoubleAttribute("distance", filterElement));
            gradientGlowFilter.setStrength(getDoubleAttribute("strength", filterElement));
            gradientGlowFilter.setQuality(getIntAttribute("quality", filterElement));
            gradientGlowFilter.setInner(getBooleanAttribute("inner", filterElement));
            gradientGlowFilter.setKnockout(getBooleanAttribute("knockout", filterElement));
            gradientGlowFilter.setOnTop(getBooleanAttribute("ontop", filterElement));
            filters.add(gradientGlowFilter);
        } else if (filterElement.getName().equals("gradientbevel")) {
            Element pointsElement = getElement("controlpoints", filterElement);
            List pointElements = pointsElement.elements("controlpoint");
            int controlPointsCount = pointElements.size();
            RGBA[] colors = new RGBA[controlPointsCount];
            short[] ratios = new short[controlPointsCount];
            for (int i = 0; i < controlPointsCount; i++) {
                Element pointElement = (Element) pointElements.get(i);
                colors[i] = readRGBA(getElement("color", pointElement));
                ratios[i] = getShortAttribute("ratio", pointElement);
            }
            GradientBevelFilter gradientBevelFilter = new GradientBevelFilter(colors, ratios);
            gradientBevelFilter.setX(getDoubleAttribute("x", filterElement));
            gradientBevelFilter.setY(getDoubleAttribute("y", filterElement));
            gradientBevelFilter.setAngle(getDoubleAttribute("angle", filterElement));
            gradientBevelFilter.setDistance(getDoubleAttribute("distance", filterElement));
            gradientBevelFilter.setStrength(getDoubleAttribute("strength", filterElement));
            gradientBevelFilter.setQuality(getIntAttribute("quality", filterElement));
            gradientBevelFilter.setInner(getBooleanAttribute("inner", filterElement));
            gradientBevelFilter.setKnockout(getBooleanAttribute("knockout", filterElement));
            gradientBevelFilter.setOnTop(getBooleanAttribute("ontop", filterElement));
            filters.add(gradientBevelFilter);
        }
    }
    return filters;
}

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

License:Open Source License

static ZlibBitmapData readZlibBitmapData(Element parentElement) {
    // transparency not supported
    Element element = parentElement.element("bitmapdata");
    if (element != null) {
        return new BitmapData(readBitmapPixelData(element));
    }//  w  w  w.j  a v a2  s.c  o m
    element = parentElement.element("colormapdata");
    if (element != null) {
        Element colorTableElement = getElement("colortable", element);
        RGB[] colorTable = readRGBArray(colorTableElement);
        Element pixelDataElement = getElement("pixeldata", element);
        short[] pixelData = Base64.decodeUnsigned(pixelDataElement.getText());
        return new ColorMapData(colorTable, pixelData);
    }
    throw new MissingNodeException("Element " + parentElement.getPath()
            + " must contain either a bitmapdata or a colormapdata element!");
}

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

License:Open Source License

static ZlibBitmapData readZlibBitmapData2(Element parentElement) {
    // transparency supported
    Element element = parentElement.element("alphabitmapdata");
    if (element != null) {
        return new AlphaBitmapData(readRGBAArray(element));
    }/*  w w w . java2 s .  co m*/
    element = parentElement.element("alphacolormapdata");
    if (element != null) {
        Element colorTableElement = getElement("colortable", element);
        RGBA[] colorTable = readRGBAArray(colorTableElement);
        Element pixelDataElement = getElement("pixeldata", element);
        short[] pixelData = Base64.decodeUnsigned(pixelDataElement.getText());
        return new AlphaColorMapData(colorTable, pixelData);
    }
    throw new MissingNodeException("Element " + parentElement.getPath()
            + " must contain either an alphabitmapdata or an alphacolormapdata element!");
}

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

License:Open Source License

private static BitmapPixelData[] readBitmapPixelData(Element parentElement) {
    Element element = parentElement.element("pix15array");
    if (element != null) {
        byte[] buffer = Base64.decode(element.getText());
        int arrayLength = buffer.length / 3;
        Pix15[] array = new Pix15[arrayLength];
        for (int i = 0; i < arrayLength; i++) {
            int j = i * 3;
            array[i] = new Pix15(buffer[j], buffer[j + 1], buffer[j + 2]);
        }/*from w  w  w  . j a  va2s  . co m*/
        return array;
    }
    element = parentElement.element("pix24array");
    if (element != null) {
        short[] buffer = Base64.decodeUnsigned(element.getText());
        int arrayLength = buffer.length / 3;
        Pix24[] array = new Pix24[arrayLength];
        for (int i = 0; i < arrayLength; i++) {
            int j = i * 3;
            array[i] = new Pix24(buffer[j], buffer[j + 1], buffer[j + 2]);
        }
        return array;
    }
    throw new MissingNodeException("Element " + parentElement.getPath()
            + " must contain either a pix15array or a pix24array element!");
}

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

License:Open Source License

private static RGBA[] readRGBAArray(Element parentElement) {
    Element rgbaArrayElement = getElement("rgbaarray", parentElement);
    short[] buffer = Base64.decodeUnsigned(rgbaArrayElement.getText());
    int arrayLength = buffer.length / 4;
    RGBA[] rgbaArray = new RGBA[arrayLength];
    for (int i = 0; i < arrayLength; i++) {
        int j = i * 4;
        rgbaArray[i] = new RGBA(buffer[j], buffer[j + 1], buffer[j + 2], buffer[j + 3]);
    }/*w  w  w .  ja v  a2s  .c  o  m*/
    return rgbaArray;
}

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

License:Open Source License

private static RGB[] readRGBArray(Element parentElement) {
    Element rgbArrayElement = getElement("rgbarray", parentElement);
    short[] buffer = Base64.decodeUnsigned(rgbArrayElement.getText());
    int arrayLength = buffer.length / 3;
    RGB[] rgbArray = new RGB[arrayLength];
    for (int i = 0; i < arrayLength; i++) {
        int j = i * 3;
        rgbArray[i] = new RGB(buffer[j], buffer[j + 1], buffer[j + 2]);
    }/* w  ww  .jav  a 2  s . c  o  m*/
    return rgbArray;
}

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

License:Open Source License

static Tag readUnknownTag(Element tagElement) {
    short code = RecordXMLReader.getShortAttribute("code", tagElement);
    byte[] data = Base64.decode(tagElement.getText());
    return new UnknownTag(code, data);
}

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

License:Open Source License

private static Tag readDefineEditText(Element tagElement) {
    int characterId = RecordXMLReader.getCharacterId(tagElement);
    Rect bounds = RecordXMLReader.readRect(RecordXMLReader.getElement("bounds", tagElement));
    String var = tagElement.attributeValue("variable");
    DefineEditText defineEditText = new DefineEditText(characterId, bounds, var);
    if (RecordXMLReader.getBooleanAttribute("wordwrap", tagElement)) {
        defineEditText.setWordWrap(true);
    }//from   ww  w . ja  v  a2  s.  com
    if (RecordXMLReader.getBooleanAttribute("multiline", tagElement)) {
        defineEditText.setMultiline(true);
    }
    if (RecordXMLReader.getBooleanAttribute("password", tagElement)) {
        defineEditText.setPassword(true);
    }
    if (RecordXMLReader.getBooleanAttribute("readonly", tagElement)) {
        defineEditText.setReadOnly(true);
    }
    if (RecordXMLReader.getBooleanAttribute("autosize", tagElement)) {
        defineEditText.setAutoSize(true);
    }
    if (RecordXMLReader.getBooleanAttribute("noselect", tagElement)) {
        defineEditText.setNoSelect(true);
    }
    if (RecordXMLReader.getBooleanAttribute("border", tagElement)) {
        defineEditText.setBorder(true);
    }
    if (RecordXMLReader.getBooleanAttribute("border", tagElement)) {
        defineEditText.setBorder(true);
    }
    if (RecordXMLReader.getBooleanAttribute("html", tagElement)) {
        defineEditText.setHtml(true);
    }
    if (RecordXMLReader.getBooleanAttribute("useoutlines", tagElement)) {
        defineEditText.setUseOutlines(true);
    }
    Attribute maxLength = tagElement.attribute("maxlength");
    if (maxLength != null) {
        defineEditText.setMaxLength(Integer.parseInt(maxLength.getValue()));
    }
    Element initialText = tagElement.element("initialtext");
    if (initialText != null) {
        defineEditText.setInitialText(initialText.getText());
    }
    Element color = tagElement.element("color");
    if (color != null) {
        defineEditText.setTextColor(RecordXMLReader.readRGBA(color));
    }
    Element font = tagElement.element("font");
    if (font != null) {
        defineEditText.setFont(RecordXMLReader.getIntAttribute("fontid", font),
                RecordXMLReader.getIntAttribute("height", font));
    }
    Element layout = tagElement.element("layout");
    if (layout != null) {
        String alignString = getStringAttribute("align", layout);
        short align;
        if (alignString.equals("center")) {
            align = DefineEditText.ALIGN_CENTER;
        } else if (alignString.equals("justify")) {
            align = DefineEditText.ALIGN_JUSTIFY;
        } else if (alignString.equals("right")) {
            align = DefineEditText.ALIGN_RIGHT;
        } else {
            align = DefineEditText.ALIGN_LEFT;
        }
        int leftMargin = RecordXMLReader.getIntAttribute("leftmargin", layout);
        int rightMargin = RecordXMLReader.getIntAttribute("rightmargin", layout);
        int indent = RecordXMLReader.getIntAttribute("indent", layout);
        int leading = RecordXMLReader.getIntAttribute("leading", layout);
        defineEditText.setLayout(align, leftMargin, rightMargin, indent, leading);
    }
    return defineEditText;
}

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

License:Open Source License

private static Tag readDefineFontInfo(Element tagElement) {
    int fontId = RecordXMLReader.getIntAttribute("fontid", tagElement);
    String fontName = getStringAttribute("fontname", tagElement);
    List charElements = tagElement.elements();
    int arrayLength = charElements.size();
    char[] codeTable = new char[arrayLength];
    for (int i = 0; i < arrayLength; i++) {
        Element charElement = (Element) charElements.get(i);
        codeTable[i] = charElement.getText().charAt(0);
    }//  w w  w.  j  a  v  a2 s .c  o  m
    DefineFontInfo defineFontInfo = new DefineFontInfo(fontId, fontName, codeTable);
    if (RecordXMLReader.getBooleanAttribute("ansi", tagElement)) {
        defineFontInfo.setANSI(true);
    }
    if (RecordXMLReader.getBooleanAttribute("shiftjis", tagElement)) {
        defineFontInfo.setShiftJIS(true);
    }
    if (RecordXMLReader.getBooleanAttribute("bold", tagElement)) {
        defineFontInfo.setBold(true);
    }
    if (RecordXMLReader.getBooleanAttribute("italic", tagElement)) {
        defineFontInfo.setItalic(true);
    }
    if (RecordXMLReader.getBooleanAttribute("smalltext", tagElement)) {
        defineFontInfo.setSmallText(true);
    }
    return defineFontInfo;
}