Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry.asset;
 
 import  org.apache.hivemind.Location;
 import  org.apache.hivemind.Resource;
 import  org.apache.hivemind.util.Defense;
 
 import java.util.*;

Implementation of the org.apache.tapestry.asset.AssetSource service interface.
 
 public class AssetSourceImpl implements AssetSource
 {
     private Map _assetFactoryByPrefix = new HashMap();
 
     private List _contributions;
 
 
     private AssetFactory _lookupAssetFactory;
 
 
 
     public void initializeService()
     {
         Iterator i = .iterator();
         while (i.hasNext())
         {
             AssetFactoryContribution c = (AssetFactoryContributioni.next();
 
             .put(c.getPrefix(), c.getFactory());
         }
     }
 
     public IAsset findAsset(Resource baseString pathLocale locale, Location location)
     {
         return findAsset(basenullpathlocalelocation);
     }
 
     public IAsset findAsset(Resource baseIComponentSpecification specString pathLocale locale, Location location)
     {
         Defense.notNull(path"path");
         Defense.notNull(location"location");
 
         int colonx = path.indexOf(':');
         
         String prefix = colonx > -1 ? path.substring(0, colonx) : null;
         String truePath = colonx > -1 ? path.substring(colonx + 1) : path;
 
         AssetFactory factory = null;
 
         if (prefix != null) {
 
             factory = (AssetFactory.get(prefix);
         }
 
         // now we have to search
         
         if (factory == null && prefix == null) {
             
             factory = findAssetFactory(specbasetruePathlocale);
         }
         
         // Unknown prefix is expected to happen when an external asset (using an established
         // prefix such as http:) is referenced.
 
         if (factory == null)
         {
             factory = ;
 
             // Path is the full path, including the prefix (which is really the scheme
             // of the URL).
 
             truePath = path;
         }
         
         if (truePath.startsWith("/"))
             return factory.createAbsoluteAsset(truePathlocalelocation);
 
         // This can happen when a 3.0 DTD is read in
        return factory.createAsset(basespectruePathlocalelocation);
    }
    AssetFactory findAssetFactory(IComponentSpecification spec, Resource baseResourceString pathLocale locale)
    {
        // need to check these two core factories in order first
        if (.assetExists(specbaseResourcepathlocale))
            return ;
        if (.assetExists(specbaseResourcepathlocale))
            return ;
        
        for (int i=0; i < .size(); i++) {
            if (c.getFactory().assetExists(specbaseResourcepathlocale))
                return c.getFactory();
        }
        return null;
    }

    
Factory used when the path has no prefix, and the type of asset must be inferred from the type of resource.
    public void setLookupAssetFactory(AssetFactory lookupAssetFactory)
    {
         = lookupAssetFactory;
    }

    
List of org.apache.tapestry.asset.AssetFactoryContribution.
    public void setContributions(List contributions)
    {
         = contributions;
    }

    
Factory used when an unrecognized prefix (typically, an arbitrary URL's scheme) is provided.
    public void setDefaultAssetFactory(AssetFactory defaultAssetFactory)
    {
         = defaultAssetFactory;
    }
    public void setClasspathAssetFactory(AssetFactory classpathAssetFactory)
    {
         = classpathAssetFactory;
    }
    public void setContextAssetFactory(AssetFactory contextAssetFactory)
    {
         = contextAssetFactory;
    }
New to GrepCode? Check out our FAQ X