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.iterzp.momo.utils.SettingUtils.java

License:Open Source License

/**
 * //from   w  w w. jav a  2  s .c om
 * 
 * @param setting
 *            
 */
public static void set(Setting setting) {
    try {
        File shopxxXmlFile = new ClassPathResource(CommonAttributes.MOMO_XML_PATH).getFile();
        Document document = new SAXReader().read(shopxxXmlFile);
        List<Element> elements = document.selectNodes("/momo/setting");
        for (Element element : elements) {
            try {
                String name = element.attributeValue("name");
                String value = beanUtils.getProperty(setting, name);
                Attribute attribute = element.attribute("value");
                attribute.setValue(value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }

        FileOutputStream fileOutputStream = null;
        XMLWriter xmlWriter = null;
        try {
            OutputFormat outputFormat = OutputFormat.createPrettyPrint();
            outputFormat.setEncoding("UTF-8");
            outputFormat.setIndent(true);
            outputFormat.setIndent("   ");
            outputFormat.setNewlines(true);
            fileOutputStream = new FileOutputStream(shopxxXmlFile);
            xmlWriter = new XMLWriter(fileOutputStream, outputFormat);
            xmlWriter.write(document);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (xmlWriter != null) {
                try {
                    xmlWriter.close();
                } catch (IOException e) {
                }
            }
            IOUtils.closeQuietly(fileOutputStream);
        }

        Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME);
        cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.jasperserver.export.ImporterImpl.java

License:Open Source License

protected void process() {
    Document indexDocument = readIndexDocument();
    Element indexRoot = indexDocument.getRootElement();

    Properties properties = new Properties();
    for (Iterator it = indexRoot.elementIterator(getPropertyElementName()); it.hasNext();) {
        Element propElement = (Element) it.next();
        String propKey = propElement.attribute(getPropertyNameAttribute()).getValue();
        Attribute valueAttr = propElement.attribute(getPropertyValueAttribute());
        String value = valueAttr == null ? null : valueAttr.getValue();
        properties.setProperty(propKey, value);
    }// w  ww  .  ja va  2s.c o  m
    input.propertiesRead(properties);

    Attributes contextAttributes = createContextAttributes();
    contextAttributes.setAttribute("sourceJsVersion", properties.getProperty(VERSION_ATTR));
    contextAttributes.setAttribute("targetJsVersion", super.getJsVersion());

    for (Iterator it = indexRoot.elementIterator(getIndexModuleElementName()); it.hasNext();) {
        if (Thread.interrupted()) {
            throw new RuntimeException("Cancelled");
        }
        Element moduleElement = (Element) it.next();
        String moduleId = moduleElement.attribute(getIndexModuleIdAttributeName()).getValue();
        ImporterModule module = getModuleRegister().getImporterModule(moduleId);
        if (module == null) {
            throw new JSException("jsexception.import.module.not.found", new Object[] { moduleId });
        }

        commandOut.debug("Invoking module " + module);

        contextAttributes.setAttribute("appContext", this.task.getApplicationContext());
        ModuleContextImpl moduleContext = new ModuleContextImpl(moduleElement, contextAttributes);
        module.init(moduleContext);

        List<String> messages = new ArrayList<String>();
        ImportRunMonitor.start();
        try {
            List<String> moduleMessages = module.process();
            if (moduleMessages != null) {
                messages.addAll(moduleMessages);
            }
        } finally {
            ImportRunMonitor.stop();
            for (String message : messages) {
                commandOut.info(message);
            }
        }
    }
}

From source file:com.jeeframework.util.xml.XMLProperties.java

License:Open Source License

/**
 * Returns the value of the specified property.
 *
 * @param name        the name of the property to get.
 * @param ignoreEmpty Ignore empty property values (return null)
 * @return the value of the specified property.
 *///from  ww w .j  a  v  a 2 s . c om
public synchronized String getProperty(String name, boolean ignoreEmpty) {
    String value = propertyCache.get(name);
    if (value != null) {
        return value;
    }

    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML hierarchy.
    Element element = document.getRootElement();
    for (String aPropName : propName) {
        element = element.element(aPropName);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return null.
            return null;
        }
    }
    // At this point, we found a matching property, so return its value.
    // Empty strings are returned as null.
    value = element.getTextTrim();
    if (ignoreEmpty && "".equals(value)) {
        return null;
    } else {
        // check to see if the property is marked as encrypted
        Attribute encrypted = element.attribute(ENCRYPTED_ATTRIBUTE);
        if (encrypted != null) {
            value = EncryptUtil.desDecrypt(encryptKey, value);
        }
        //            else {
        //                // rewrite property as an encrypted value
        //                Log.info("Rewriting XML property " + name + " as an encrypted value");
        //                setProperty(name, value, false);
        //            }
        // Add to cache so that getting property next time is fast.
        propertyCache.put(name, value);
        return value;
    }
}

From source file:com.jeeframework.util.xml.XMLProperties.java

License:Open Source License

/**
 * Return all values who's path matches the given property
 * name as a String array, or an empty array if the if there
 * are no children. This allows you to retrieve several values
 * with the same property name. For example, consider the
 * XML file entry://ww  w .  j  ava  2 s. co m
 * <pre>
 * &lt;foo&gt;
 *     &lt;bar&gt;
 *         &lt;prop&gt;some value&lt;/prop&gt;
 *         &lt;prop&gt;other value&lt;/prop&gt;
 *         &lt;prop&gt;last value&lt;/prop&gt;
 *     &lt;/bar&gt;
 * &lt;/foo&gt;
 * </pre>
 * If you call getProperties("foo.bar.prop") will return a string array containing
 * {"some value", "other value", "last value"}.
 *
 * @param name the name of the property to retrieve
 * @return all child property values for the given node name.
 */
public List<String> getProperties(String name, boolean asList) {
    List<String> result = new ArrayList<String>();
    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML hierarchy,
    // stopping one short.
    Element element = document.getRootElement();
    for (int i = 0; i < propName.length - 1; i++) {
        element = element.element(propName[i]);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return empty array.
            return result;
        }
    }
    // We found matching property, return names of children.
    Iterator<Element> iter = element.elementIterator(propName[propName.length - 1]);
    Element prop;
    String value;
    boolean updateEncryption = false;
    while (iter.hasNext()) {
        prop = iter.next();
        // Empty strings are skipped.
        value = prop.getTextTrim();
        if (!"".equals(value)) {
            // check to see if the property is marked as encrypted
            Attribute encrypted = prop.attribute(ENCRYPTED_ATTRIBUTE);
            if (encrypted != null) {
                value = EncryptUtil.desDecrypt(encryptKey, value);
            } else {
                // rewrite property as an encrypted value
                prop.addAttribute(ENCRYPTED_ATTRIBUTE, "true");
                updateEncryption = true;
            }
            result.add(value);
        }
    }
    if (updateEncryption) {
        Log.info("Rewriting values for XML property " + name + " using encryption");
        saveProperties();
    }
    return result;
}

From source file:com.jeeframework.util.xml.XMLProperties.java

License:Open Source License

/**
 * Return all values who's path matches the given property
 * name as a String array, or an empty array if the if there
 * are no children. This allows you to retrieve several values
 * with the same property name. For example, consider the
 * XML file entry:/*  w  w w  . j a va2s. c om*/
 * <pre>
 * &lt;foo&gt;
 *     &lt;bar&gt;
 *         &lt;prop&gt;some value&lt;/prop&gt;
 *         &lt;prop&gt;other value&lt;/prop&gt;
 *         &lt;prop&gt;last value&lt;/prop&gt;
 *     &lt;/bar&gt;
 * &lt;/foo&gt;
 * </pre>
 * If you call getProperties("foo.bar.prop") will return a string array containing
 * {"some value", "other value", "last value"}.
 *
 * @param name the name of the property to retrieve
 * @return all child property values for the given node name.
 */
public Iterator getChildProperties(String name) {
    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML hierarchy,
    // stopping one short.
    Element element = document.getRootElement();
    for (int i = 0; i < propName.length - 1; i++) {
        element = element.element(propName[i]);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return empty array.
            return Collections.EMPTY_LIST.iterator();
        }
    }
    // We found matching property, return values of the children.
    Iterator<Element> iter = element.elementIterator(propName[propName.length - 1]);
    ArrayList<String> props = new ArrayList<String>();
    Element prop;
    String value;
    while (iter.hasNext()) {
        prop = iter.next();
        value = prop.getText();
        // check to see if the property is marked as encrypted
        if (Boolean.parseBoolean(prop.attribute(ENCRYPTED_ATTRIBUTE).getText())) {
            value = EncryptUtil.desDecrypt(encryptKey, value);
        }
        props.add(value);
    }
    return props.iterator();
}

From source file:com.jeeframework.util.xml.XMLProperties.java

License:Open Source License

/**
 * Removes the given attribute from the XML document.
 *
 * @param name      the property name to lookup - ie, "foo.bar"
 * @param attribute the name of the attribute, ie "id"
 * @return the value of the attribute of the given property or <tt>null</tt> if
 * it did not exist./*w  w  w  .  j a  va 2s.c  om*/
 */
public String removeAttribute(String name, String attribute) {
    if (name == null || attribute == null) {
        return null;
    }
    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML hierarchy.
    Element element = document.getRootElement();
    for (String child : propName) {
        element = element.element(child);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return empty array.
            break;
        }
    }
    String result = null;
    if (element != null) {
        // Get the attribute value and then remove the attribute
        Attribute attr = element.attribute(attribute);
        result = attr.getValue();
        element.remove(attr);
    }
    return result;
}

From source file:com.jfaker.framework.flow.web.ProcessController.java

License:Apache License

/**
 * ???/*from  w ww .  ja v a  2  s  .com*/
 */
public void getProcessTaskInfo() {
    Process process = engine.process().getProcessById(getPara(PARA_PROCESSID));
    //Process process = engine.process().getProcessById("23e85c95caf74a9eaef8cc9df9594448");
    String flowId = this.getPara("flowId");
    String flowName = this.getPara("flowName");
    setAttr("process", process);
    if (process.getDBContent() != null) {
        try {
            String content = new String(process.getDBContent(), "UTF-8");
            System.out.println(new String(process.getDBContent(), "UTF-8"));
            Document document = DocumentHelper.parseText(content);
            Element rootEle = document.getRootElement();
            List taskNodes = rootEle.elements("task");
            List<Object> list = new ArrayList<Object>();
            Map map = null;
            for (Iterator it = taskNodes.iterator(); it.hasNext();) {
                map = new HashMap();
                Element elm = (Element) it.next();
                map.put("processId", process.getId());
                map.put("processName", process.getName());
                map.put("SUB_FLOW_ID", flowId);
                map.put("FLOW_NAME", flowName);
                map.put("tacheCode", elm.attribute("name").getText());
                map.put("tachName", elm.attribute("displayName").getText());
                list.add(map);

            }
            setAttr("tacheList", list);
            renderJson(list);
            //renderJson(JSONArray.fromObject(list).toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.jonschang.ai.network.feedforward.FeedForwardXmlUnmarshaller.java

License:LGPL

public void unmarshal(FeedForward obj, Reader xmlReader) throws XmlException {
    SAXReader reader = new SAXReader();
    Document doc = null;/*w w w .j  a  v  a 2 s . co  m*/

    try {
        doc = reader.read(xmlReader);
    } catch (Exception e) {
        throw new XmlException("Could not read the Xml document", e);
    }

    Element root = doc.getRootElement();
    Element current = null;

    Map<Integer, Neuron> intToNeuronMap = new HashMap<Integer, Neuron>();
    Map<Integer, Activator> intToActivatorMap = new HashMap<Integer, Activator>();
    int neuronIndex = 0, activators = 0;
    Attribute attr = null;
    Neuron neuron = null;
    Neuron outputNeuron = null;

    obj.getAllLayers().clear();

    // build all the neurons and cache them in an
    // index-to-neuron map
    for (Object e : root.elements())
        if (e instanceof Element) {
            current = (Element) e;

            if (current.getName().compareTo("layers") == 0) {
                for (Object layerObject : current.elements())
                    if (((Element) layerObject).getName().compareTo("layer") == 0) {
                        List<Neuron> thisLayer = new ArrayList<Neuron>();
                        for (Object neuronObject : ((Element) layerObject).elements())
                            if (((Element) neuronObject).getName().compareTo("neuron") == 0) {
                                neuron = new GenericNeuron();

                                intToNeuronMap.put(neuronIndex, neuron);

                                attr = ((Element) neuronObject).attribute("threshold");
                                neuron.setThreshold(Double.valueOf(attr.getValue()));

                                thisLayer.add(neuron);

                                neuronIndex++;
                            }
                        obj.getAllLayers().add(thisLayer);
                    }
            } else if (current.getName().compareTo("activators") == 0 && current.elements().size() > 0) {
                for (Object a : current.elements())
                    if (a instanceof Element) {
                        Element activator = (Element) a;
                        ActivatorXmlFactory axf = new ActivatorXmlFactory();
                        Activator activatorObject = null;
                        String clazz = activator.attributeValue("type");
                        try {
                            activatorObject = (Activator) Class.forName(clazz).newInstance();
                            @SuppressWarnings(value = "unchecked")
                            XmlUnmarshaller<Activator> m = (XmlUnmarshaller<Activator>) axf
                                    .getUnmarshaller(activatorObject);
                            m.unmarshal(activatorObject, new StringReader(activator.asXML()));
                        } catch (Exception cnfe) {
                            throw new XmlException(cnfe);
                        }
                        intToActivatorMap.put(activators, activatorObject);
                        activators++;
                    }

            }
        }

    // now that we've built a cross-reference of index-to-neuron
    // we can process the synapses and easily reconstruct
    // the connections between neurons
    Integer inputIndex = 0, outputIndex, activatorIndex = 0;
    Double weight;
    for (Object e : root.elements())
        if (((Element) e).getName().compareTo("layers") == 0) {
            for (Object layerObject : current.elements())
                if (((Element) layerObject).getName().compareTo("layer") == 0) {
                    for (Object neuronObject : ((Element) layerObject).elements())
                        if (((Element) neuronObject).getName().compareTo("neuron") == 0) {
                            current = (Element) neuronObject;

                            neuron = intToNeuronMap.get(inputIndex);

                            // set the activator 
                            attr = current.attribute("activator-index");
                            activatorIndex = Integer.valueOf(attr.getValue());
                            neuron.setActivator(intToActivatorMap.get(activatorIndex));

                            // process the out-going synapses of the neuron
                            if (current.element("synapses") != null
                                    && current.element("synapses").element("synapse") != null) {
                                for (Object e2 : current.element("synapses").elements())
                                    if (e2 instanceof Element) {
                                        current = (Element) e2;

                                        // get the synapses output neuron
                                        attr = current.attribute("output");
                                        outputIndex = Integer.valueOf(attr.getValue());
                                        outputNeuron = intToNeuronMap.get(outputIndex);

                                        // set the weight of the synapse
                                        attr = current.attribute("weight");
                                        weight = Double.valueOf(attr.getValue());
                                        Synapse s = new GenericSynapse();
                                        neuron.setSynapseTo(s, outputNeuron);
                                        s.setWeight(weight);
                                    }
                            }
                            inputIndex++;
                        }
                }
        }

    obj.getInputNeurons().clear();
    obj.getOutputNeurons().clear();
    obj.getInputNeurons().addAll(obj.getAllLayers().get(0));
    obj.getOutputNeurons().addAll(obj.getAllLayers().get(obj.getAllLayers().size() - 1));
}

From source file:com.jonschang.investing.stocks.service.YahooHistoricalStockQuoteService.java

License:LGPL

private void pullKeyEventData(String urlString, Stock stock, BusinessCalendar cal, TimeInterval interval,
        DateRange range, Map<Date, StockQuote> dateToQuoteMap) throws Exception {
    URL url = getDateYearsUrl(urlString, stock.getSymbol(), range.getStart(), range.getEnd());
    SAXReader reader = new SAXReader();
    Document doc = reader.read(url.openConnection().getInputStream());
    Element rootElement = doc.getRootElement();

    // ok, so the date range specifiable to the keyevents service is not very fine-grained,
    // therefore, we'll assume that if there are any StockEvent's at all in a StockQuote,
    // that we pulled them here at an earlier call.
    List<Element> seriesList = rootElement.elements("series");
    if (seriesList.size() != 1)
        throw new ServiceException(
                "Expecting only a single 'series' tag in the XML document returned from " + url.toURI());
    Element series = seriesList.get(0);

    List<Element> valuesList = series.elements("values");
    if (valuesList.size() != 1)
        throw new ServiceException(
                "Expecting only a single 'values' tag in the XML document returned from " + url.toURI());
    List<Element> values = valuesList.get(0).elements("value");

    int type = 0;
    if (urlString.compareTo(m_splitUrl) == 0)
        type = 1; // split
    else if (urlString.compareTo(m_dividendUrl) == 0)
        type = 2; // dividend
    StockEventSplit split = null;//from  w w  w.j  av a 2  s  .  com
    StockEventDividend div = null;

    List<Element> ps = series.elements("p");
    for (Element p : ps) {

        if (urlString.compareTo(m_splitUrl) == 0)
            split = new StockEventSplit();
        else if (urlString.compareTo(m_dividendUrl) == 0)
            div = new StockEventDividend();

        List<Element> theseValues = p.elements("v");
        if (theseValues.size() != values.size())
            throw new ServiceException("Expecting the number of 'v' tags to match the number of 'values'");

        Date vDate = new SimpleDateFormat("yyyyMMdd").parse(p.attribute("ref").getText());
        cal.setTimeInMillis(vDate.getTime());
        cal.normalizeToInterval(interval);
        vDate = cal.getTime();

        StockQuote quote = dateToQuoteMap.get(vDate);
        if (quote == null)
            continue;
        if (quote.getStockEvents() != null
                && !((type == 1 && stockEventsHas(StockEventSplit.class, quote.getStockEvents()))
                        || (type == 2 && stockEventsHas(StockEventDividend.class, quote.getStockEvents()))))
            continue;

        List<StockEvent> events = quote.getStockEvents();
        if (events == null) {
            events = new ArrayList<StockEvent>();
            quote.setStockEvents(events);
        }

        int idx = 0;
        for (Element v : theseValues) {
            Element value = values.get(idx);
            if (value.attribute("id").getText().compareTo("denominator") == 0) {
                split.setDenominator(Double.valueOf(v.getTextTrim()).floatValue());
            } else if (value.attribute("id").getText().compareTo("numerator") == 0) {
                split.setNumerator(Double.valueOf(v.getTextTrim()).floatValue());
            } else if (value.attribute("id").getText().compareTo("dividend") == 0) {
                div.setDividend(Double.valueOf(v.getTextTrim()));
            }
            idx++;
        }

        // split
        if (type == 1) {
            split.setStockQuote(quote);
            events.add(split);
        } else
        // dividend
        if (type == 2) {
            div.setStockQuote(quote);
            events.add(div);
        }
    }
}

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

License:Open Source License

static Action readAction(Element element) {
    String name = element.getName();
    Action action;//from w  w  w . j av  a  2  s  . c o m
    if (name.equals("add")) {
        action = new Add();
    } else if (name.equals("add2")) {
        action = new Add2();
    } else if (name.equals("and")) {
        action = new And();
    } else if (name.equals("asciitochar")) {
        action = new AsciiToChar();
    } else if (name.equals("bitand")) {
        action = new BitAnd();
    } else if (name.equals("bitlshift")) {
        action = new BitLShift();
    } else if (name.equals("bitor")) {
        action = new BitOr();
    } else if (name.equals("bitrshift")) {
        action = new BitRShift();
    } else if (name.equals("biturshift")) {
        action = new BitURShift();
    } else if (name.equals("bitxor")) {
        action = new BitXor();
    } else if (name.equals("call")) {
        action = new Call();
    } else if (name.equals("callfunction")) {
        action = new CallFunction();
    } else if (name.equals("callmethod")) {
        action = new CallMethod();
    } else if (name.equals("castop")) {
        action = new CastOp();
    } else if (name.equals("chartoascii")) {
        action = new CharToAscii();
    } else if (name.equals("clonesprite")) {
        action = new CloneSprite();
    } else if (name.equals("constantpool")) {
        action = readConstantPool(element);
    } else if (name.equals("decrement")) {
        action = new Decrement();
    } else if (name.equals("definefunction")) {
        action = readDefineFunction(element);
    } else if (name.equals("definefunction2")) {
        action = readDefineFunction2(element);
    } else if (name.equals("definelocal")) {
        action = new DefineLocal();
    } else if (name.equals("definelocal2")) {
        action = new DefineLocal2();
    } else if (name.equals("delete")) {
        action = new Delete();
    } else if (name.equals("delete2")) {
        action = new Delete2();
    } else if (name.equals("divide")) {
        action = new Divide();
    } else if (name.equals("enddrag")) {
        action = new EndDrag();
    } else if (name.equals("enumerate")) {
        action = new Enumerate();
    } else if (name.equals("enumerate2")) {
        action = new Enumerate2();
    } else if (name.equals("equals")) {
        action = new Equals();
    } else if (name.equals("equals2")) {
        action = new Equals2();
    } else if (name.equals("extends")) {
        action = new Extends();
    } else if (name.equals("getmember")) {
        action = new GetMember();
    } else if (name.equals("getproperty")) {
        action = new GetProperty();
    } else if (name.equals("gettime")) {
        action = new GetTime();
    } else if (name.equals("geturl")) {
        action = readGetURL(element);
    } else if (name.equals("geturl2")) {
        action = readGetURL2(element);
    } else if (name.equals("getvariable")) {
        action = new GetVariable();
    } else if (name.equals("gotoframe")) {
        action = readGoToFrame(element);
    } else if (name.equals("gotoframe2")) {
        action = readGoToFrame2(element);
    } else if (name.equals("gotolabel")) {
        action = readGoToLabel(element);
    } else if (name.equals("greater")) {
        action = new Greater();
    } else if (name.equals("if")) {
        action = readIf(element);
    } else if (name.equals("implementsop")) {
        action = new ImplementsOp();
    } else if (name.equals("increment")) {
        action = new Increment();
    } else if (name.equals("initarray")) {
        action = new InitArray();
    } else if (name.equals("initobject")) {
        action = new InitObject();
    } else if (name.equals("instanceof")) {
        action = new InstanceOf();
    } else if (name.equals("jump")) {
        action = readJump(element);
    } else if (name.equals("less")) {
        action = new Less();
    } else if (name.equals("less2")) {
        action = new Less2();
    } else if (name.equals("mbasciitochar")) {
        action = new MBAsciiToChar();
    } else if (name.equals("mbchartoascii")) {
        action = new MBCharToAscii();
    } else if (name.equals("mbstringextract")) {
        action = new MBStringExtract();
    } else if (name.equals("mbstringlength")) {
        action = new MBStringLength();
    } else if (name.equals("modulo")) {
        action = new Modulo();
    } else if (name.equals("multiply")) {
        action = new Multiply();
    } else if (name.equals("newmethod")) {
        action = new NewMethod();
    } else if (name.equals("newobject")) {
        action = new NewObject();
    } else if (name.equals("nextframe")) {
        action = new NextFrame();
    } else if (name.equals("not")) {
        action = new Not();
    } else if (name.equals("or")) {
        action = new Or();
    } else if (name.equals("play")) {
        action = new Play();
    } else if (name.equals("pop")) {
        action = new Pop();
    } else if (name.equals("previousframe")) {
        action = new PreviousFrame();
    } else if (name.equals("push")) {
        action = readPush(element);
    } else if (name.equals("pushduplicate")) {
        action = new PushDuplicate();
    } else if (name.equals("randomnumber")) {
        action = new RandomNumber();
    } else if (name.equals("removesprite")) {
        action = new RemoveSprite();
    } else if (name.equals("return")) {
        action = new Return();
    } else if (name.equals("setmember")) {
        action = new SetMember();
    } else if (name.equals("setproperty")) {
        action = new SetProperty();
    } else if (name.equals("settarget")) {
        action = readSetTarget(element);
    } else if (name.equals("settarget2")) {
        action = new SetTarget2();
    } else if (name.equals("setvariable")) {
        action = new SetVariable();
    } else if (name.equals("stackswap")) {
        action = new StackSwap();
    } else if (name.equals("startdrag")) {
        action = new StartDrag();
    } else if (name.equals("stop")) {
        action = new Stop();
    } else if (name.equals("stopsounds")) {
        action = new StopSounds();
    } else if (name.equals("storeregister")) {
        action = readStoreRegister(element);
    } else if (name.equals("strictequals")) {
        action = new StrictEquals();
    } else if (name.equals("stringadd")) {
        action = new StringAdd();
    } else if (name.equals("stringequals")) {
        action = new StringEquals();
    } else if (name.equals("stringextract")) {
        action = new StringExtract();
    } else if (name.equals("stringgreater")) {
        action = new StringGreater();
    } else if (name.equals("stringlength")) {
        action = new StringLength();
    } else if (name.equals("stringless")) {
        action = new StringLess();
    } else if (name.equals("subtract")) {
        action = new Subtract();
    } else if (name.equals("targetpath")) {
        action = new TargetPath();
    } else if (name.equals("throw")) {
        action = new Throw();
    } else if (name.equals("tointeger")) {
        action = new ToInteger();
    } else if (name.equals("tonumber")) {
        action = new ToNumber();
    } else if (name.equals("tostring")) {
        action = new ToString();
    } else if (name.equals("togglequality")) {
        action = new ToggleQuality();
    } else if (name.equals("trace")) {
        action = new Trace();
    } else if (name.equals("try")) {
        action = readTry(element);
    } else if (name.equals("typeof")) {
        action = new TypeOf();
    } else if (name.equals("waitforframe")) {
        action = readWaitForFrame(element);
    } else if (name.equals("waitforframe2")) {
        action = readWaitForFrame2(element);
    } else if (name.equals("with")) {
        action = readWith(element);
    } else if (name.equals("unknownaction")) {
        action = readUnknownAction(element);
    } else {
        throw new IllegalArgumentException("Unexpected action record name: " + name);
    }
    Attribute label = element.attribute("label");
    if (label != null) {
        action.setLabel(label.getValue());
    }
    return action;
}