Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

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

License:Open Source License

static AlignmentZone[] readAlignmentZones(Element parentElement) {
    Element zonesElement = getElement("zones", parentElement);
    List zoneElements = zonesElement.elements("zone");
    int zonesCount = zoneElements.size();
    AlignmentZone[] zones = new AlignmentZone[zonesCount];
    for (int i = 0; i < zonesCount; i++) {
        Element zoneElement = (Element) zoneElements.get(i);
        AlignmentZone zone = new AlignmentZone();
        Attribute leftAttribute = zoneElement.attribute("left");
        if (leftAttribute != null) {
            float left = Float.parseFloat(leftAttribute.getValue());
            float width = getFloatAttribute("width", zoneElement);
            zone.setX(left, width);/*from   www. ja  v  a 2  s .com*/
        }
        Attribute baselineAttribute = zoneElement.attribute("baseline");
        if (baselineAttribute != null) {
            float baseline = Float.parseFloat(baselineAttribute.getValue());
            float height = getFloatAttribute("height", zoneElement);
            zone.setY(baseline, height);
        }
        zones[i] = zone;
    }
    return zones;
}

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

License:Open Source License

static ButtonCondAction[] readButtonCondActions(Element parentElement) {
    Element actionsElement = parentElement.element("actions");
    if (actionsElement != null) {
        List actions = actionsElement.elements();
        int arraySize = actions.size();
        ButtonCondAction[] actionArray = new ButtonCondAction[arraySize];
        for (int i = 0; i < arraySize; i++) {
            ButtonCondAction action = new ButtonCondAction();
            Element actionElement = (Element) actions.get(i);
            if (getBooleanAttribute("outdowntoidle", actionElement)) {
                action.setOutDownToIdle();
            }//from   w  ww.  ja  va2s.c o  m
            if (getBooleanAttribute("outdowntooverdown", actionElement)) {
                action.setOutDownToOverDown();
            }
            if (getBooleanAttribute("idletooverdown", actionElement)) {
                action.setIdleToOverDown();
            }
            if (getBooleanAttribute("idletooverup", actionElement)) {
                action.setIdleToOverUp();
            }
            if (getBooleanAttribute("overdowntoidle", actionElement)) {
                action.setOverDownToIdle();
            }
            if (getBooleanAttribute("overdowntooutdown", actionElement)) {
                action.setOverDownToOutDown();
            }
            if (getBooleanAttribute("overdowntooverup", actionElement)) {
                action.setOverDownToOverUp();
            }
            if (getBooleanAttribute("overuptoidle", actionElement)) {
                action.setOverUpToIdle();
            }
            if (getBooleanAttribute("overuptooverdown", actionElement)) {
                action.setOverUpToOverDown();
            }
            Attribute keyPress = actionElement.attribute("keypress");
            if (keyPress != null) {
                action.setKeyPress(Byte.parseByte(keyPress.getValue()));
            }
            readActionBlock(action.getActions(), actionElement);
            actionArray[i] = action;
        }
        return actionArray;
    }
    return null;
}

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

License:Open Source License

static ClipActions readClipActions(Element element) {
    ClipEventFlags eventFlags = readClipEventFlags(element);
    List recordElements = element.elements("clipactionrecord");
    List records = new ArrayList();
    for (Iterator it = recordElements.iterator(); it.hasNext();) {
        Element recordElement = (Element) it.next();
        ClipActionRecord record = new ClipActionRecord(readClipEventFlags(recordElement));
        Attribute keyCode = recordElement.attribute("keycode");
        if (keyCode != null) {
            record.setKeyCode(Short.parseShort(keyCode.getValue()));
        }/*  w  ww  .ja v a2s. c  om*/
        readActionBlock(record.getActions(), recordElement);
        records.add(record);
    }
    return new ClipActions(eventFlags, records);
}

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

License:Open Source License

static SoundInfo readSoundInfo(Element parentElement) {
    Element element = getElement("soundinfo", parentElement);
    SoundInfo soundInfo = new SoundInfo();
    if (getBooleanAttribute("syncstop", element)) {
        soundInfo.setSyncStop();/*from w  w w  .  j a v  a2 s . c om*/
    }
    if (getBooleanAttribute("syncnomultiple", element)) {
        soundInfo.setSyncNoMultiple();
    }
    Attribute loopCount = element.attribute("loopcount");
    if (loopCount != null) {
        soundInfo.setLoopCount(Integer.parseInt(loopCount.getValue()));
    }
    Attribute inPoint = element.attribute("inpoint");
    if (inPoint != null) {
        soundInfo.setInPoint(Integer.parseInt(inPoint.getValue()));
    }
    Element envelopeRecordsElement = element.element("enveloperecords");
    if (envelopeRecordsElement != null) {
        soundInfo.setEnvelopeRecords(readSoundEnvelopeRecords(envelopeRecordsElement));
    }
    return soundInfo;
}

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

License:Open Source License

static TextRecord[] readTextRecords(Element parentElement) {
    Element element = getElement("textrecords", parentElement);
    List recordElements = element.elements();
    int arrayLength = recordElements.size();
    TextRecord[] records = new TextRecord[arrayLength];
    for (int i = 0; i < arrayLength; i++) {
        Element recordElement = (Element) recordElements.get(i);
        GlyphEntry[] glyphEntries = readGlyphEntries(recordElement);
        TextRecord record = new TextRecord(glyphEntries);
        Attribute fontId = recordElement.attribute("fontid");
        if (fontId != null) {
            record.setFont(Integer.parseInt(fontId.getValue()), getIntAttribute("height", recordElement));
        }//www .j a v a  2s. c  o  m
        Attribute xOffset = recordElement.attribute("xoffset");
        if (xOffset != null) {
            record.setXOffset(Short.parseShort(xOffset.getValue()));
        }
        Attribute yOffset = recordElement.attribute("yoffset");
        if (yOffset != null) {
            record.setYOffset(Short.parseShort(yOffset.getValue()));
        }
        Element color = recordElement.element("color");
        if (color != null) {
            record.setTextColor(RecordXMLReader.readColor(color));
        }
        records[i] = record;
    }
    return records;
}

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

License:Open Source License

private static ShapeRecord readStyleChangeRecord(Element element) {
    StyleChangeRecord record = new StyleChangeRecord();
    Element moveTo = element.element("moveto");
    if (moveTo != null) {
        record.setMoveTo(getIntAttribute("x", moveTo), getIntAttribute("y", moveTo));
    }/*ww w.j a va 2 s  .  c om*/
    Element styles = element.element("styles");
    if (styles != null) {
        Attribute line = styles.attribute("line");
        if (line != null) {
            record.setLineStyle(Integer.parseInt(line.getValue()));
        }
        Attribute fill0 = styles.attribute("fill0");
        if (fill0 != null) {
            record.setFillStyle0(Integer.parseInt(fill0.getValue()));
        }
        Attribute fill1 = styles.attribute("fill1");
        if (fill1 != null) {
            record.setFillStyle1(Integer.parseInt(fill1.getValue()));
        }
        Element newLineStyles = styles.element("linestyles");
        if (newLineStyles != null) {
            // new line styles always come together with new fill styles
            Element newFillStyles = getElement("fillstyles", styles);
            record.setNewStyles(readLineStyles(newLineStyles), readFillStyles(newFillStyles));
        }
    }
    return record;
}

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

License:Open Source License

private static String getStringAttribute(String attributeName, Element parentElement) {
    Attribute attribute = (Attribute) parentElement.selectSingleNode("@" + attributeName);
    if (attribute == null) {
        throw new MissingAttributeException(attributeName, parentElement.getPath());
    }/*from  w  w  w .  ja  va 2 s .co  m*/
    return attribute.getValue();
}

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. j a  v a2s . c o  m*/
    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 readDefineFont2(Element tagElement) {
    int characterId = RecordXMLReader.getCharacterId(tagElement);
    String fontName = getStringAttribute("fontname", tagElement);
    Shape[] glyphShapes = null;/*  www .  j a  v a 2 s .c o m*/
    char[] codeTable = null;
    short[] advanceTable = null;
    Rect[] boundsTable = null;
    boolean hasLayout = false;
    Element glyphShapeTableElement = tagElement.element("glyphshapetable");
    if (glyphShapeTableElement != null) {
        List glyphElements = glyphShapeTableElement.elements();
        int numGlyphs = glyphElements.size();
        advanceTable = new short[numGlyphs];
        boundsTable = new Rect[numGlyphs];
        glyphShapes = new Shape[numGlyphs];
        codeTable = new char[numGlyphs];
        for (int i = 0; i < numGlyphs; i++) {
            Element glyphElement = (Element) glyphElements.get(i);
            codeTable[i] = getStringAttribute("char", glyphElement).charAt(0);
            glyphShapes[i] = RecordXMLReader.readShape(RecordXMLReader.getElement("shape", glyphElement));
            Attribute advance = glyphElement.attribute("advance");
            if (advance != null) {
                hasLayout = true;
                advanceTable[i] = Short.parseShort(advance.getValue());
                boundsTable[i] = RecordXMLReader.readRect(RecordXMLReader.getElement("bounds", glyphElement));
            }
        }
    }
    DefineFont2 defineFont2 = new DefineFont2(characterId, fontName, glyphShapes, codeTable);
    if (hasLayout) {
        Element layout = RecordXMLReader.getElement("layout", tagElement);
        short ascent = RecordXMLReader.getShortAttribute("ascent", layout);
        short descent = RecordXMLReader.getShortAttribute("descent", layout);
        short leading = RecordXMLReader.getShortAttribute("leading", layout);
        KerningRecord[] kerningTable = null;
        Element kerningTableElement = layout.element("kerningtable");
        if (kerningTableElement != null) {
            List recordElements = kerningTableElement.elements();
            int arrayLength = recordElements.size();
            kerningTable = new KerningRecord[arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                Element recordElement = (Element) recordElements.get(i);
                char left = getStringAttribute("left", recordElement).charAt(0);
                char right = getStringAttribute("right", recordElement).charAt(0);
                short adjustment = RecordXMLReader.getShortAttribute("adjust", recordElement);
                kerningTable[i] = new KerningRecord(left, right, adjustment);
            }
        }
        defineFont2.setLayout(ascent, descent, leading, advanceTable, boundsTable, kerningTable);
    }
    if (RecordXMLReader.getBooleanAttribute("ansi", tagElement)) {
        defineFont2.setANSI(true);
    }
    if (RecordXMLReader.getBooleanAttribute("shiftjis", tagElement)) {
        defineFont2.setShiftJIS(true);
    }
    if (RecordXMLReader.getBooleanAttribute("bold", tagElement)) {
        defineFont2.setBold(true);
    }
    if (RecordXMLReader.getBooleanAttribute("italic", tagElement)) {
        defineFont2.setItalic(true);
    }
    if (RecordXMLReader.getBooleanAttribute("smalltext", tagElement)) {
        defineFont2.setSmallText(true);
    }
    defineFont2.setLanguageCode(readLangCode(tagElement));
    return defineFont2;
}

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

License:Open Source License

private static Tag readDefineFont3(Element tagElement) {
    int characterId = RecordXMLReader.getCharacterId(tagElement);
    String fontName = getStringAttribute("fontname", tagElement);
    Shape[] glyphShapes = null;//from  w w  w  .j a va2  s.  co  m
    char[] codeTable = null;
    short[] advanceTable = null;
    Rect[] boundsTable = null;
    boolean hasLayout = false;
    Element glyphShapeTableElement = tagElement.element("glyphshapetable");
    if (glyphShapeTableElement != null) {
        List glyphElements = glyphShapeTableElement.elements();
        int numGlyphs = glyphElements.size();
        advanceTable = new short[numGlyphs];
        boundsTable = new Rect[numGlyphs];
        glyphShapes = new Shape[numGlyphs];
        codeTable = new char[numGlyphs];
        for (int i = 0; i < numGlyphs; i++) {
            Element glyphElement = (Element) glyphElements.get(i);
            codeTable[i] = getStringAttribute("char", glyphElement).charAt(0);
            glyphShapes[i] = RecordXMLReader.readShape(RecordXMLReader.getElement("shape", glyphElement));
            Attribute advance = glyphElement.attribute("advance");
            if (advance != null) {
                hasLayout = true;
                advanceTable[i] = Short.parseShort(advance.getValue());
                boundsTable[i] = RecordXMLReader.readRect(RecordXMLReader.getElement("bounds", glyphElement));
            }
        }
    }
    DefineFont3 defineFont3 = new DefineFont3(characterId, fontName, glyphShapes, codeTable);
    if (hasLayout) {
        Element layout = RecordXMLReader.getElement("layout", tagElement);
        short ascent = RecordXMLReader.getShortAttribute("ascent", layout);
        short descent = RecordXMLReader.getShortAttribute("descent", layout);
        short leading = RecordXMLReader.getShortAttribute("leading", layout);
        KerningRecord[] kerningTable = null;
        Element kerningTableElement = layout.element("kerningtable");
        if (kerningTableElement != null) {
            List recordElements = kerningTableElement.elements();
            int arrayLength = recordElements.size();
            kerningTable = new KerningRecord[arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                Element recordElement = (Element) recordElements.get(i);
                char left = getStringAttribute("left", recordElement).charAt(0);
                char right = getStringAttribute("right", recordElement).charAt(0);
                short adjustment = RecordXMLReader.getShortAttribute("adjust", recordElement);
                kerningTable[i] = new KerningRecord(left, right, adjustment);
            }
        }
        defineFont3.setLayout(ascent, descent, leading, advanceTable, boundsTable, kerningTable);
    }
    if (RecordXMLReader.getBooleanAttribute("bold", tagElement)) {
        defineFont3.setBold(true);
    }
    if (RecordXMLReader.getBooleanAttribute("italic", tagElement)) {
        defineFont3.setItalic(true);
    }
    if (RecordXMLReader.getBooleanAttribute("smalltext", tagElement)) {
        defineFont3.setSmallText(true);
    }
    defineFont3.setLanguageCode(readLangCode(tagElement));
    return defineFont3;
}