Java 类org.dom4j.io.DOMReader 实例源码

项目:GKHMC    文件:CorpusHandler.java   
public static void readXML2OutFile(String xmlName, String outFileName)
        throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = documentBuilderFactory.newDocumentBuilder();

    org.w3c.dom.Document doc = null;
    doc = db.parse(new File(xmlName));

    DOMReader domReader = new DOMReader();
    Document document = domReader.read(doc);

    Element rootElement = document.getRootElement();
    File outputFile = new File(outFileName);
    FileOutputStream outputStream = new FileOutputStream(outputFile);
    PrintStream printStream = new PrintStream(outputStream);
    int num = 0;

    for (Element itemIter : rootElement.elements()) {
        Element contentEle = itemIter.element("content");
        String content = contentEle.getTextTrim();
        content = content.replaceAll("\\[title.*?\\[/title\\]", "");
        for(String str : content.split("\\[/p\\] .+? \\[p\\]")) {
            printStream.println(str);
        }
    }
}
项目:gluu    文件:LogFileSizeChecker.java   
private List<LogDir> readConfig(String source) {
    List<LogDir> logDirs = new ArrayList<LogDir>();
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        org.w3c.dom.Document document = builder.parse(new InputSource(new FileInputStream(new File(source))));
        DOMReader reader = new DOMReader();
        Document doc = reader.read(document);
        Element element = doc.getRootElement();
        Iterator itr = element.elementIterator();
        while (itr.hasNext()) {
            element = (Element) itr.next();
            String prefix = element.element("prefix").getText();
            String location = element.element("location").getText();

            String extension = "";
            if (element.element("extension") != null) {
                extension = element.element("extension").getText();
            }
            if (extension == null || extension.trim().equals("")) {
                extension = "log";
            }

            LogDir logDir = new LogDir(prefix, location, extension);
            logDirs.add(logDir);
            log.debug("Prefix: " + prefix + " Location: " + location);
        }
        log.info("OutXML: " + doc.asXML());
    } catch (Exception ex) {
        log.debug("Exception while reading configuration file: " + ex);
    }
    return logDirs;
}
项目:jnrpe    文件:PluginRepositoryUtil.java   
/**
 * Loads the plugins definitions from the jnrpe_plugins.xml file.
 * 
 * @param cl Classloader to be used to load classes
 * @param in InputStream to the jnrpe_plugins.xml file
 * @return a collection of all the declared plugins
 * @throws PluginConfigurationException on any error reading the plugin configuration
 */
@SuppressWarnings("unchecked")
public static Collection<PluginDefinition> loadFromXmlPluginPackageDefinitions(final ClassLoader cl, final InputStream in)
        throws PluginConfigurationException {

    List<PluginDefinition> res = new ArrayList<PluginDefinition>();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    Document document;

    try {
        DocumentBuilder loader = factory.newDocumentBuilder();
        DOMReader reader = new DOMReader();

        document = reader.read(loader.parse(in));
    } catch (Exception e) {
        throw new PluginConfigurationException(e.getMessage(), e);
    }

    Element plugins = document.getRootElement();

    // TODO : validate against schema

    // iterate through child elements of root
    for (Iterator<Element> i = plugins.elementIterator(); i.hasNext();) {
        res.add(parsePluginDefinition(cl, i.next()));
    }

    return res;
}
项目:Openfire    文件:Xep227Exporter.java   
@Override
public List<String> importUsers(InputStream inputStream, String previousDomain, boolean isUserProviderReadOnly) {
  Log.debug("importUsers");

  DOMReader xmlReader = new DOMReader();            
  Document doc = xmlReader.read(new UserSchemaValidator(inputStream).validateAndParse());

  return importUsers(doc, previousDomain, isUserProviderReadOnly);
}
项目:Openfire    文件:OpenfireExporter.java   
@Override
public List<String> importUsers(InputStream inputStream, String previousDomain, boolean isUserProviderReadOnly) {
  Log.debug("importUsers");

  DOMReader xmlReader = new DOMReader();            
  Document doc = xmlReader.read(new UserSchemaValidator(inputStream).validateAndParse());

  return importUsers(doc, previousDomain, isUserProviderReadOnly);
}
项目:jnrpe    文件:PluginRepositoryUtil.java   
/**
 * Loads the definition of a single plugin from an XML file.
 * 
 * @param cl
 *            The classloader to be used to instantiate the plugin class
 * @param in
 *            The stream to the XML file
 * @return The plugin definition
 * @throws PluginConfigurationException if an error occurs parsing the plugin definition
 */
public static PluginDefinition parseXmlPluginDefinition(final ClassLoader cl, final InputStream in) throws PluginConfigurationException {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    Document document;

    try {
        DocumentBuilder loader = factory.newDocumentBuilder();
        DOMReader reader = new DOMReader();

        document = reader.read(loader.parse(in));
    } catch (Exception e) {
        throw new PluginConfigurationException(e.getMessage(), e);
    }

    Element plugin = document.getRootElement();

    // TODO : validate against schema

    return parsePluginDefinition(cl, plugin);
}
项目:cernunnos    文件:NekoHtmlPhrase.java   
public Object evaluate(TaskRequest req, TaskResponse res) {


        Node rslt = null;

        String ctx_str = (String) context.evaluate(req, res);
        String loc_str = (String) location.evaluate(req, res);
        try {

            URL ctx = new URL(ctx_str);
            URL src = new URL(ctx, loc_str);

            DOMParser parser = new DOMParser();
            parser.parse(src.toString());

            Document doc = new DOMReader().read(parser.getDocument());
            rslt = doc.getRootElement();


        } catch (Throwable t) {
            String msg = "Unable to read the specified document:"
                        + "\n\tCONTEXT=" + ctx_str
                        + "\n\tLOCATION=" + loc_str;
            throw new RuntimeException(msg, t);
        }

        return rslt;

    }