View Javadoc

1   /*
2    * Copyright 2010 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.fatwire.gst.foundation.taglib;
17  
18  import java.io.IOException;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.List;
22  import javax.servlet.jsp.JspException;
23  
24  import COM.FutureTense.Interfaces.ICS;
25  
26  import com.fatwire.assetapi.data.AssetId;
27  import com.fatwire.mda.DimensionFilterInstance;
28  
29  /**
30   * simple tag for translating an asset
31   *
32   * @author Tony Field
33   * @since 11-11-22
34   */
35  public final class TranslateAssetTag extends MultilingualGsfSimpleTag {
36  
37      private AssetId assetId = null;
38  
39      private String output = null;
40  
41      public void setId(AssetId id) {
42          this.assetId = id;
43      }
44  
45      public void setOutput(String s) {
46          output = s;
47      }
48  
49      public void doTag() throws JspException, IOException {
50          LOG.trace("gsf:translate-asset start");
51  
52          final ICS ics = getICS();
53  
54          List<AssetId> toFilterList = Collections.singletonList(assetId);
55  
56          Collection<AssetId> result;
57  
58          DimensionFilterInstance filter = getDimensionFilter();
59  
60          if (filter == null) {
61              LOG.debug("Unable to locate dimension filter. Not filtering assets.  Returning input list");
62              result = toFilterList;
63          } else {
64              result = filter.filterAssets(toFilterList);
65              if (LOG.isDebugEnabled()) {
66                  LOG.debug("Filtered " + toFilterList + " using " + filter + " and got " + result);
67              }
68          }
69  
70          AssetId finalOutput = result == null || result.size() == 0 ? assetId : result.iterator().next();
71  
72          // register the result
73          ics.SetVar(output + ":c", finalOutput.getType());
74          ics.SetVar(output + ":cid", Long.toString(finalOutput.getId()));
75          getJspContext().setAttribute(output, finalOutput);
76  
77          super.doTag();
78          LOG.trace("gsf:translate-asset end");
79      }
80  }