01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.geronimo.cxf;
19:
20: import java.io.FileNotFoundException;
21: import java.io.IOException;
22: import java.net.MalformedURLException;
23: import java.net.URL;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.apache.cxf.Bus;
28: import org.apache.cxf.catalog.OASISCatalogManager;
29: import org.apache.xml.resolver.Catalog;
30:
31: public class CXFCatalogUtils {
32:
33: private static final Log LOG = LogFactory
34: .getLog(CXFCatalogUtils.class);
35:
36: private CXFCatalogUtils() {
37: }
38:
39: public static void loadOASISCatalog(Bus bus, URL baseURL,
40: String catalogName) {
41: URL catalogURL = null;
42: try {
43: catalogURL = new URL(baseURL, catalogName);
44: LOG.debug("Checking for " + catalogURL + " catalog.");
45: catalogURL.openStream().close();
46: loadOASISCatalog(bus, catalogURL);
47: } catch (MalformedURLException e) {
48: LOG.warn("Error constructing catalog URL: " + baseURL + " "
49: + catalogName);
50: } catch (FileNotFoundException e) {
51: LOG.debug("Catalog " + catalogURL
52: + " is not present in the module");
53: } catch (IOException e) {
54: LOG.warn("Failed to load catalog file: " + catalogURL, e);
55: }
56: }
57:
58: private static void loadOASISCatalog(Bus bus, URL catalogURL) {
59: OASISCatalogManager catalog = new OASISCatalogManager();
60: try {
61: catalog.loadCatalog(catalogURL);
62: LOG.debug("Loaded " + catalogURL + " catalog.");
63: bus.setExtension(catalog.getCatalog(), Catalog.class);
64: } catch (IOException e) {
65: LOG.warn("Failed to load catalog file: " + catalogURL, e);
66: }
67: }
68: }
|