001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 package org.apache.geronimo.cxf; 020 021 import java.io.FileNotFoundException; 022 import java.io.IOException; 023 import java.net.MalformedURLException; 024 import java.net.URL; 025 026 import org.apache.commons.logging.Log; 027 import org.apache.commons.logging.LogFactory; 028 import org.apache.cxf.Bus; 029 import org.apache.cxf.catalog.OASISCatalogManager; 030 import org.apache.xml.resolver.Catalog; 031 032 public class CXFCatalogUtils { 033 034 private static final Log LOG = LogFactory.getLog(CXFCatalogUtils.class); 035 036 private CXFCatalogUtils() { 037 } 038 039 public static void loadOASISCatalog(Bus bus, URL baseURL, String catalogName) { 040 URL catalogURL = null; 041 try { 042 catalogURL = new URL(baseURL, catalogName); 043 LOG.debug("Checking for " + catalogURL + " catalog."); 044 catalogURL.openStream().close(); 045 loadOASISCatalog(bus, catalogURL); 046 } catch (MalformedURLException e) { 047 LOG.warn("Error constructing catalog URL: " + baseURL + " " + catalogName); 048 } catch (FileNotFoundException e) { 049 LOG.debug("Catalog " + catalogURL + " is not present in the module"); 050 } catch (IOException e) { 051 LOG.warn("Failed to load catalog file: " + catalogURL, e); 052 } 053 } 054 055 private static void loadOASISCatalog(Bus bus, URL catalogURL) { 056 OASISCatalogManager catalog = new OASISCatalogManager(); 057 try { 058 catalog.loadCatalog(catalogURL); 059 LOG.debug("Loaded " + catalogURL + " catalog."); 060 bus.setExtension(catalog.getCatalog(), Catalog.class); 061 } catch (IOException e) { 062 LOG.warn("Failed to load catalog file: " + catalogURL, e); 063 } 064 } 065 }