View Javadoc
1   package org.apache.maven.doxia.parser.module;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * An abstract base class that implements the ParserModule interface.
24   *
25   * @since 1.6
26   */
27  public abstract class AbstractParserModule
28      implements ParserModule
29  {
30      /** The source directory. */
31      private final String sourceDirectory;
32  
33      /** The supported file extensions. */
34      private final String[] extensions;
35  
36      /** The default file extension. */
37      private final String parserId;
38  
39      /**
40       * Constructor with null.
41       */
42      public AbstractParserModule()
43      {
44          this( null, null, (String[]) null );
45      }
46  
47      /**
48       * Constructor with same value for everything: source directory and file extension equal parserId.
49       */
50      public AbstractParserModule( String parserId )
51      {
52          this( parserId, parserId, parserId );
53      }
54  
55      /**
56       * Constructor with same value for parser id and source directory.
57       */
58      public AbstractParserModule( String parserId, String extension )
59      {
60          this( parserId, parserId, new String[] { extension } );
61      }
62  
63      /**
64       * @param sourceDirectory not null
65       * @param extension not null
66       * @param parserId not null
67       * @since 1.1.1
68       * @deprecated can cause confusion with constructor with multiple extensions
69       */
70      protected AbstractParserModule( String sourceDirectory, String extension, String parserId )
71      {
72          super();
73          this.sourceDirectory = sourceDirectory;
74          this.extensions = new String[] { extension };
75          this.parserId = parserId;
76      }
77  
78      /**
79       * @param sourceDirectory not null
80       * @param parserId not null (usually equals sourceDirectory)
81       * @param extensions not null
82       * @since 1.7
83       */
84      protected AbstractParserModule( String sourceDirectory, String parserId, String... extensions )
85      {
86          super();
87          this.sourceDirectory = sourceDirectory;
88          this.extensions = extensions;
89          this.parserId = parserId;
90      }
91  
92      /** {@inheritDoc} */
93      public String getSourceDirectory()
94      {
95          return sourceDirectory;
96      }
97  
98      /** {@inheritDoc} */
99      public String[] getExtensions()
100     {
101         return extensions;
102     }
103 
104     /** {@inheritDoc} */
105     public String getParserId()
106     {
107         return parserId;
108     }
109 }