View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.shared.resource;
20  
21  /**
22   * Contains the metadata information to reference a resource 
23   */
24  public class ResourceMetaImpl extends ResourceMeta
25  {
26  
27      private final String _prefix;
28      private final String _libraryName;
29      private final String _libraryVersion;
30      private final String _resourceName;
31      private final String _resourceVersion;
32      private final String _contractName;
33  
34      public ResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
35              String resourceName, String resourceVersion)
36      {
37          this(prefix, libraryName, libraryVersion, resourceName, resourceVersion, null);
38      }
39      
40      public ResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
41              String resourceName, String resourceVersion, String contractName)
42      {
43          _prefix = prefix;
44          _libraryName = libraryName;
45          _libraryVersion = libraryVersion;
46          _resourceName = resourceName;
47          _resourceVersion = resourceVersion;
48          _contractName = contractName;
49      }
50  
51      public String getLibraryName()
52      {
53          return _libraryName;
54      }    
55      
56      public String getResourceName()
57      {
58          return _resourceName;
59      }    
60  
61      public String getLocalePrefix()
62      {
63          return _prefix;
64      }
65  
66      public String getLibraryVersion()
67      {
68          return _libraryVersion;
69      }
70  
71      public String getResourceVersion()
72      {
73          return _resourceVersion;
74      }
75  
76      public String getContractName()
77      {
78          return _contractName;
79      }
80      
81      @Override
82      public String getResourceIdentifier()
83      {
84          StringBuilder builder = new StringBuilder();
85          boolean firstSlashAdded = false;
86          if (_prefix != null && _prefix.length() > 0)
87          {
88              builder.append(_prefix);
89              firstSlashAdded = true;
90          }
91          if (_libraryName != null)
92          {
93              if (firstSlashAdded)
94              {
95                  builder.append('/');
96              }
97              builder.append(_libraryName);
98              firstSlashAdded = true;
99          }
100         if (_libraryVersion != null)
101         {
102             if (firstSlashAdded)
103             {
104                 builder.append('/');
105             }
106             builder.append(_libraryVersion);
107             firstSlashAdded = true;
108         }
109         if (_resourceName != null)
110         {
111             if (firstSlashAdded)
112             {
113                 builder.append('/');
114             }
115             builder.append(_resourceName);
116             firstSlashAdded = true;
117         }
118         if (_resourceVersion != null)
119         {
120             if (firstSlashAdded)
121             {
122                 builder.append('/');
123             }
124             builder.append(_resourceVersion);
125             builder.append(
126                     _resourceName.substring(_resourceName.lastIndexOf('.')));
127             firstSlashAdded = true;
128         }
129 
130         return builder.toString();
131     }
132 
133     @Override
134     public boolean couldResourceContainValueExpressions()
135     {
136         return false;
137     }
138 
139 }