⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml.java

📁 开放源代码的基于SAML的单点登录系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                SAMLConfig.instance().getBooleanProperty("org.opensaml.compatibility-mode") ? XML.SAMLP_SCHEMA_ID : XML.SAMLP11_SCHEMA_ID,                null);            registerSchema(XML.SOAP11ENV_NS, XML.SOAP11ENV_SCHEMA_ID, null);            registerSchema(XML.XMLSIG_NS, XML.XMLSIG_SCHEMA_ID, null);            registerSchema(XML.XML_NS, XML.XML_SCHEMA_ID, null);            registerSchema(XML.XPATH2_NS, XML.XPATH2_SCHEMA_ID, null);            System.setProperty("org.apache.xerces.xni.parser.Configuration", "org.apache.xerces.parsers.XMLGrammarCachingConfiguration");        }        /**         *  Get a DOM parser suitable for our task         *         * @return                    A DOM parser ready to use         * @exception  SAMLException  Raised if a system error prevents a parser         *      from being created         */        public synchronized DOMParser get()            throws SAMLException        {            try            {                DOMParser p = null;                if (pool.empty())                {                    // Build a parser to order.                    p = new DOMParser();                    p.setFeature("http://xml.org/sax/features/validation", true);                    p.setFeature("http://apache.org/xml/features/validation/schema", true);                    p.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);                    p.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);                    p.setEntityResolver(this);                    p.setErrorHandler(this);                }                else                    p = (DOMParser)pool.pop();                p.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",schemaLocations);                return p;            }            catch (org.xml.sax.SAXException e)            {                throw new SAMLException("XML.ParserPool.get() unable to configure parser properly",e);            }        }        /**         *  Parses a document using a pooled parser with the proper settings         *         * @param  in                       A stream containing the content to         *      be parsed         * @return                          The DOM document resulting from the         *      parse         * @exception  SAMLException        Raised if a parser is unavailable         * @exception  SAXException         Raised if a parsing error occurs         * @exception  java.io.IOException  Raised if an I/O error occurs         */        public Document parse(InputStream in)            throws SAMLException, SAXException, java.io.IOException        {            DOMParser p = get();            try            {                p.parse(new InputSource(in));                return p.getDocument();            }            finally            {                put(p);            }        }        /**         *  Parses a document using a pooled parser with the proper settings         *         * @param  systemId                 The URI to parse         * @return                          The DOM document resulting from the         *      parse         * @exception  SAMLException        Raised if a parser is unavailable         * @exception  SAXException         Raised if a parsing error occurs         * @exception  java.io.IOException  Raised if an I/O error occurs         */        public Document parse(String systemId)            throws SAMLException, SAXException, java.io.IOException        {            DOMParser p = get();            try            {                p.parse(new InputSource(systemId));                return p.getDocument();            }            finally            {                put(p);            }        }        /**         *  Builds a new DOM document         *         * @return    An empty DOM document          */        public Document newDocument()        {            return new DocumentImpl();        }        /**         *  Registers an extension schema and optional resolver with the parser         *  runtime         *         * @param  namespace  The extension namespace         * @param  schema     The system ID of the extension schema         * @param  resolver   An optional entity resolver that can custom         *      resolve the schema         */        public synchronized void registerSchema(String namespace, String schema, EntityResolver resolver)        {            if (namespace != null && schema != null)            {                if (schemaLocMap.containsKey(namespace))                    schemaLocMap.remove(namespace);                                schemaLocMap.put(namespace, schema);                if (resolver != null)                    resolvers.add(resolver);                schemaLocations = null;                Iterator i = schemaLocMap.entrySet().iterator();                while (i.hasNext())                {                    Map.Entry e = (Map.Entry)i.next();                    if (schemaLocations == null)                        schemaLocations = e.getKey() + " " + e.getValue();                    else                        schemaLocations += " " + e.getKey() + " " + e.getValue();                }            }        }        /**         *  Return a parser to the pool         *         * @param  p  Description of Parameter         */        public synchronized void put(DOMParser p)        {            pool.push(p);        }        /**         *  A customized entity resolver that utilizes internal machinery for         *  the SAML, SOAP, and DSig schemas and chains to externally provided         *  resolvers         *         * @param  publicId                 The public identifier of the entity         * @param  systemId                 The system identifier of the entity         * @return                          A source of bytes for the entity or         *      null         * @exception  SAXException         Raised if an XML parsing problem         *      occurs         * @exception  java.io.IOException  Raised if an I/O problem is detected         */        public InputSource resolveEntity(String publicId, String systemId)            throws SAXException, java.io.IOException        {            log.debug("ParserPool resolving entity: publicId = " + publicId + " : systemId = " + systemId);            InputSource src = null;            if (systemId.endsWith(SAML_SCHEMA_ID) && SAML_schema != null)                src = new InputSource(new ByteArrayInputStream(SAML_schema));            else if (systemId.endsWith(SAMLP_SCHEMA_ID) && SAMLP_schema != null)                src = new InputSource(new ByteArrayInputStream(SAMLP_schema));            else if (systemId.endsWith(SAML11_SCHEMA_ID) && SAML11_schema != null)                src = new InputSource(new ByteArrayInputStream(SAML11_schema));            else if (systemId.endsWith(SAMLP11_SCHEMA_ID) && SAMLP11_schema != null)                src = new InputSource(new ByteArrayInputStream(SAMLP11_schema));            else if (systemId.endsWith(XMLSIG_SCHEMA_ID) && XMLSig_schema != null)                src = new InputSource(new ByteArrayInputStream(XMLSig_schema));            else if (systemId.endsWith(SOAP11ENV_SCHEMA_ID) && SOAP11Env_schema != null)                src = new InputSource(new ByteArrayInputStream(SOAP11Env_schema));            else if (systemId.endsWith(XML_SCHEMA_ID) && XML_schema != null)                src = new InputSource(new ByteArrayInputStream(XML_schema));            else if (systemId.endsWith(XPATH2_SCHEMA_ID) && XPath2_schema != null)                src = new InputSource(new ByteArrayInputStream(XPath2_schema));            else if (resolvers != null)            {                for (Iterator i = resolvers.iterator(); src == null && i.hasNext(); )                    src = ((EntityResolver)(i.next())).resolveEntity(publicId, systemId);            }            if (src != null)            {                log.debug("entity resolved by ParserPool");            }            return src;        }        /**         *  Called by parser if a fatal error is detected, does nothing         *         * @param  exception         Describes the error         * @exception  SAXException  Can be raised to indicate an explicit error         */        public void fatalError(SAXParseException exception)            throws SAXException { }        /**         *  Called by parser if an error is detected, currently just throws e         *         * @param  e                      Description of Parameter         * @exception  SAXParseException  Can be raised to indicate an explicit         *      error         */        public void error(SAXParseException e)            throws SAXParseException        {            throw e;        }        /**         *  Called by parser if a warning is issued, currently logs the         *  condition         *         * @param  e                      Describes the warning         * @exception  SAXParseException  Can be raised to indicate an explicit         *      error         */        public void warning(SAXParseException e)            throws SAXParseException        {            log.warn("Parser warning: line = " + e.getLineNumber() + " : uri = " + e.getSystemId());            log.warn("Parser warning (root cause): " + e.getMessage());        }    }    // Static initializer block preloads schemas.    static    {        try        {            int b;            StringBuffer buf = new StringBuffer(1024);            InputStream xmlin = XML.class.getResourceAsStream("/schemas/" + SAML_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate SAML assertion schema");            else            {                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                SAML_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + SAMLP_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate SAML protocol schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                SAMLP_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + SAML11_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate SAML 1.1 assertion schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                SAML11_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + SAMLP11_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate SAML 1.1 protocol schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                SAMLP11_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + XMLSIG_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate XML Signature schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                XMLSig_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + XPATH2_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate XPath Filter2 schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                XPath2_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + SOAP11ENV_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XML static initializer unable to locate SOAP 1.1 Envelope schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                SOAP11Env_schema = buf.toString().getBytes();                xmlin.close();            }            xmlin = XML.class.getResourceAsStream("/schemas/" + XML_SCHEMA_ID);            if (xmlin == null)                throw new RuntimeException("XM static initializer unable to locate XML core schema");            else            {                buf.setLength(0);                while ((b = xmlin.read()) != -1)                    buf.append((char)b);                XML_schema = buf.toString().getBytes();                xmlin.close();            }        }        catch (java.io.IOException e)        {            throw new RuntimeException("XML static initializer caught an I/O error");        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -