Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

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

License:Open Source License

private static Try readTry(Element element) {
    Try tryAction;//www.j  a  va 2  s. com
    Attribute catchRegister = element.attribute("catchregister");
    if (catchRegister != null) {
        tryAction = new Try(Short.parseShort(catchRegister.getValue()));
    } else {
        Attribute catchVariable = element.attribute("catchvariable");
        if (catchVariable != null) {
            tryAction = new Try(catchVariable.getValue());
        } else {
            throw new MissingNodeException(
                    "Neither catch register nor catch variable specified within try action!");
        }
    }
    RecordXMLReader.readActionBlock(tryAction.getTryBlock(), RecordXMLReader.getElement("try", element));
    Element catchElement = element.element("catch");
    if (catchElement != null) {
        RecordXMLReader.readActionBlock(tryAction.getCatchBlock(), catchElement);
    }
    Element finallyElement = element.element("finally");
    if (finallyElement != null) {
        RecordXMLReader.readActionBlock(tryAction.getFinallyBlock(), finallyElement);
    }
    return tryAction;
}

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

License:Open Source License

static boolean getBooleanAttribute(String name, Element parentElement) {
    // boolean attributes are written only for "true" values
    Attribute attribute = parentElement.attribute(name);
    return ((attribute != null) && attribute.getValue().equalsIgnoreCase("true"));
}

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

License:Open Source License

static String getStringAttribute(String attributeName, Element parentElement) {
    Attribute attribute = parentElement.attribute(attributeName);
    if (attribute == null) {
        throw new MissingAttributeException(attributeName, parentElement.getPath());
    }//from  w  w w. j  a  v a 2s  . c  o  m
    return attribute.getValue();
}

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   w ww  .  j  a  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 ww  w .j  a v  a2s  . c  om
            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  w w .  ja v  a  2s  . c o  m
        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 Color readColor(Element element) {
    if (element.attribute("a") == null) {
        return readRGB(element);
    }/*from   w w  w .ja v  a  2 s. c  om*/
    return readRGBA(element);
}

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  av  a  2  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));
        }//from   w w w  .j  a v  a 2  s.com
        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));
    }// w  w  w.  ja v  a 2 s . co  m
    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;
}