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       * @param parserId the parser id
51       */
52      public AbstractParserModule( String parserId )
53      {
54          this( parserId, parserId, parserId );
55      }
56  
57      /**
58       * Constructor with same value for parser id and source directory.
59       * 
60       * @param parserId the parser id
61       * @param extension the file extension
62       */
63      public AbstractParserModule( String parserId, String extension )
64      {
65          this( parserId, parserId, new String[] { extension } );
66      }
67  
68      /**
69       * @param sourceDirectory not null
70       * @param extension not null
71       * @param parserId not null
72       * @since 1.1.1
73       * @deprecated can cause confusion with constructor with multiple extensions
74       */
75      protected AbstractParserModule( String sourceDirectory, String extension, String parserId )
76      {
77          super();
78          this.sourceDirectory = sourceDirectory;
79          this.extensions = new String[] { extension };
80          this.parserId = parserId;
81      }
82  
83      /**
84       * @param sourceDirectory not null
85       * @param parserId not null (usually equals sourceDirectory)
86       * @param extensions not null
87       * @since 1.7
88       */
89      protected AbstractParserModule( String sourceDirectory, String parserId, String... extensions )
90      {
91          super();
92          this.sourceDirectory = sourceDirectory;
93          this.extensions = extensions;
94          this.parserId = parserId;
95      }
96  
97      /** {@inheritDoc} */
98      public String getSourceDirectory()
99      {
100         return sourceDirectory;
101     }
102 
103     /** {@inheritDoc} */
104     public String[] getExtensions()
105     {
106         return extensions;
107     }
108 
109     /** {@inheritDoc} */
110     public String getParserId()
111     {
112         return parserId;
113     }
114 }