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

📄 loaderimpl.java

📁 xbrlapi的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            throw new XBRLException(                    "The standard roles URL could not be formed for discovery.",                    e);        }                discover(url);    }    /**     * Perform a discovery starting with an XML document that is represented as     * an input source.     *      * @param url     *            The URL to be used for the document that is supplied as a     *            string.     * @param inputSource     *            The InputSource representation of the XML document to be     *            parsed.     * @throws XBRLException     *             if the discovery process fails.     */    /*     * public void discover(URL url, InputSource inputSource) throws     * XBRLException {     *      * this.setNextFragmentId(getStore().getNextFragmentId());     *      * while (url != null) { if (! getStore().hasDocument(url.toString())) {     * setDocumentURL(url.toString()); parse(url, inputSource); } url =     * getNextDocumentToExplore(); }     *      * getStore().storeLoaderState(this.getCurrentFragmentId(),this.getDocumentsStillToAnalyse());     *  }     */    /**     * Retrieve URI of the next document to parse from the list of starting     * point URLs provided or URLs found during the discovery process.     *      * @throws XBRLException     * @return the URI of the next document to explore or null if there are     *         none.     */    private URL getNextDocumentToExplore() throws XBRLException {        try {            for (String key : documentQueue.keySet()) {                if ((documentQueue.get(key)).equals(new Integer(0))) {                    documentQueue.put(key, new Integer(1));                    URL url = new URL(key);                    return url;                }            }            return null;        } catch (MalformedURLException e) {            throw new XBRLException(                    "The URL syntax for the next DTS document is malformed.", e);        }    }    /**     * Parse an XML Document supplied as a URL the next part of the DTS.     *      * @param url     *            The URL of the document to parse.     * @throws XBRLException     */    private void parse(URL url) throws XBRLException {        try {            InputSource inputSource = this.entityResolver.resolveEntity("", url.toString());            ContentHandler contentHandler = new ContentHandlerImpl(this, url);            parse(url, inputSource, contentHandler);        } catch (SAXException e) {            throw new XBRLException("SAX exception thrown when parsing " + url,e);        } catch (IOException e) {            throw new XBRLException("IO exception thrown when parsing " + url,e);        }    }    /**     * HJU Modification Property that is designed to hold a string with space     * delimited pairs of namespaces and the corresponding URLs of files to be     * loaded from a local source rather than from the original URL. This mimics     * the xsi:schemaLocation attribute. This property is used to substitute a     * local URL for a DTS discovered one when stashing URLs for later     * discovery. HJU     */    // private String _namespaceLocations = null;    /**     * HJU Modification Allow the user to specify local file locations for     * schema urls. HJU     */    /*     * public void setNamespaceLocations(String namespaceLocations) {     * _namespaceLocations = namespaceLocations; }     */    /**     * Parse an XML Document supplied as a string the next part of the DTS.     *      * @param url     *            The URL to associate with the supplied XML.     * @param xml     *            The XML document as a string.     * @throws XBRLException     */    private void parse(URL url, String xml) throws XBRLException {        InputSource inputSource = new InputSource(new StringReader(xml));        ContentHandler contentHandler = new ContentHandlerImpl(this, url, xml);        parse(url, inputSource, contentHandler);    }    /**     * Parse the supplied input source.     *      * @param url     *            The URL to be associated with the supplied input source.     * @param inputSource     *            The input source to parse.     * @param contentHandler     *            The content handler to use for SAX parsing.     * @throws XBRLException     */    private void parse(URL url, InputSource inputSource,            ContentHandler contentHandler) throws XBRLException {        // Create and configure the SAX parser factory        SAXParserFactory factory = SAXParserFactory.newInstance();        factory.setValidating(false); // Standard XML validation - schema                                        // validation used instead.        factory.setNamespaceAware(true);        /*         * // Turn on XML Schema validation         * factory.setFeature("http://xml.org/sax/features/validation",true);         * factory.setFeature("http://apache.org/xml/features/validation/schema",true);         * factory.setFeature("http://apache.org/xml/features/validation/schema-full-checking",false);         */        // Create the SAX parser to use        SAXParser parser = null;        try {            parser = factory.newSAXParser();        } catch (ParserConfigurationException e) {            throw new XBRLException("SAX Parser could not be created.", e);        } catch (SAXException e) {            throw new XBRLException(                    "Exception thrown setting up the SAX Parser.", e);        }        XMLReader reader = null;        try {            reader = parser.getXMLReader();        } catch (SAXException e) {            throw new XBRLException(                    "Exception thrown setting up the SAX reader.", e);        }        reader.setEntityResolver(this.entityResolver);        reader.setContentHandler(contentHandler);        reader.setErrorHandler((ErrorHandler) contentHandler);        try {            reader.setFeature("http://xml.org/sax/features/namespace-prefixes",                    true);        } catch (SAXNotRecognizedException e) {            throw new XBRLException(                    "The sax parser does not recognise a lexical handler or a declaration handler.",                    e);        } catch (SAXNotSupportedException e) {            throw new XBRLException(                    "The sax parser does not support a lexical handler or a declaration handler.",                    e);        }        try {            reader.setProperty(Constants.JAXP_SCHEMA_LANGUAGE,                    Constants.W3C_XML_SCHEMA);        } catch (SAXNotSupportedException e) {            throw new XBRLException(                    "The SAX parser does not support XML Schema validation.", e);        } catch (SAXNotRecognizedException e) {            throw new XBRLException(                    "The SAX parser does not recognise the XML Schema validation property.",                    e);        }        try {            reader.parse(inputSource);        } catch (SAXException e) {            throw new XBRLException("SAX exception thrown when parsing " + url,                    e);        } catch (IOException e) {            throw new XBRLException("IO exception thrown when parsing " + url,                    e);        }        // Remove any document stub from the data store once parsing is complete.        getStore().removeStub(documentId);            }    /**     * Load a serialised data store. TODO implement loading of a serialised data     * store using a different class to the loader.     */    public void load(File file) throws XBRLException {        throw new XBRLException(                "Loading from a serialised store is not yet implemented.");    }    /**     * Load a serialised DTS TODO Implement the load URL method for a DTS using     * a different class to the loader.     */    public void load(URL url) throws XBRLException {        throw new XBRLException("The load method is not yet implemented.");    }    /**     * Set the starting points for DTSImpl discovery using a linked list     *      * @param urls     *            A list of starting point document URLs for DTSImpl discovery     * @throws XBRLException     */    protected void setStartingURLs(List<URL> urls) throws XBRLException {        if (urls == null)            throw new XBRLException("Null list of urls is not permitted.");        for (int i = 0; i < urls.size(); i++) {            stashURL(urls.get(i));        }    }    /**     * Stash a URL to await loading into DTS.     *      * @param url     *            The absolute URL to be stashed (any relative URL gets resolved     *            against the Base URL before stashing. TODO put this     *            functionality at the SAX parse call for the document. TODO     *            make sure that the fragment after the # is handled for stashed     *            URLs in the loader.     * @throws XBRLException     *             if the URL cannot be stored for later exploration or if the     *             URL is not absolute     */    public synchronized void stashURL(URL url) throws XBRLException {        // Make sure that the URL is a valid URI and is absolute        try {            if (!new URI(url.toString()).isAbsolute()) {                logger.warn("Failed to stash " + url);                throw new XBRLException("The URL: " + url + " needs to be resolved against a base URL prior to stashing.");                            }                        } catch (URISyntaxException e) {            throw new XBRLException("The URL: " + url + " is not a valid URI.",e);        }        URL dereferencedURL = null;        try {            dereferencedURL = new URL(url.getProtocol(), url.getHost(), url                    .getPort(), url.getPath());        } catch (MalformedURLException e) {            throw new XBRLException(                    "Malformed URL found in DTS discovery process: " + url, e);        }        // Stash the URL if it has not already been stashed        if (!documentQueue.containsKey(dereferencedURL.toString())) {            // Only stash if the document does not already have a match.            URL matchURL = getStore().getMatcher().getMatch(dereferencedURL);            if (matchURL.equals(dereferencedURL)) {                logger.debug(Thread.currentThread().getName() + " stashing " + url);                documentQueue.put(dereferencedURL.toString(), new Integer(0));            } else {                logger.debug("No need to stash " + dereferencedURL + " because it has match " + matchURL);            }                    }    }    /**     * Set the resolver for the resolution of entities found during the loading     * and XLink processing     *      * @param resolver     *            An entity resolver implementation     */    public void setEntityResolver(EntityResolver resolver) {        this.entityResolver = resolver;    }    public String getNextFragmentId() throws XBRLException {        String id = getCurrentFragmentId();        incrementFragmentId();        return id;    }    public String getCurrentFragmentId() {        return getDocumentId() + "_" + (new Integer(fragmentId)).toString();    }    public void incrementFragmentId() {        fragmentId = fragmentId + 1;    }    /**     * Used to set the next fragment id using the information in the data store.     * This is useful when coming back to an existing data store to add     * additional documents.     *      * @param id     * @throws XBRLException     */    private void setNextFragmentId(String id) {        fragmentId = (new Integer(id)).intValue();    }    /**     * Return the entity resolver being used by the loader.     *      * @return the entity resolver being used by the loader.     */    public EntityResolver getEntityResolver() {        return this.entityResolver;    }    private boolean useSchemaLocationAttributes = false;    /**     * @see org.xbrlapi.loader.Loader#useSchemaLocationAttributes()     */    public boolean useSchemaLocationAttributes() {        return this.useSchemaLocationAttributes;    }    /**     * @see org.xbrlapi.loader.Loader#setSchemaLocationAttributeUsage(boolean)     */    public void setSchemaLocationAttributeUsage(boolean useThem) {        this.useSchemaLocationAttributes = useThem;    }    /**     * @see org.xbrlapi.loader.Loader#storeDocumentsToAnalyse()     */    public void storeDocumentsToAnalyse() throws XBRLException {        getStore().storeLoaderState(getDocumentsStillToAnalyse());    }}

⌨️ 快捷键说明

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