View Javadoc

1   /*
2   * Licensed to the Apache Software Foundation (ASF) under one or more
3   * contributor license agreements.  See the NOTICE file distributed with
4   * this work for additional information regarding copyright ownership.
5   * The ASF licenses this file to You under the Apache License, Version 2.0
6   * (the "License"); you may not use this file except in compliance with
7   * the License.  You may obtain a copy of the License at
8   *
9   *     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) throws Exception
35      {
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, String portletApplication) throws Exception
47      {
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, String portletApplication, String forcedVersion) throws Exception
61      {
62          String version = forcedVersion;
63          if(version == null)
64          {
65              version = doc.getRootElement().getAttributeValue("version", "2.3");
66          }
67          
68          try
69          {
70              // Check version is a valid number
71              Double.parseDouble(version);
72          }
73          catch(NumberFormatException e)
74          {
75              throw new Exception("Unable to create JetspeedWebApplicationRewriter for version " + version, e);
76          }
77          
78          if(version.equals("2.3"))
79          {
80              return new JetspeedWebApplicationRewriter2_3(doc, portletApplication);
81          }
82          else if(version.compareTo("2.4") >= 0)
83          {
84              return new JetspeedWebApplicationRewriter2_4(doc, portletApplication);
85          }
86          else
87          {
88              throw new Exception("Unable to create JetspeedWebApplicationRewriter for version " + version);
89          }
90      }
91  }