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

📄 schemavalidate.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    protected void addSchemaLocations() {        Iterator it = schemaLocations.values().iterator();        StringBuffer buffer = new StringBuffer();        int count = 0;        while (it.hasNext()) {            if (count > 0) {                buffer.append(' ');            }            SchemaLocation schemaLocation = (SchemaLocation) it.next();            String tuple = schemaLocation.getURIandLocation();            buffer.append(tuple);            log("Adding schema " + tuple, Project.MSG_VERBOSE);            count++;        }        if (count > 0) {            setProperty(XmlConstants.PROPERTY_SCHEMA_LOCATION, buffer.toString());        }    }    /**     * get the URL of the no namespace schema     * @return the schema URL     */    protected String getNoNamespaceSchemaURL() {        if (anonymousSchema == null) {            return null;        } else {            return anonymousSchema.getSchemaLocationURL();        }    }    /**     * set a feature if it is supported, log at verbose level if     * not     * @param feature the feature.     * @param value a <code>boolean</code> value.     */    protected void setFeatureIfSupported(String feature, boolean value) {        try {            getXmlReader().setFeature(feature, value);        } catch (SAXNotRecognizedException e) {            log("Not recognizied: " + feature, Project.MSG_VERBOSE);        } catch (SAXNotSupportedException e) {            log("Not supported: " + feature, Project.MSG_VERBOSE);        }    }    /**     * handler called on successful file validation.     *     * @param fileProcessed number of files processed.     */    protected void onSuccessfulValidation(int fileProcessed) {        log(fileProcessed + MESSAGE_FILES_VALIDATED, Project.MSG_VERBOSE);    }    /**     * representation of a schema location. This is a URI plus either a file or     * a url     */    public static class SchemaLocation {        private String namespace;        private File file;        private String url;        /** No namespace URI */        public static final String ERROR_NO_URI = "No namespace URI";        /** Both URL and File were given for schema */        public static final String ERROR_TWO_LOCATIONS            = "Both URL and File were given for schema ";        /** File not found */        public static final String ERROR_NO_FILE = "File not found: ";        /** Cannot make URL */        public static final String ERROR_NO_URL_REPRESENTATION            = "Cannot make a URL of ";        /** No location provided */        public static final String ERROR_NO_LOCATION            = "No file or URL supplied for the schema ";        /** No arg constructor */        public SchemaLocation() {        }        /**         * Get the namespace.         * @return the namespace.         */        public String getNamespace() {            return namespace;        }        /**         * set the namespace of this schema. Any URI         * @param namespace the namespace to use.         */        public void setNamespace(String namespace) {            this.namespace = namespace;        }        /**         * Get the file.         * @return the file containing the schema.         */        public File getFile() {            return file;        }        /**         * identify a file that contains this namespace's schema.         * The file must exist.         * @param file the file contains the schema.         */        public void setFile(File file) {            this.file = file;        }        /**         * The URL containing the schema.         * @return the URL string.         */        public String getUrl() {            return url;        }        /**         * identify a URL that hosts the schema.         * @param url the URL string.         */        public void setUrl(String url) {            this.url = url;        }        /**         * get the URL of the schema         * @return a URL to the schema         * @throws BuildException if not         */        public String getSchemaLocationURL() {            boolean hasFile = file != null;            boolean hasURL = isSet(url);            //error if both are empty, or both are set            if (!hasFile && !hasURL) {                throw new BuildException(ERROR_NO_LOCATION + namespace);            }            if (hasFile && hasURL) {                throw new BuildException(ERROR_TWO_LOCATIONS + namespace);            }            String schema = url;            if (hasFile) {                if (!file.exists()) {                    throw new BuildException(ERROR_NO_FILE + file);                }                try {                    schema = FileUtils.getFileUtils().getFileURL(file).toString();                } catch (MalformedURLException e) {                    //this is almost implausible, but required handling                    throw new BuildException(ERROR_NO_URL_REPRESENTATION + file, e);                }            }            return schema;        }        /**         * validate the fields then create a "uri location" string         *         * @return string of uri and location         * @throws BuildException if there is an error.         */        public String getURIandLocation() throws BuildException {            validateNamespace();            StringBuffer buffer = new StringBuffer();            buffer.append(namespace);            buffer.append(' ');            buffer.append(getSchemaLocationURL());            return new String(buffer);        }        /**         * assert that a namespace is valid         * @throws BuildException if not         */        public void validateNamespace() {            if (!isSet(getNamespace())) {                throw new BuildException(ERROR_NO_URI);            }        }        /**         * check that a property is set         * @param property string to check         * @return true if it is not null or empty         */        private boolean isSet(String property) {            return property != null && property.length() != 0;        }        /**         * equality test checks namespace, location and filename. All must match,         * @param o object to compare against         * @return true iff the objects are considered equal in value         */        public boolean equals(Object o) {            if (this == o) {                return true;            }            if (!(o instanceof SchemaLocation)) {                return false;            }            final SchemaLocation schemaLocation = (SchemaLocation) o;            if (file != null ? !file.equals(schemaLocation.file) : schemaLocation.file != null) {                return false;            }            if (namespace != null ? !namespace.equals(schemaLocation.namespace)                    : schemaLocation.namespace != null) {                return false;            }            if (url != null ? !url.equals(schemaLocation.url) : schemaLocation.url != null) {                return false;            }            return true;        }        /**         * Generate a hashcode depending on the namespace, url and file name.         * @return the hashcode.         */        public int hashCode() {            int result;            // CheckStyle:MagicNumber OFF            result = (namespace != null ? namespace.hashCode() : 0);            result = 29 * result + (file != null ? file.hashCode() : 0);            result = 29 * result + (url != null ? url.hashCode() : 0);            // CheckStyle:MagicNumber OFF            return result;        }        /**         * Returns a string representation of the object for error messages         * and the like         * @return a string representation of the object.         */        public String toString() {            StringBuffer buffer = new StringBuffer();            buffer.append(namespace != null ? namespace : "(anonymous)");            buffer.append(' ');            buffer.append(url != null ? (url + " ") : "");            buffer.append(file != null ? file.getAbsolutePath() : "");            return buffer.toString();        }    } //SchemaLocation}

⌨️ 快捷键说明

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