01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.tools.deploy;
18:
19: import org.jdom.Document;
20:
21: /**
22: * @author Nicolas Dutertry
23: * @version $Id: JetspeedWebApplicationRewriterFactory.java 516881 2007-03-11 10:34:21Z ate $
24: */
25: public class JetspeedWebApplicationRewriterFactory {
26:
27: /**
28: * Returns an instance of JetspeedWebApplicationRewriter.
29: *
30: * @param doc
31: * @return JetspeedWebApplicationRewriter
32: * @throws Exception
33: */
34: public JetspeedWebApplicationRewriter getInstance(Document doc)
35: throws Exception {
36: return getInstance(doc, null, null);
37: }
38:
39: /**
40: * Returns an instance of JetspeedWebApplicationRewriter.
41: *
42: * @param doc
43: * @return JetspeedWebApplicationRewriter
44: * @throws Exception
45: */
46: public JetspeedWebApplicationRewriter getInstance(Document doc,
47: String portletApplication) throws Exception {
48: return getInstance(doc, portletApplication, null);
49: }
50:
51: /**
52: * Returns an instance of JetspeedWebApplicationRewriter.
53: *
54: * @param doc
55: * @param portletApplication
56: * @param forcedVersion
57: * @return JetspeedWebApplicationRewriter
58: * @throws Exception
59: */
60: public JetspeedWebApplicationRewriter getInstance(Document doc,
61: String portletApplication, String forcedVersion)
62: throws Exception {
63: String version = forcedVersion;
64: if (version == null) {
65: version = doc.getRootElement().getAttributeValue("version",
66: "2.3");
67: }
68:
69: try {
70: // Check version is a valid number
71: Double.parseDouble(version);
72: } catch (NumberFormatException e) {
73: throw new Exception(
74: "Unable to create JetspeedWebApplicationRewriter for version "
75: + version, e);
76: }
77:
78: if (version.equals("2.3")) {
79: return new JetspeedWebApplicationRewriter2_3(doc,
80: portletApplication);
81: } else if (version.compareTo("2.4") >= 0) {
82: return new JetspeedWebApplicationRewriter2_4(doc,
83: portletApplication);
84: } else {
85: throw new Exception(
86: "Unable to create JetspeedWebApplicationRewriter for version "
87: + version);
88: }
89: }
90: }
|