FileDocCategorySizeDatePackage
MultiResourceFile.javaAPI DocAndroid 1.5 API5728Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources.manager

MultiResourceFile

public final class MultiResourceFile extends ResourceFile implements com.android.layoutlib.utils.ValueResourceParser.IValueResourceRepository
Represents a resource file able to declare multiple resources, which could be of different {@link ResourceType}.

This is typically an XML file inside res/values.

Fields Summary
private static final SAXParserFactory
sParserFactory
private final HashMap
mResourceItems
Constructors Summary
public MultiResourceFile(com.android.ide.eclipse.editors.resources.manager.files.IAbstractFile file, ResourceFolder folder)


         
        super(file, folder);
    
Methods Summary
public voidaddResourceValue(java.lang.String resType, com.android.layoutlib.utils.ResourceValue value)
Adds a resource item to the list

param
resType The type of the resource
param
value The value of the resource.

        ResourceType type = ResourceType.getEnum(resType);
        if (type != null) {
            HashMap<String, ResourceValue> list = mResourceItems.get(type);
    
            // if the list does not exist, create it.
            if (list == null) {
                list = new HashMap<String, ResourceValue>();
                mResourceItems.put(type, list);
            } else {
                // look for a possible value already existing.
                ResourceValue oldValue = list.get(value.getName());
                
                if (oldValue != null) {
                    oldValue.replaceWith(value);
                    return;
                }
            }
            
            // empty list or no match found? add the given resource
            list.put(value.getName(), value);
        }
    
public com.android.ide.eclipse.common.resources.ResourceType[]getResourceTypes()

        update();

        Set<ResourceType> keys = mResourceItems.keySet();
        
        return keys.toArray(new ResourceType[keys.size()]);
    
public java.util.CollectiongetResources(com.android.ide.eclipse.common.resources.ResourceType type, ProjectResources projectResources)

        update();

        HashMap<String, ResourceValue> list = mResourceItems.get(type);
        
        ArrayList<ProjectResourceItem> items = new ArrayList<ProjectResourceItem>();
        
        if (list != null) {
            Collection<ResourceValue> values = list.values();
            for (ResourceValue res : values) {
                ProjectResourceItem item = projectResources.findResourceItem(type, res.getName());
                
                if (item == null) {
                    if (type == ResourceType.ID) {
                        item = new IdResourceItem(res.getName(), false /* isDeclaredInline */);
                    } else {
                        item = new ConfigurableResourceItem(res.getName());
                    }
                    items.add(item);
                }

                item.add(this);
            }
        }

        return items;
    
public com.android.layoutlib.api.IResourceValuegetValue(com.android.ide.eclipse.common.resources.ResourceType type, java.lang.String name)

        update();

        // get the list for the given type
        HashMap<String, ResourceValue> list = mResourceItems.get(type);

        if (list != null) {
            return list.get(name);
        }
        
        return null;
    
public booleanhasResources(com.android.ide.eclipse.common.resources.ResourceType type)

        update();

        HashMap<String, ResourceValue> list = mResourceItems.get(type);
        return (list != null && list.size() > 0);
    
private voidparseFile()
Parses the file and creates a list of {@link ResourceType}.

        try {
            SAXParser parser = sParserFactory.newSAXParser();
            parser.parse(getFile().getContents(), new ValueResourceParser(this, isFramework()));
        } catch (ParserConfigurationException e) {
        } catch (SAXException e) {
        } catch (IOException e) {
        } catch (CoreException e) {
        }
    
private voidupdate()
Updates the Resource items if necessary.

        if (isTouched() == true) {
            // reset current content.
            mResourceItems.clear();

            // need to parse the file and find the content.
            parseFile();
            
            resetTouch();
        }