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  /**
18   * 
19   */
20  package com.fatwire.gst.foundation.facade.runtag.asset;
21  
22  import java.util.ArrayList;
23  import java.util.Enumeration;
24  import java.util.List;
25  
26  import COM.FutureTense.Interfaces.ICS;
27  
28  import com.fatwire.gst.foundation.facade.runtag.TagRunner;
29  
30  /**
31   * 
32   * 
33   * @author Dolf Dijkstra
34   * 
35   */
36  
37  public class LoadAndExport implements TagRunner {
38  
39      private final String assetType;
40  
41      private final long assetId;
42  
43      public LoadAndExport(final String assetType, final long assetId) {
44          super();
45          this.assetType = assetType;
46          this.assetId = assetId;
47      }
48  
49      public String execute(final ICS ics) {
50          final String name = "asset" + ics.genID(true);
51          try {
52              final AssetLoadById al = new AssetLoadById();
53              al.setName(name);
54              al.setAssetType(assetType);
55              al.setAssetId(assetId);
56              // al.setEditable(true);
57              al.setOption(AssetLoadById.OPTION_READ_ONLY_COMPLETE);
58  
59              al.execute(ics);
60  
61              new AssetScatter(name, "as", "PubList").execute(ics);
62              new AssetScatter(name, "as", true).execute(ics);
63              new AssetExport(name, "as", "xml").execute(ics);
64  
65              final String xml = ics.GetVar("xml");
66              ics.RemoveVar("xml");
67              return xml;
68          } finally {
69              // cleaning up
70              ics.SetObj(name, null);// clear obj from ics
71              final List<String> toClean = new ArrayList<String>();
72              for (final Enumeration<?> e = ics.GetVars(); e.hasMoreElements();) {
73                  final String k = (String) e.nextElement();
74                  if (k.startsWith("as:")) {
75                      toClean.add(k);
76                  }
77              }
78              // preventing java.util.ConcurrentModificationException
79              for (String n : toClean) {
80                  ics.RemoveVar(n);
81              }
82  
83          }
84      }
85  
86      public long getAssetId() {
87          return assetId;
88      }
89  
90      public String getAssetType() {
91          return assetType;
92      }
93  
94  }