Coverage Report - org.apache.tapestry.javascript.JavascriptManagerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JavascriptManagerImpl
100% 
100% 
1.2
 
 1  
 // Copyright 2007 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.javascript;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.hivemind.HiveMind;
 21  
 import org.apache.hivemind.Location;
 22  
 import org.apache.hivemind.util.URLResource;
 23  
 import org.apache.tapestry.IAsset;
 24  
 import org.apache.tapestry.TapestryUtils;
 25  
 import org.apache.tapestry.asset.AssetSource;
 26  
 import org.apache.tapestry.util.DescribedLocation;
 27  
 
 28  
 /**
 29  
  * An implementation that accepts a comma separated String for
 30  
  * files, formFiles and widgetFiles. 
 31  
  *
 32  
  * @author Andreas Andreou
 33  
  * @since 4.1.4
 34  
  */
 35  
 public class JavascriptManagerImpl implements JavascriptManager
 36  
 {
 37  
     private AssetSource _assetSource;
 38  
     private List _files;
 39  
     private List _formFiles;
 40  
     private List _widgetFiles;
 41  
     private IAsset _path;
 42  
     private IAsset _tapestryFile;
 43  
     private IAsset _tapestryPath;
 44  
 
 45  
     public JavascriptManagerImpl()
 46  3
     {
 47  3
         _files = new ArrayList();
 48  3
         _formFiles = new ArrayList();
 49  3
         _widgetFiles = new ArrayList();
 50  3
     }
 51  
 
 52  
     public IAsset getFirstAsset()
 53  
     {
 54  3
         return findFirst(_files);
 55  
     }
 56  
 
 57  
     public IAsset getFirstFormAsset()
 58  
     {
 59  2
         return findFirst(_formFiles);
 60  
     }
 61  
 
 62  
     public IAsset getFirstWidgetAsset()
 63  
     {
 64  2
         return findFirst(_widgetFiles);
 65  
     }
 66  
 
 67  
     public List getAssets()
 68  
     {
 69  3
         return _files;
 70  
     }
 71  
 
 72  
     public List getFormAssets()
 73  
     {
 74  2
         return _formFiles;
 75  
     }
 76  
 
 77  
     public List getWidgetAssets()
 78  
     {
 79  2
         return _widgetFiles;
 80  
     }
 81  
 
 82  
     public IAsset getPath()
 83  
     {
 84  2
         return _path;
 85  
     }
 86  
 
 87  
     public IAsset getTapestryAsset()
 88  
     {
 89  3
         return _tapestryFile;
 90  
     }
 91  
 
 92  
     public IAsset getTapestryPath()
 93  
     {
 94  2
         return _tapestryPath;
 95  
     }
 96  
 
 97  
     public void setFiles(String files)
 98  
     {
 99  2
         _files = buildAssetList(files, "files");
 100  2
     }
 101  
 
 102  
     public void setFormFiles(String formFiles)
 103  
     {
 104  2
         _formFiles = buildAssetList(formFiles, "formFiles");
 105  2
     }
 106  
 
 107  
     public void setWidgetFiles(String widgetFiles)
 108  
     {
 109  2
         _widgetFiles = buildAssetList(widgetFiles, "widgetFiles");
 110  2
     }
 111  
 
 112  
     public void setFolder(String path)
 113  
     {
 114  2
         _path = findAsset(path, "folder");
 115  2
     }
 116  
 
 117  
     public void setTapestryFile(String tapestryFile)
 118  
     {
 119  2
         _tapestryFile = findAsset(tapestryFile, "tapestryFile");
 120  2
     }
 121  
 
 122  
     public void setTapestryFolder(String tapestryPath)
 123  
     {
 124  2
         _tapestryPath = findAsset(tapestryPath, "tapestryFolder");
 125  2
     }
 126  
 
 127  
     public void setAssetSource(AssetSource assetSource)
 128  
     {
 129  3
         _assetSource = assetSource;
 130  3
     }
 131  
 
 132  
     private List buildAssetList(String files, String name)
 133  
     {
 134  6
         String[] js = TapestryUtils.split(files);
 135  
         
 136  6
         List list = new ArrayList(js.length);
 137  8
         for (int i=0; i<js.length; i++) {
 138  2
             list.add(findAsset(js[i], name + i));
 139  
         }
 140  
 
 141  6
         return list;
 142  
     }
 143  
 
 144  
     private IAsset findAsset(String path, String description)
 145  
     {
 146  8
         IAsset asset = null;
 147  8
         if ( !HiveMind.isBlank(path) )
 148  
         {
 149  3
             Location location = new DescribedLocation(new URLResource(path), description);
 150  3
             asset = _assetSource.findAsset(null, path, null, location);
 151  
         }
 152  8
         return asset;
 153  
     }
 154  
 
 155  
     private IAsset findFirst(List list)
 156  
     {
 157  7
         if (list == null || list.isEmpty())
 158  6
             return null;
 159  
         else
 160  1
             return (IAsset) list.get(0);
 161  
     }
 162  
 }