View Javadoc
1   package org.codehaus.plexus.components.io.resources;
2   
3   /*
4    * Copyright 2007 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
20  import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
21  
22  /**
23   * Default implementation of a resource collection with attributes.
24   */
25  public abstract class AbstractPlexusIoResourceCollectionWithAttributes extends AbstractPlexusIoResourceCollection {
26  
27      private PlexusIoResourceAttributes defaultFileAttributes;
28  
29      private PlexusIoResourceAttributes defaultDirAttributes;
30  
31      private PlexusIoResourceAttributes overrideFileAttributes;
32  
33      private PlexusIoResourceAttributes overrideDirAttributes;
34  
35      protected AbstractPlexusIoResourceCollectionWithAttributes() {}
36  
37      protected PlexusIoResourceAttributes getDefaultFileAttributes() {
38          return defaultFileAttributes;
39      }
40  
41      protected void setDefaultFileAttributes(final PlexusIoResourceAttributes defaultFileAttributes) {
42          this.defaultFileAttributes = defaultFileAttributes;
43      }
44  
45      protected PlexusIoResourceAttributes getDefaultDirAttributes() {
46          return defaultDirAttributes;
47      }
48  
49      protected void setDefaultDirAttributes(final PlexusIoResourceAttributes defaultDirAttributes) {
50          this.defaultDirAttributes = defaultDirAttributes;
51      }
52  
53      protected PlexusIoResourceAttributes getOverrideFileAttributes() {
54          return overrideFileAttributes;
55      }
56  
57      protected void setOverrideFileAttributes(final PlexusIoResourceAttributes overrideFileAttributes) {
58          this.overrideFileAttributes = overrideFileAttributes;
59      }
60  
61      protected PlexusIoResourceAttributes getOverrideDirAttributes() {
62          return overrideDirAttributes;
63      }
64  
65      protected void setOverrideDirAttributes(final PlexusIoResourceAttributes overrideDirAttributes) {
66          this.overrideDirAttributes = overrideDirAttributes;
67      }
68  
69      protected PlexusIoResourceAttributes mergeAttributes(PlexusIoResourceAttributes currentAttrs, boolean isDirectory) {
70          if (isDirectory) {
71              currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes(
72                      getOverrideDirAttributes(), currentAttrs, getDefaultDirAttributes());
73          } else {
74              currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes(
75                      getOverrideFileAttributes(), currentAttrs, getDefaultFileAttributes());
76          }
77          return currentAttrs;
78      }
79  }