001 /* 002 * Copyright 2005 Stephen J. McConnell 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.tools.tasks; 020 021 import net.dpml.library.Resource; 022 import net.dpml.library.Feature; 023 import net.dpml.library.Type; 024 025 import org.apache.tools.ant.BuildException; 026 import org.apache.tools.ant.Project; 027 028 /** 029 * Locate a named feature of the a project or resource. 030 * 031 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 032 * @version 1.1.3 033 */ 034 public abstract class FeatureTask extends ResourceTask 035 { 036 private String m_feature; 037 private String m_type; // optional - used to select type when resolving uris 038 private boolean m_alias = false; // used when resolving uris 039 040 /** 041 * Set filename resolution switch. If true the filename feature will 042 * return an alias path. 043 * 044 * @param flag the alias switch 045 */ 046 public void setAlias( final boolean flag ) 047 { 048 m_alias = flag; 049 } 050 051 /** 052 * Set the name of the feature. 053 * @param feature the feature name 054 */ 055 public void setFeature( final String feature ) 056 { 057 m_feature = feature; 058 } 059 060 /** 061 * Optionaly set the resource type that the feature is related to. 062 * @param type the resource type 063 */ 064 public void setType( final String type ) 065 { 066 m_type = type; 067 } 068 069 /** 070 * Return the assigned feature name. 071 * @return the feature name 072 */ 073 protected String getFeature() 074 { 075 return m_feature; 076 } 077 078 /** 079 * Resolve the feature value. 080 * @return the feature value 081 */ 082 protected String resolve() 083 { 084 if( null == m_feature ) 085 { 086 final String error = "Missing 'feature' attribute."; 087 throw new BuildException( error ); 088 } 089 else 090 { 091 log( "Processing feature: " + m_feature, Project.MSG_VERBOSE ); 092 } 093 094 Resource resource = getResource(); 095 Feature feature = Feature.parse( m_feature ); 096 if( null == m_type ) 097 { 098 return Feature.resolve( resource, feature ); 099 } 100 else 101 { 102 Type type = resource.getType( m_type ); 103 return Feature.resolve( resource, feature, type, m_alias ); 104 } 105 } 106 }