Home | History | Annotate | Download | only in resources
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      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.android.ide.common.resources;
     18 
     19 import com.android.ide.common.rendering.api.ResourceValue;
     20 import com.android.ide.common.resources.configuration.Configurable;
     21 import com.android.ide.common.resources.configuration.FolderConfiguration;
     22 import com.android.io.IAbstractFile;
     23 import com.android.resources.ResourceType;
     24 
     25 import java.util.Collection;
     26 
     27 /**
     28  * Represents a Resource file (a file under $Project/res/)
     29  */
     30 public abstract class ResourceFile implements Configurable {
     31 
     32     private final IAbstractFile mFile;
     33     private final ResourceFolder mFolder;
     34 
     35     protected ResourceFile(IAbstractFile file, ResourceFolder folder) {
     36         mFile = file;
     37         mFolder = folder;
     38     }
     39 
     40     protected abstract void load(ScanningContext context);
     41     protected abstract void update(ScanningContext context);
     42     protected abstract void dispose(ScanningContext context);
     43 
     44     @Override
     45     public FolderConfiguration getConfiguration() {
     46         return mFolder.getConfiguration();
     47     }
     48 
     49     /**
     50      * Returns the IFile associated with the ResourceFile.
     51      */
     52     public final IAbstractFile getFile() {
     53         return mFile;
     54     }
     55 
     56     /**
     57      * Returns the parent folder as a {@link ResourceFolder}.
     58      */
     59     public final ResourceFolder getFolder() {
     60         return mFolder;
     61     }
     62 
     63     public final ResourceRepository getRepository() {
     64         return mFolder.getRepository();
     65     }
     66 
     67     /**
     68      * Returns whether the resource is a framework resource.
     69      */
     70     public final boolean isFramework() {
     71         return mFolder.getRepository().isFrameworkRepository();
     72     }
     73 
     74     /**
     75      * Returns the list of {@link ResourceType} generated by the file. This is never null.
     76      */
     77     public abstract Collection<ResourceType> getResourceTypes();
     78 
     79     /**
     80      * Returns whether the file generated a resource of a specific type.
     81      * @param type The {@link ResourceType}
     82      */
     83     public abstract boolean hasResources(ResourceType type);
     84 
     85     /**
     86      * Returns the value of a resource generated by this file by {@link ResourceType} and name.
     87      * <p/>If no resource match, <code>null</code> is returned.
     88      * @param type the type of the resource.
     89      * @param name the name of the resource.
     90      */
     91     public abstract ResourceValue getValue(ResourceType type, String name);
     92 
     93     @Override
     94     public String toString() {
     95         return mFile.toString();
     96     }
     97 }
     98 
     99