Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

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

Prototype

List<Element> elements(QName qName);

Source Link

Document

Returns the elements contained in this element with the given fully qualified name.

Usage

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

private void parseQueries(Element bandElement, BandBuilder bandDefinitionBuilder) {
    Element reportQueriesElement = bandElement.element("queries");

    if (reportQueriesElement != null) {
        List<Element> reportQueryElements = reportQueriesElement.elements("query");
        for (Element queryElement : reportQueryElements) {
            String script = queryElement.element("script").getText();
            String type = queryElement.attribute("type").getText();
            String queryName = queryElement.attribute("name").getText();

            bandDefinitionBuilder.query(queryName, script, type);
        }/*from w ww . java2  s . co m*/
    }
}

From source file:com.iflytek.edu.cloud.frame.support.jdbc.CustomSQL.java

License:Apache License

protected void read(InputStream is) {

    if (is == null)
        return;/*from   w  w w.  java  2 s.  c  o m*/

    Document document;
    try {
        document = saxReader.read(is);
    } catch (DocumentException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    Element rootElement = document.getRootElement();

    for (Object sqlObj : rootElement.elements("sql")) {
        Element sqlElement = (Element) sqlObj;
        String id = sqlElement.attributeValue("id");
        String tempateType = sqlElement.attributeValue("tempateType");

        if ("simple".equals(tempateType) || "httl".equals(tempateType)) {
            String content = transform(sqlElement.getText());

            SQLBean bean = new SQLBean();
            bean.setTempateType(tempateType);
            bean.setContent(content);

            try {
                Template template = engine.parseTemplate(content);
                bean.setTemplate(template);
                _sqlPool.put(id, bean);
            } catch (ParseException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        } else {
            logger.warn("{}  tempateType  {} ??simplehttl", id,
                    tempateType);
        }
    }
}

From source file:com.iih5.smartorm.kit.SqlXmlKit.java

License:Apache License

private void init(File dataDir) {
    try {//w w  w.ja va 2 s .  c o  m
        List<File> files = new ArrayList<File>();
        listDirectory(dataDir, files);
        for (File file : files) {
            if (file.getName().contains(".xml")) {
                SAXReader reader = new SAXReader();
                Document document = reader.read(file);
                Element xmlRoot = document.getRootElement();
                for (Object e : xmlRoot.elements("class")) {
                    Map<String, String> methods = new HashMap<String, String>();
                    Element clasz = (Element) e;
                    for (Object ebj : clasz.elements("sql")) {
                        Element sql = (Element) ebj;
                        methods.put(sql.attribute("method").getValue(), sql.getText());
                    }
                    resourcesMap.put(clasz.attributeValue("name"), methods);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

License:Apache License

/**
 * ???/*from  w w w.  j  a 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.jga.view.seguridad.RolManagedBean.java

protected List<Rol> getSecurityRoles() {

    HttpServletRequest origRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();//from   w  ww  .  j a  v  a 2  s  .c om
    ServletContext sc = origRequest.getServletContext();
    InputStream is = sc.getResourceAsStream("/WEB-INF/web.xml");

    try {
        SAXReader reader = new SAXReader();
        Document doc = reader.read(is);

        Element webApp = doc.getRootElement();

        // Type safety warning:  dom4j doesn't use generics
        List<Element> roleElements = webApp.elements("security-role");
        for (Element roleEl : roleElements) {
            roles.add(new Rol(roleEl.element("role-name").getText()));
        }
    } catch (EJBException ex) {
        Exception ne = (Exception) ex.getCause();
        Logger.getLogger(UsuarioManagedBean.class.getName()).log(Level.SEVERE, null, ne);
    } catch (Exception ex) {
        Logger.getLogger(UsuarioManagedBean.class.getName()).log(Level.SEVERE, null, ex);
    }

    return roles;
}

From source file:com.jonschang.ai.ga.GenericPhenotype.java

License:LGPL

public void setXml(Element xml) throws XmlException {
    if (xml.getName().compareTo("phenotype") == 0) {
        Logger.getLogger(this.getClass()).trace("populating Phenotype with xml: " + xml.asXML());
        this.setScore(Double.valueOf(xml.attributeValue("score")));
        List<Element> xmlGenes = (List<Element>) xml.elements("gene");
        if (genes == null)
            genes = new ArrayList<G>();
        else/*from  w w w.j  a va 2s.  c o m*/
            genes.clear();
        for (Element geneEle : xmlGenes) {
            try {
                G newGene = factory.newGene(geneEle.attributeValue("name"));
                newGene.setXml(geneEle);
                genes.add(newGene);
            } catch (GeneticAlgException gae) {
                throw new XmlException("Could not create a new gene " + geneEle.attributeValue("name"), gae);
            }
        }
    }
}

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 ww  w  . j a v a 2  s  .c om*/
    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.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   ww w  .  j a v a2  s. c  o  m*/
        }
        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 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()));
        }//from w w  w.j  a v  a2  s .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

private static Gradient readGradient(Element parentElement) {
    Element element = parentElement.element("gradient");
    boolean focal = false;
    if (element == null) {
        element = getElement("focalgradient", parentElement);
        focal = true;// ww w .ja v a  2s. c  o m
    }
    List recordElements = element.elements("gradrecord");
    int arrayLength = recordElements.size();
    GradRecord[] records = new GradRecord[arrayLength];
    for (int i = 0; i < arrayLength; i++) {
        Element recordElement = (Element) recordElements.get(i);
        records[i] = new GradRecord(getShortAttribute("ratio", recordElement),
                readColor(getElement("color", recordElement)));
    }
    Gradient gradient;
    if (focal) {
        gradient = new FocalGradient(records, getDoubleAttribute("focalpointratio", element));
    } else {
        gradient = new Gradient(records);
    }
    gradient.setInterpolationMethod(readInterpolationMethod(element));
    gradient.setSpreadMethod(readSpreadMethod(element));
    return gradient;
}