Java 类org.jdom2.input.sax.XMLReaderJDOMFactory 实例源码

项目:Equella    文件:RssPortletRenderer.java   
private SAXBuilder createBuilder()
{
    return new SAXBuilder(new XMLReaderJDOMFactory()
    {
        @Override
        public XMLReader createXMLReader() throws JDOMException
        {
            SAXParserFactory fac = SAXParserFactory.newInstance();
            // All JDOM parsers are namespace aware.
            fac.setNamespaceAware(true);
            fac.setValidating(false);
            try
            {
                fac.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
                return fac.newSAXParser().getXMLReader();
            }
            catch (ParserConfigurationException | SAXException e)
            {
                throw new RuntimeException(e);
            }
        }

        @Override
        public boolean isValidating()
        {
            return false;
        }
    }, null, null);
}
项目:mycore    文件:MCRXMLParserImpl.java   
public MCRXMLParserImpl(XMLReaderJDOMFactory factory, boolean silent) {
    this.validate = factory.isValidating();
    builder = new SAXBuilder(factory);
    builder.setFeature(FEATURE_NAMESPACES, true);
    builder.setFeature(FEATURE_SCHEMA_SUPPORT, validate);
    builder.setFeature(FEATURE_FULL_SCHEMA_SUPPORT, false);
    builder.setErrorHandler(new MCRXMLParserErrorHandler(silent));
    builder.setEntityResolver(new XercesBugFixResolver(MCREntityResolver.instance()));
}
项目:ANNeML-Lab    文件:AL_gui.java   
public void loadFile(String pathname, String filename) {

        try {
            // Build & creat the document with SAX, use XML schema validation
            URL path = ClassLoader.getSystemResource("ANNeML.xsd");
            if(path.getFile()==null) {
                jLabel2.setForeground(Color.RED);
                jLabel2.setText("error loading XML schema");  
            }
            else{
                //File argylexsd = new File(path.toURI());
                //XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(argylexsd);
                XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory("ANNeML.xsd"); //***for .jar deployment
                SAXBuilder builder = new SAXBuilder(schemafac);
                AL_gui.NNetMap = builder.build(pathname);
                java.util.List subnets = XPath.newInstance("//SUBNET").selectNodes(AL_gui.NNetMap);
                java.util.List layers = XPath.newInstance("//LAYER").selectNodes(AL_gui.NNetMap);
                java.util.List inputNeurodes = XPath.newInstance("//NEURODE[SYNAPSE/@ORG_NEURODE='INPUT']").selectNodes(AL_gui.NNetMap);
                java.util.List hiddenNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='HIDDEN']/NEURODE").selectNodes(AL_gui.NNetMap);
                java.util.List outputNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='OUTPUT']/NEURODE").selectNodes(AL_gui.NNetMap);                
                jLabel2.setForeground(Color.GREEN);
                jLabel2.setText("Valid ANNeML file.");
            } 
            } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(AL_gui.this, "There was an error parsing the file.\n" + e.toString(), "Warning", JOptionPane.WARNING_MESSAGE);
        }


    }
项目:mycore    文件:MCRXMLParserImpl.java   
public MCRXMLParserImpl(XMLReaderJDOMFactory factory) {
    this(factory, false);
}
项目:vizardous    文件:Forest.java   
/**
  * Parses the PhyloXML file and fill the structure of MetaML.
  * 
  * @param f PhyloXML file.
  * @return Returns an PhyloXML object.
  */
 private PhyloXML readPhyloXML(File f) throws JDOMException {
    try {
         // TODO A round of non-validating parsing to get the file name of the referenced XSD

         // Set the implementation of SAXParserFactory to the one bundled wit the JRE
         System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");

         // Read bundled XML schema             
        URL xsdUrl = getClass().getResource("/schemas/phyloxml-1.10.xsd");
        XMLReaderJDOMFactory factory = new XMLReaderXSDFactory(xsdUrl);

         // This builder validates against the provided XSD
         SAXBuilder sb = new SAXBuilder(factory);
         Document doc = sb.build(f);

Element rootElement = doc.getRootElement();
Namespace phyloXMLNamespace = rootElement.getNamespace();

/*
          * Parse <phyloxml>
          */
Namespace defaultNamespace = Namespace.getNamespace("phyloxml", phyloXMLNamespace.getURI());
XPathExpression<Element> phylogenyExpression = xpfac.compile("phyloxml:"+Constants.PHYLOXML_PHYLOGENY, Filters.element(), null, defaultNamespace);

for (Element phylogenyElement : phylogenyExpression.evaluate(rootElement)) {                                    
             Phylogeny phylogeny = new Phylogeny(this);

             readSubClades(defaultNamespace, phylogeny, phylogenyElement, null);

    /*
     * This is a pretty dirty hack. We just hijack the
     * phylogenyObject2 field, knowing that readSubClades will
     * add the Clades to this Phylogeny. After one phylogeny has
     * been processed we add phylogenyObject2 to the list of
     * phylogenies and start over again.
     * 
     * THIS HACK WILL NOT BE THREADSAFE!!
     */
    phylogenies.add(phylogeny);
}

/*
 * Parse project name
 */
Namespace metaXMLNamespace = Namespace.getNamespace("metaxml", "http://metaXML.fz-juelich.de");
XPathExpression<Element> projectNameExpression = xpfac.compile("metaxml:"+Constants.PHYLOXML_PROJECTNAME, Filters.element(), null, metaXMLNamespace);           
for (Element projectNameElement : projectNameExpression.evaluate(rootElement)) {
    this.projectName = projectNameElement.getValue();
}
     } catch (IOException ex) {
        /* TODO Handle exceptions properly */
        logger.error("Loading from file failed", ex);
     }

     return new PhyloXML(phylogenies);
 }
项目:rome    文件:SAXBuilder.java   
public SAXBuilder(final XMLReaderJDOMFactory factory) {
    super(factory);
}