Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.tools.validator.internal;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.URIParserUtil;
import org.apache.cxf.common.xmlschema.LSInputImpl;
import org.apache.cxf.resource.URIResolver;
import org.apache.cxf.tools.common.ToolConstants;
import org.apache.cxf.tools.common.ToolException;
public class SchemaValidator extends AbstractDefinitionValidator {
protected static final Logger LOG = LogUtils.getL7dLogger(SchemaValidator.class);
protected String[] defaultSchemas;
protected String schemaLocation = "./";
private String wsdlsrc;
private String[] xsds;
private List schemaFromJar;
private DocumentBuilder docBuilder;
private SAXParser saxParser;
public SchemaValidator(String schemaDir) throws ToolException {
schemaLocation = schemaDir;
defaultSchemas = getDefaultSchemas();
}
public SchemaValidator(String schemaDir, String wsdl, String[] schemas) throws ToolException {
schemaLocation = schemaDir;
defaultSchemas = getDefaultSchemas();
wsdlsrc = wsdl;
xsds = schemas;
}
public SchemaValidator(List defaultSchemas, String wsdl, String[] schemas) {
schemaLocation = null;
schemaFromJar = defaultSchemas;
wsdlsrc = wsdl;
xsds = schemas;
}
public boolean isValid() {
return validate(wsdlsrc, xsds);
}
public boolean validate(String wsdlsource, String[] schemas) throws ToolException {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
docFactory.setNamespaceAware(true);
docBuilder = docFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new ToolException(e);
}
String systemId = null;
systemId = URIParserUtil.getAbsoluteURI(wsdlsource);
InputSource is = new InputSource(systemId);
return validate(is, schemas);
}
private Schema createSchema(List xsdsInJar, String[] schemas)
throws SAXException, IOException {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
SchemaResourceResolver resourceResolver = new SchemaResourceResolver();
sf.setResourceResolver(resourceResolver);
List