Example usage for org.dom4j Element elementText

List of usage examples for org.dom4j Element elementText

Introduction

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

Prototype

String elementText(QName qname);

Source Link

Usage

From source file:org.panopticode.supplement.javancss.JavaNCSSSupplement.java

License:Open Source License

void loadClassData(PanopticodeProject project, Document document) {
    for (PanopticodeClass panopticodeClass : project.getClasses()) {
        if (panopticodeClass.isInnerClass()) {
            int ncss = 0;
            for (PanopticodeMethod panopticodeMethod : panopticodeClass.getMethods()) {
                IntegerMetric integerMetric = ((IntegerMetric) panopticodeMethod.getMetricByName("NCSS"));
                if (integerMetric != null) {
                    ncss += integerMetric.getValue();
                }/* w  w  w  .  ja v  a 2s.com*/
            }
            panopticodeClass.addMetric(ncssDeclaration.createMetric(ncss));
        } else {
            Element objectElement = getElementByClass(document, panopticodeClass);

            if (objectElement != null) {
                int ncss = Integer.parseInt(objectElement.elementText("ncss"));

                panopticodeClass.addMetric(ncssDeclaration.createMetric(ncss));
            } else {
                declaration.addError("ERROR - JavaNCSSSupplement - Could not find match for class '"
                        + formatClassName(panopticodeClass) + "'");
            }
        }
    }
}

From source file:org.panopticode.supplement.javancss.JavaNCSSSupplement.java

License:Open Source License

void loadMethodData(PanopticodeProject project, Document document) {
    for (PanopticodeMethod panopticodeMethod : project.getMethods()) {
        if (!isSyntheticEnumMethod(panopticodeMethod)) {
            Element functionElement = getElementByMethod(document, panopticodeMethod);

            if (functionElement != null) {
                int ncss = Integer.parseInt(functionElement.elementText("ncss"));
                int ccn = Integer.parseInt(functionElement.elementText("ccn"));

                panopticodeMethod.addMetric(ncssDeclaration.createMetric(ncss));
                panopticodeMethod.addMetric(ccnDeclaration.createMetric(ccn));
            } else {
                declaration.addError("WARNING - JavaNCSSSupplement - Could not find match for method '"
                        + formatMethodName(panopticodeMethod) + "'");
            }//  w w w.  j  a  va2  s .co m
        }
    }
}

From source file:org.panopticode.supplement.javancss.JavaNCSSSupplement.java

License:Open Source License

Element getElementByClass(Document doc, PanopticodeClass panopticodeClass) {
    String className;/*ww  w. j  a v a 2 s  . c  o m*/

    className = formatClassName(panopticodeClass);

    for (Object objObjectElement : doc.getRootElement().element("objects").elements("object")) {
        Element objectElement;
        String javaNCSSObjectName;

        objectElement = (Element) objObjectElement;
        javaNCSSObjectName = objectElement.elementText("name");

        if (className.equals(javaNCSSObjectName)) {
            return objectElement;
        }
    }

    return null;
}

From source file:org.panopticode.supplement.javancss.JavaNCSSSupplement.java

License:Open Source License

Element getElementByMethod(Document doc, PanopticodeMethod panopticodeMethod) {
    String methodName;/*from w  ww.ja va  2s  . c  o m*/

    methodName = formatMethodName(panopticodeMethod);

    for (Object objFunctiontElement : doc.getRootElement().element("functions").elements("function")) {
        Element functionElement;
        String javaNCSSFunctionName;

        functionElement = (Element) objFunctiontElement;
        javaNCSSFunctionName = functionElement.elementText("name");

        if (methodName.equals(javaNCSSFunctionName)) {
            return functionElement;
        }
    }

    return null;
}

From source file:org.richie.codeGen.database.pdm.PdmParser.java

License:Apache License

/**
 * @param doc//from w w w  . j  a v  a2 s  .  co  m
 * @param tableMap
 * @param columnMap
 */
@SuppressWarnings("unchecked")
private static List<Table> parseTables(Document doc, Map<String, Table> tableMap,
        Map<String, Column> columnMap) {
    List<Table> tables = new ArrayList<Table>();
    String dataBaseCode = null;
    String dataBaseName = null;
    String dataBaseType = null;
    List<Element> headerList = doc.selectNodes("//?PowerDesigner");
    if (headerList != null) {
        Element rootElement = doc.getRootElement();
        dataBaseType = rootElement.attributeValue("Target");
    }
    List<Element> dList = doc.selectNodes("//o:Model");
    if (dList != null && dList.size() > 0) {
        Element element = dList.get(0);
        dataBaseName = element.elementText("Name");
        dataBaseCode = element.elementText("Code");
    }
    List<Element> tList = doc.selectNodes("//c:Tables//o:Table");
    for (Element tableElement : tList) {
        List<Column> list = new ArrayList<Column>();
        Table table = parseTableElement(tableElement);
        table.setDataBaseCode(dataBaseCode);
        table.setDataBaseName(dataBaseName);
        table.setDataBaseType(getDataBaseByPdmFile(dataBaseType));
        tableMap.put(table.getId(), table);
        String primaryKeyId = getPrimaryKeyId(tableElement);
        if (tableElement.element("Columns") == null)
            continue;
        List<Element> colList = tableElement.element("Columns").elements("Column");
        for (Element colElement : colList) {
            Column column = parseColumn(primaryKeyId, colElement);
            columnMap.put(column.getId(), column);
            list.add(column);
        }
        table.setFields(list);
        tables.add(table);
    }
    return tables;
}

From source file:org.seamless_ip.services.transferobjects.seamproj.VisualisationTO.java

License:Open Source License

@SuppressWarnings("unchecked")
public void fromXML(Element element) {
    setTitle(element.elementText("title"));
    setDescription(element.elementText("description"));
    setAuthor(element.elementText("author"));

    indicatorIds.clear();//from   ww  w .ja v a 2  s .co  m
    Iterator<Element> indiIter = element.element("selectedIndicators").elementIterator("indicator");
    while (indiIter.hasNext())
        indicatorIds.add(indiIter.next().attributeValue("id"));

    experimentIds.clear();
    Iterator<Element> exprIter = element.element("selectedExperiments").elementIterator("experiment");
    while (exprIter.hasNext())
        experimentIds.add(exprIter.next().attributeValue("id"));

    setBaselineExperimentId(element.elementText("baselineExperimentId"));
    setBaselineExperimentTitle(element.elementText("baselineExperimentTitle"));

    // retrieve additional properties and store in dictionary
    properties = new Hashtable<String, Object>();
    if (element.element("properties") != null) {
        Iterator<Element> propIter = element.element("properties").elementIterator("property");
        while (propIter.hasNext()) {
            Element prop = propIter.next();
            String key = prop.attributeValue("key");
            String value = prop.attributeValue("value");
            if ((key != null) && (value != null)) {
                properties.put(key, value);
            }
        }
    }
}

From source file:org.snipsnap.net.admin.ThemeHelper.java

License:Open Source License

public static Map getThemeDocuments(Configuration config, int valueType) {
    // find theme files in filesystem
    File themeDir = new File(config.getWebInfDir(), "themes");
    File[] files = themeDir.listFiles(new FilenameFilter() {
        public boolean accept(File file, String s) {
            return s.endsWith(".snip");
        }/* w w w  . ja v  a  2  s .  c om*/
    });

    Map themeDocs = new HashMap();
    SAXReader saxReader = new SAXReader();
    for (int f = 0; f < files.length; f++) {
        try {
            Document themeDoc = saxReader.read(new FileReader(files[f]));
            Iterator it = themeDoc.getRootElement().elementIterator("snip");
            while (it.hasNext()) {
                Element snipEl = (Element) it.next();
                String tagName = snipEl.element("name").getText();
                if (tagName.startsWith(THEME_PREFIX) && tagName.indexOf('/', THEME_PREFIX.length()) == -1) {
                    String themeName = tagName.substring(tagName.lastIndexOf('/') + 1);
                    switch (valueType) {
                    case FILES:
                        themeDocs.put(themeName, files[f]);
                        break;
                    case DOCUMENTS:
                        themeDocs.put(themeName, themeDoc);
                        break;
                    case CONTENT:
                        themeDocs.put(themeName, snipEl.elementText("content"));
                        break;
                    }
                }
            }
        } catch (Exception e) {
            Logger.warn("Error reading potential theme file", e);
        }
    }
    return themeDocs;
}

From source file:org.snipsnap.net.admin.ThemeImageServlet.java

License:Open Source License

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String name = request.getParameter("name");

    Configuration config = Application.get().getConfiguration();
    Map installedThemes = ThemeHelper.getInstalledThemes();
    AttachmentStorage storage = (AttachmentStorage) snipsnap.api.container.Components
            .getComponent(AttachmentStorage.class);
    if (installedThemes.containsKey(name)) {
        Snip themeSnip = (snipsnap.api.snip.Snip) installedThemes.get(name);
        Attachment att = themeSnip.getAttachments().getAttachment("screenshot.png");
        if (att != null) {
            sendImage(response, storage.getInputStream(att), (int) att.getSize(), att.getContentType());
            return;
        }/*ww  w.  ja  v  a2s .c o  m*/
    } else {
        Map themeDocs = ThemeHelper.getThemeDocuments(config, ThemeHelper.DOCUMENTS);
        Document themeDoc = (Document) themeDocs.get(name);
        if (null != themeDoc) {
            Element attEl = getThemeElement(themeDoc, name);
            if (attEl.element("data") != null) {
                try {
                    sendImage(response, getImageStream(attEl.elementText("data")),
                            Integer.parseInt(attEl.elementText("size")), attEl.elementText("contentType"));
                    return;
                } catch (Exception e) {
                    Logger.warn("unable to read image stream", e);
                }
            }
        }
    }
    response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

From source file:org.snipsnap.net.admin.ThemeImageServlet.java

License:Open Source License

private Element getThemeElement(Document doc, String name) {
    Iterator it = doc.getRootElement().elementIterator("snip");
    while (it.hasNext()) {
        Element element = (Element) it.next();
        String snipName = element.elementText("name");
        if (null != snipName && snipName.endsWith(name)) {
            Iterator attIt = element.element("attachments").elementIterator("attachment");
            while (attIt.hasNext()) {
                Element attEl = (Element) attIt.next();
                if (attEl.elementText("name").equals("screenshot.png")) {
                    return attEl;
                }/*from  ww  w .  j  a v a 2s. co  m*/
            }
        }
    }
    return null;
}

From source file:org.snipsnap.snip.XMLSnipExport.java

License:Open Source License

private static void storeAttachments(Element snipEl, File attRoot) {
    Element attachmentsEl = snipEl.element("attachments");
    Iterator attIt = attachmentsEl.elements("attachment").iterator();
    while (attIt.hasNext()) {
        Element att = (Element) attIt.next();
        try {//from w w w . j av a  2s  .c  om
            addAttachmentFile(att, new File(attRoot, att.elementText("location")));
        } catch (Exception e) {
            Logger.fatal("unable to export attachment: " + e);
            e.printStackTrace();
        }
    }
}