View Javadoc

1   /*
2    * Copyright 2008 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  
17  package com.fatwire.gst.foundation.facade.runtag.assetset;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  import COM.FutureTense.Interfaces.IList;
21  
22  import com.fatwire.assetapi.data.AssetId;
23  import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner;
24  
25  /**
26   * Wrapper around the ASSETSET.GETATTRIBUTEVALUES xml tag
27   * 
28   * <pre>
29   * &lt;ASSETSET.GETATTRIBUTEVALUES NAME="assetsetname" ATTRIBUTE="attribname"
30   * [TYPENAME="assettypename"] LISTVARNAME="varname"
31   * [ORDERING="ascending|descending"]/&gt;
32   * </pre>
33   * 
34   * @author Mike Field
35   * @author Dolf Dijkstra
36   * @since July 15, 2008
37   */
38  public final class GetAttributeValues extends AbstractTagRunner {
39      // Default Constructor
40      public GetAttributeValues() {
41          super("ASSETSET.GETATTRIBUTEVALUES");
42      }
43  
44      /**
45       * Sets name to the value of <code>s</code>
46       * 
47       * @param s The name of the assetset to return
48       */
49      public void setName(String s) {
50          // validate first
51          if (s == null || s.length() == 0) {
52              throw new IllegalArgumentException("Invalid name string: " + s);
53          }
54          this.set("NAME", s);
55      }
56  
57      /**
58       * Sets attribute to the value of <code>s</code>
59       * 
60       * @param s The name of the attribute
61       */
62      public void setAttribute(String s) {
63          // validate first
64          if (s == null || s.length() == 0) {
65              throw new IllegalArgumentException("Invalid attribute string: " + s);
66          }
67          this.set("ATTRIBUTE", s);
68      }
69  
70      /**
71       * Sets listvarname to the value of <code>s</code>
72       * 
73       * @param s The name of the listvarname
74       */
75      public void setListvarname(String s) {
76          // validate first
77          if (s == null || s.length() == 0) {
78              throw new IllegalArgumentException("Invalid listvarname string: " + s);
79          }
80          this.set("LISTVARNAME", s);
81      }
82  
83      /**
84       * Sets typename to the value of <code>s</code>
85       * 
86       * @param s The attribute's typename
87       */
88      public void setTypename(String s) {
89          // validate first
90          if (s == null || s.length() == 0) {
91              throw new IllegalArgumentException("Invalid typename string: " + s);
92          }
93          this.set("TYPENAME", s);
94      }
95  
96      /**
97       * Sets immediateonly to the value of <code>s</code>
98       * 
99       * @param s The value of immediateonly: true or false
100      */
101     public void setImmediateonly(String s) {
102         // validate first
103         if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
104             throw new IllegalArgumentException("Invalid immediateonly string: " + s);
105         }
106         this.set("IMMEDIATEONLY", s);
107     }
108 
109     /**
110      * Sets ordering to the value of <code>s</code>
111      * 
112      * @param s The value of the ordering field: ascending or descending
113      */
114     public void setOrdering(String s) {
115         // validate first
116         if (s == null || s.length() == 0 || !s.equals("ascending") && !s.equals("descending")) {
117             throw new IllegalArgumentException("Invalid ordering string: " + s);
118         }
119         this.set("ORDERING", s);
120     }
121 
122     /**
123      * 
124      * @param ics
125      * @param id
126      * @param deptype
127      * @param locale
128      * @param attr
129      * @param attrType
130      * @param ordering
131      * @return IList with the attribute values.
132      */
133     public static IList getAttributeValues(ICS ics, AssetId id, String deptype, String locale, String attr,
134             String attrType, String ordering) {
135 
136         // create asset set
137         SetAsset setAsset = new SetAsset();
138         final String assetSetName = "__AssetSet" + ics.genID(false);
139         setAsset.setName(assetSetName);
140         setAsset.setType(id.getType());
141         setAsset.setId(Long.toString(id.getId()));
142         if (deptype != null) {
143             setAsset.setDeptype(deptype);
144         }
145         if (locale != null) {
146             setAsset.setLocale(locale);
147         }
148         setAsset.execute(ics);
149 
150         GetAttributeValues gav = new GetAttributeValues();
151         gav.setName(assetSetName);
152         gav.setAttribute(attr);
153         if (attrType != null) {
154             gav.setTypename(attrType);
155         }
156         if (ordering != null) {
157             gav.setOrdering(ordering);
158         }
159         String listname = ics.genID(true);
160         gav.setListvarname(listname);
161         gav.execute(ics);
162 
163         IList result = ics.GetList(listname);
164         ics.RegisterList(listname, null);
165         return result;
166     }
167 
168 }