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.commons.resourcehandler.resource;
20  
21  /**
22   * Contains the metadata information to reference a resource 
23   * 
24   * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
25   * @version $Revision: 700544 $ $Date: 2008-09-30 13:44:02 -0500 (Mar, 30 Sep 2008) $
26   */
27  public class ResourceMetaImpl extends ResourceMeta
28  {
29  
30      private final String _prefix;
31      private final String _libraryName;
32      private final String _libraryVersion;
33      private final String _resourceName;
34      private final String _resourceVersion;
35      
36      public ResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
37              String resourceName, String resourceVersion)
38      {
39          _prefix = prefix;
40          _libraryName = libraryName;
41          _libraryVersion = libraryVersion;
42          _resourceName = resourceName;
43          _resourceVersion = resourceVersion;
44      }
45  
46      public String getLibraryName()
47      {
48          return _libraryName;
49      }    
50      
51      public String getResourceName()
52      {
53          return _resourceName;
54      }    
55  
56      public String getLocalePrefix()
57      {
58          return _prefix;
59      }
60  
61      public String getLibraryVersion()
62      {
63          return _libraryVersion;
64      }
65  
66      public String getResourceVersion()
67      {
68          return _resourceVersion;
69      }
70      
71      @Override
72      public String getResourceIdentifier()
73      {
74          StringBuilder builder = new StringBuilder();
75          boolean firstSlashAdded = false;
76          if (_prefix != null && _prefix.length() > 0)
77          {
78              builder.append(_prefix);
79              firstSlashAdded = true;
80          }
81          if (_libraryName != null)
82          {
83              if (firstSlashAdded) builder.append('/');
84              builder.append(_libraryName);
85              firstSlashAdded = true;
86          }
87          if (_libraryVersion != null)
88          {
89              if (firstSlashAdded) builder.append('/');
90              builder.append(_libraryVersion);
91              firstSlashAdded = true;
92          }
93          if (_resourceName != null)
94          {
95              if (firstSlashAdded) builder.append('/');
96              builder.append(_resourceName);
97              firstSlashAdded = true;
98          }
99          if (_resourceVersion != null)
100         {
101             if (firstSlashAdded) builder.append('/');
102             builder.append(_resourceVersion);
103             builder.append(
104                     _resourceName.substring(_resourceName.lastIndexOf('.')));
105             firstSlashAdded = true;
106         }
107 
108         return builder.toString();
109     }
110 
111     @Override
112     public boolean couldResourceContainValueExpressions()
113     {
114         return false;
115     }
116 }