protected void publishSchemaImports ( URL parentURL , Element element , List < String > published , String expLocation ) throws Exception { Element childElement = getFirstChildElement ( element ) ; while ( childElement != null ) { //first check on namespace only to avoid doing anything on any other wsdl/schema elements final String ns = childElement . getNamespaceURI ( ) ; if ( Constants . NS_SCHEMA_XSD . equals ( ns ) ) { final String ln = childElement . getLocalName ( ) ; if ( "import" . equals ( ln ) || "include" . equals ( ln ) ) { String schemaLocation = childElement . getAttribute ( "schemaLocation" ) ; if ( schemaLocation . length ( ) > 0 && schemaLocation . startsWith ( "http://" ) == false && schemaLocation . startsWith ( "https://" ) == false ) { // infinity loops prevention if ( ! published . contains ( schemaLocation ) ) { published . add ( schemaLocation ) ; String baseURI = parentURL . toExternalForm ( ) ; URL xsdURL = new URL ( baseURI . substring ( 0 , baseURI . lastIndexOf ( "/" ) + 1 ) + schemaLocation ) ; File targetFile = new File ( xsdURL . getFile ( ) ) ; //JBWS-3488 createParentDir ( targetFile ) ; String deploymentName = dep . getCanonicalName ( ) ; // get the resource path including the separator int index = baseURI . indexOf ( deploymentName ) + 1 ; String resourcePath = baseURI . substring ( index + deploymentName . length ( ) ) ; //check for sub-directories resourcePath = resourcePath . substring ( 0 , resourcePath . lastIndexOf ( "/" ) + 1 ) ; resourcePath = expLocation + resourcePath + schemaLocation ; while ( resourcePath . indexOf ( "//" ) != - 1 ) { resourcePath = resourcePath . replace ( "//" , "/" ) ; } URL resourceURL = dep . getResourceResolver ( ) . resolve ( resourcePath ) ; InputStream is = new ResourceURL ( resourceURL ) . openStream ( ) ; if ( is == null ) throw MESSAGES . cannotFindSchemaImportInDeployment ( resourcePath , deploymentName ) ; FileOutputStream fos = null ; try { fos = new FileOutputStream ( targetFile ) ; IOUtils . copyStream ( fos , is ) ; } finally { if ( fos != null ) fos . close ( ) ; } DEPLOYMENT_LOGGER . xmlSchemaImportPublishedTo ( xsdURL ) ; // recursively publish imports Element subdoc = DOMUtils . parse ( xsdURL . openStream ( ) , getDocumentBuilder ( ) ) ; publishSchemaImports ( xsdURL , subdoc , published , expLocation ) ; } } } else if ( "schema" . equals ( ln ) ) { //recurse, as xsd:schema might contain an import publishSchemaImports ( parentURL , childElement , published , expLocation ) ; } } else if ( Constants . NS_WSDL11 . equals ( ns ) && "types" . equals ( childElement . getLocalName ( ) ) ) { //recurse as wsdl:types might contain a schema publishSchemaImports ( parentURL , childElement , published , expLocation ) ; } childElement = getNextSiblingElement ( childElement ) ; } }
Publish the schema imports for a given wsdl definition