Example usage for org.dom4j.io SAXReader SAXReader

List of usage examples for org.dom4j.io SAXReader SAXReader

Introduction

In this page you can find the example usage for org.dom4j.io SAXReader SAXReader.

Prototype

public SAXReader() 

Source Link

Usage

From source file:com.ah.be.parameter.BeParaModuleDefImpl.java

public void insertDefaultCustomReportField() {
    try {/* w  ww  . j  a va2  s. c om*/
        long rowCount = QueryUtil.findRowCount(AhCustomReportField.class, null);

        if (rowCount > 0) {
            return;
        }

        List<AhCustomReportField> reportFields = new ArrayList<>();

        SAXReader reader = new SAXReader();
        String docName = AhDirTools.getHmRoot() + "resources" + File.separator + "customReport" + File.separator
                + "custom_report_table.xml";
        Document doc = reader.read(new File(docName));
        Element root = doc.getRootElement();
        List<?> rootLst = root.elements();

        for (Object obj : rootLst) {
            List<?> rowlst = ((Element) obj).elements();
            AhCustomReportField reportField = new AhCustomReportField();
            for (int j = 0; j < rowlst.size(); j++) {
                Element elm = (Element) rowlst.get(j);
                //               String name = elm.attributeValue("name");
                String value = elm.attributeValue("value");
                if (j == 0) {
                    reportField.setId(Long.parseLong(value));
                } else if (j == 1) {
                    reportField.setType(Integer.parseInt(value));
                } else if (j == 2) {
                    reportField.setDetailType(Integer.parseInt(value));
                } else if (j == 3) {
                    reportField.setTableName(value);
                } else if (j == 4) {
                    reportField.setTableField(value);
                } else if (j == 5) {
                    reportField.setFieldString(value);
                } else if (j == 6) {
                    reportField.setStrUnit(value);
                } else if (j == 7) {
                    reportField.setDescription(value);
                }
            }
            reportFields.add(reportField);
        }

        root.clearContent();
        doc.clearContent();

        QueryUtil.bulkCreateBos(reportFields);
    } catch (Exception e) {
        setDebugMessage("insert default custom report field: ", e);
    }
}

From source file:com.ah.be.performance.db.TablePartitionProcessor.java

private void init() {
    try {/*from w w w .j a  v  a 2s.co  m*/
        File f = new File(TABLE_PARTITION_CONF_FILE);
        SAXReader reader = new SAXReader();
        Document doc = reader.read(f);
        Element root = doc.getRootElement();
        Element cata = null;

        int catalog = 1;
        for (Iterator<?> i = root.elementIterator(); i.hasNext();) {
            //for catalog
            cata = (Element) i.next();
            String enable = cata.elementText("enable");
            if (enable != null && enable.equalsIgnoreCase("false"))
                continue;
            int default_maxtime = Integer.parseInt(cata.elementTextTrim("default_maxtime"));
            int default_interval = Integer.parseInt(cata.elementTextTrim("default_interval"));
            int table_partition_number = Integer.parseInt(cata.elementTextTrim("table_partition_number"));
            int default_max_record = Integer.parseInt(cata.elementTextTrim("default_max_record"));
            int default_max_record_per_partition = Integer
                    .parseInt(cata.elementTextTrim("default_max_record_per_partition"));
            int maxtime_policy = Integer.parseInt(cata.elementTextTrim("maxtime_policy"));
            int interval_policy = Integer.parseInt(cata.elementTextTrim("interval_policy"));
            int max_record_policy = Integer.parseInt(cata.elementTextTrim("max_record_policy"));

            addTableCatalogInfo(catalog, default_maxtime, default_interval, table_partition_number,
                    default_max_record, default_max_record_per_partition, maxtime_policy, interval_policy,
                    max_record_policy);

            List<?> tableElements = cata.elements("table");
            //for table in catalog
            for (int j = 0; j < tableElements.size(); j++) {
                Element table = (Element) tableElements.get(j);
                String tableName = table.attributeValue("name");
                String schemaName = table.elementTextTrim("schemaname");
                String timeField = table.elementTextTrim("timefield");
                addTableInfo(schemaName, tableName, timeField, catalog);
            }

            catalog++;
        }
    } catch (Exception e) {
        BeLogTools.error(HmLogConst.M_PERFORMANCE_TABLEPARTITION, "Fail to init table partition configure file",
                e);
    }
}

From source file:com.ah.ui.actions.hiveap.HiveApFileAction.java

/**
 * Get the image product name and version from the header xml string
 *
 *@param lineStr -//from  ww w . j a v  a  2s.c  om
 *@return HiveApImageInfo
 */
private HiveApImageInfo getImageInfoHead(String lineStr) {
    try {
        if (!lineStr.startsWith("#!/bin/bash") || !lineStr.contains("<Image-Header")
                || !lineStr.contains("</Image-Header>") || !lineStr.contains("<Firmware>")
                || !lineStr.contains("</Firmware>")) {
            return null;
        }
        HiveApImageInfo info = new HiveApImageInfo();
        SAXReader reader = new SAXReader();
        String docName = lineStr.substring(lineStr.indexOf("<Firmware>"),
                lineStr.indexOf("</Firmware>") + "</Firmware>".length());
        Document doc = reader.read(new StringReader(docName));
        Element roota = doc.getRootElement();
        Iterator<?> iter = roota.elementIterator();
        Element foo;
        while (iter.hasNext()) {
            foo = (Element) iter.next();
            // get product name
            if (foo.getName().equalsIgnoreCase("Product")) {
                info.setProductName(foo.getStringValue());
                // get image version
            } else if (foo.getName().equalsIgnoreCase("Version")) {
                iter = foo.elementIterator();
                while (iter.hasNext()) {
                    foo = (Element) iter.next();
                    if (foo.getName().equalsIgnoreCase("External")) {
                        iter = foo.elementIterator();
                        while (iter.hasNext()) {
                            foo = (Element) iter.next();
                            // get major version
                            if (foo.getName().equalsIgnoreCase("Major")) {
                                info.setMajorVersion(foo.getStringValue());

                                // get minor version
                            } else if (foo.getName().equalsIgnoreCase("Minor")) {
                                info.setMinorVersion(foo.getStringValue());

                                // get release version
                            } else if (foo.getName().equalsIgnoreCase("Release")) {
                                info.setRelVersion(foo.getStringValue());

                                // get patch string
                            } else if (foo.getName().equalsIgnoreCase("Patch")) {
                                try {
                                    info.setImageUid(Integer.parseInt(foo.getStringValue()));
                                } catch (NumberFormatException nfe) {
                                    info.setImageUid(0);
                                }
                            }
                        }
                    }
                }
            }
        }
        String regex = "^\\d+\\.+\\d+r\\d+\\w*$";
        // check the product name and version format
        if ("".equals(info.getProductName()) || !Pattern.matches(regex, info.getImageVersion().trim())) {
            return null;
        }
        com.ah.be.config.image.ImageManager.updateHiveApImageInfo(info);
        return info;
    } catch (Exception ex) {
        log.error("checkImageInfo : ", ex.getMessage());
        return null;
    }
}

From source file:com.ai.tools.generator.util.XMLFormatter.java

License:Open Source License

public static String toString(String xml, String indent) throws DocumentException, IOException {
    SAXReader reader = new SAXReader();
    Document doc = DocumentHelper.parseText(xml);
    // Document  doc = reader.read(new StringReader(xml));

    return toString(doc, indent);
}

From source file:com.alefissak.parsers.PlanningFromFileParser.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  w w  .ja  v  a 2s.c  om*/
 * 
 * @return the document object
 * @throws AlefissakFileNotFoundException
 * @throws AlefissakParsingException
 */
@Override
public Document getDocument() throws AlefissakFileNotFoundException, AlefissakParsingException {

    if (planningFile == null) {

        throw new IllegalArgumentException("The configuration file must be specified !");
    }

    Document document = null;

    try {

        document = new SAXReader().read(planningFile);

    } catch (Exception ex) {

        throw new AlefissakParsingException(ex);
    }

    return document;
}

From source file:com.alefissak.parsers.PlanningFromFilePathParser.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w w.jav a  2 s  .co m*/
 * 
 * @return the document object
 * @throws AlefissakFileNotFoundException
 * @throws AlefissakParsingException
 */
public Document getDocument() throws AlefissakFileNotFoundException, AlefissakParsingException {

    if (StringUtil.isEmpty(planningFilePath)) {

        throw new IllegalArgumentException("The configuration file name must be specified !");
    }

    if (!new java.io.File(planningFilePath).exists()) {

        throw new AlefissakFileNotFoundException();
    }

    Document document = null;

    try {

        document = new SAXReader().read(planningFilePath);

    } catch (Exception ex) {

        throw new AlefissakParsingException(ex);
    }

    return document;
}

From source file:com.alefissak.parsers.PlanningFromURLParser.java

License:Apache License

/**
 * {@inheritDoc}//w  ww. j a v a  2  s.c  om
 * 
 * @return the document object
 * @throws AlefissakFileNotFoundException
 * @throws AlefissakParsingException
 */
@Override
public Document getDocument() throws AlefissakFileNotFoundException, AlefissakParsingException {

    if (url == null) {

        throw new IllegalArgumentException("URL must be specified for the configuration!");
    }

    Document document = null;

    try {

        document = new SAXReader().read(url);

    } catch (Exception ex) {

        throw new AlefissakParsingException(ex);
    }

    return document;
}

From source file:com.alibaba.antx.config.resource.util.TextBasedPageParser.java

License:Open Source License

/** ?xml */
protected Document getXmlDocument(Resource resource) {
    String contentType = resource.getContentType();

    if (contentType != null && contentType.startsWith("text/xml")) {
        try {//  w w w. j  a v a2 s . c o  m
            return new SAXReader().read(resource.getInputStream());
        } catch (Exception e) {
        }
    }

    return null;
}

From source file:com.alibaba.stonelab.toolkit.autoconf.Autoconf.java

License:Open Source License

@SuppressWarnings("unchecked")
private void parser(String base, String file) throws Exception {
    SAXReader reader = new SAXReader();
    Document doc = reader.read(new File(file));
    List<DefaultElement> pnodes = doc.selectNodes("config/group/property");

    StringBuilder defaults = new StringBuilder();
    for (DefaultElement node : pnodes) {
        String prop = node.attributeValue("name");
        props.add(new Propinfo(StringUtils.replace(prop, ".", "_"), file));
        // default valus
        defaults.append(node.attributeValue("defaultValue"));
    }// ww w . j  a  v a2s  .  c  o m

    List<DefaultElement> tnodes = doc.selectNodes("config/script/generate");
    for (DefaultElement node : tnodes) {
        templates.add(new AutoconfTemplate(base + "/" + node.attribute("template").getText()));
    }

    Set<String> tmp = AutoconfUtil.parsePlaceholder(defaults.toString());
    for (String str : tmp) {
        usedProps.add(StringUtils.replace(str, ".", "_"));
    }
}

From source file:com.alibaba.toolkit.util.resourcebundle.xml.XMLResourceBundleFactory.java

License:Open Source License

/**
 * XML???, <code>ResourceBundle</code>.
 *
 * @param stream   ?/*w  w  w.jav  a  2 s.  co  m*/
 * @param systemId ?
 * @return resource bundle
 * @throws ResourceBundleCreateException ?
 */
@Override
protected ResourceBundle parse(InputStream stream, String systemId) throws ResourceBundleCreateException {
    try {
        SAXReader reader = new SAXReader();
        Document doc = reader.read(stream, systemId);

        return new XMLResourceBundle(doc);
    } catch (DocumentException e) {
        throw new ResourceBundleCreateException(ResourceBundleConstant.RB_FAILED_READING_XML_DOCUMENT,
                new Object[] { systemId }, e);
    }
}