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 AliasResourceMetaImpl extends ResourceMetaImpl
25  {
26      private String _realResourceName;
27      
28      private boolean _couldContainValueExpressions;
29  
30      public AliasResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
31              String resourceName, String resourceVersion, String realResourceName, boolean couldContainValueExpressions)
32      {
33          this(prefix, libraryName, libraryVersion, resourceName, resourceVersion, realResourceName, 
34              couldContainValueExpressions, null);
35      }
36      
37      public AliasResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
38              String resourceName, String resourceVersion, String realResourceName, 
39              boolean couldContainValueExpressions, String contractName)
40      {
41          super(prefix, libraryName, libraryVersion,
42              resourceName, resourceVersion, contractName);
43          _realResourceName = realResourceName;
44          _couldContainValueExpressions = couldContainValueExpressions;
45      }
46      
47      public String getRealResourceName()
48      {
49          return _realResourceName;
50      }
51  
52      public void setRealResourceName(String realResourceName)
53      {
54          _realResourceName = realResourceName;
55      }
56      
57      @Override
58      public String getResourceIdentifier()
59      {
60          StringBuilder builder = new StringBuilder();
61          boolean firstSlashAdded = false;
62          if (getLocalePrefix() != null && getLocalePrefix().length() > 0)
63          {
64              builder.append(getLocalePrefix());
65              firstSlashAdded = true;
66          }
67          if (getLibraryName() != null)
68          {
69              if (firstSlashAdded)
70              {
71                  builder.append('/');
72              }
73              builder.append(getLibraryName());
74              firstSlashAdded = true;
75          }
76          if (getLibraryVersion() != null)
77          {
78              if (firstSlashAdded)
79              {
80                  builder.append('/');
81              }
82              builder.append(getLibraryVersion());
83              firstSlashAdded = true;
84          }
85          if (getRealResourceName() != null)
86          {
87              if (firstSlashAdded)
88              {
89                  builder.append('/');
90              }
91              builder.append(getRealResourceName());
92              firstSlashAdded = true;
93          }
94          if (getResourceVersion() != null)
95          {
96              if (firstSlashAdded)
97              {
98                  builder.append('/');
99              }
100             builder.append(getResourceVersion());
101             builder.append(
102                     getRealResourceName().substring(getRealResourceName().lastIndexOf('.')));
103             firstSlashAdded = true;
104         }
105         return builder.toString();
106     }
107 
108     @Override
109     public boolean couldResourceContainValueExpressions()
110     {
111         return _couldContainValueExpressions;
112     }
113 }