com.android.io.IAbstractFile Java Examples

The following examples show how to use com.android.io.IAbstractFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectPropertiesWorkingCopy.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Merges all properties from the given file into the current properties.
 * <p/>
 * This emulates the Ant behavior: existing properties are <em>not</em> overridden.
 * Only new undefined properties become defined.
 * <p/>
 * Typical usage:
 * <ul>
 * <li>Create a ProjectProperties with {@code PropertyType#ANT}
 * <li>Merge in values using {@code PropertyType#PROJECT}
 * <li>The result is that this contains all the properties from default plus those
 *     overridden by the build.properties file.
 * </ul>
 *
 * @param type One the possible {@link ProjectProperties.PropertyType}s.
 * @return this object, for chaining.
 */
public synchronized ProjectPropertiesWorkingCopy merge(PropertyType type) {
    if (mProjectFolder.exists() && mType != type) {
        IAbstractFile propFile = mProjectFolder.getFile(type.getFilename());
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                for (Entry<String, String> entry : map.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (!mProperties.containsKey(key) && value != null) {
                        mProperties.put(key, value);
                    }
                }
            }
        }
    }
    return this;
}
 
Example #2
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath)
        throws StreamException, XPathExpressionException {
    XPath xpath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = file.getContents();
        return xpath.evaluate(xPath, new InputSource(is));
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }
}
 
Example #3
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the value of the minSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the attribute value.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getMinSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_MIN_SDK_VERSION);

    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #4
Source File: ProjectPropertiesWorkingCopy.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Merges all properties from the given file into the current properties.
 * <p/>
 * This emulates the Ant behavior: existing properties are <em>not</em> overridden.
 * Only new undefined properties become defined.
 * <p/>
 * Typical usage:
 * <ul>
 * <li>Create a ProjectProperties with {@code PropertyType#ANT}
 * <li>Merge in values using {@code PropertyType#PROJECT}
 * <li>The result is that this contains all the properties from default plus those
 *     overridden by the build.properties file.
 * </ul>
 *
 * @param type One the possible {@link ProjectProperties.PropertyType}s.
 * @return this object, for chaining.
 */
public synchronized ProjectPropertiesWorkingCopy merge(PropertyType type) {
    if (mProjectFolder.exists() && mType != type) {
        IAbstractFile propFile = mProjectFolder.getFile(type.getFilename());
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                for (Entry<String, String> entry : map.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (!mProperties.containsKey(key) && value != null) {
                        mProperties.put(key, value);
                    }
                }
            }
        }
    }
    return this;
}
 
Example #5
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of the minSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the attribute value.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getMinSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_MIN_SDK_VERSION);

    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #6
Source File: SingleResourceFile.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the associated resource file to make sure the attribute references are valid
 *
 * @return true if parsing succeeds and false if it fails
 */
private boolean validateAttributes(ScanningContext context) {
    // We only need to check if it's a non-framework file (and an XML file; skip .png's)
    if (!isFramework() && SdkUtils.endsWith(getFile().getName(), DOT_XML)) {
        ValidatingResourceParser parser = new ValidatingResourceParser(context, false);
        try {
            IAbstractFile file = getFile();
            return parser.parse(file.getOsLocation(), file.getContents());
        } catch (Exception e) {
            context.needsFullAapt();
        }

        return false;
    }

    return true;
}
 
Example #7
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath)
        throws StreamException, XPathExpressionException {
    XPath xpath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = file.getContents();
        return xpath.evaluate(xPath, new InputSource(is));
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }
}
 
Example #8
Source File: SingleResourceFile.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Validates the associated resource file to make sure the attribute references are valid
 *
 * @return true if parsing succeeds and false if it fails
 */
private boolean validateAttributes(ScanningContext context) {
    // We only need to check if it's a non-framework file (and an XML file; skip .png's)
    if (!isFramework() && SdkUtils.endsWith(getFile().getName(), DOT_XML)) {
        ValidatingResourceParser parser = new ValidatingResourceParser(context, false);
        try {
            IAbstractFile file = getFile();
            return parser.parse(file.getOsLocation(), file.getContents());
        } catch (Exception e) {
            context.needsFullAapt();
        }

        return false;
    }

    return true;
}
 
Example #9
Source File: ResourceFolder.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
private ResourceFile createResourceFile(IAbstractFile file) {
    // check if that's a single or multi resource type folder. We have a special case
    // for ID generating resource types (layout/menu, and XML drawables, etc.).
    // MultiResourceFile handles the case when several resource types come from a single file
    // (values files).

    ResourceFile resFile;
    if (mType != ResourceFolderType.VALUES) {
        if (FolderTypeRelationship.isIdGeneratingFolderType(mType) &&
            SdkUtils.endsWithIgnoreCase(file.getName(), SdkConstants.DOT_XML)) {
            List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType);
            ResourceType primaryType = types.get(0);
            resFile = new IdGeneratingResourceFile(file, this, primaryType);
        } else {
            resFile = new SingleResourceFile(file, this);
        }
    } else {
        resFile = new MultiResourceFile(file, this, namespace);
    }
    return resFile;
}
 
Example #10
Source File: ResourceFolder.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Processes a file and adds it to its parent folder resource.
 *
 * @param file the underlying resource file.
 * @param kind the file change kind.
 * @param context a context object with state for the current update, such
 *            as a place to stash errors encountered
 * @return the {@link ResourceFile} that was created.
 */
public ResourceFile processFile(IAbstractFile file, ResourceDeltaKind kind,
        ScanningContext context) {
    // look for this file if it's already been created
    ResourceFile resFile = getFile(file, context);

    if (resFile == null) {
        if (kind != ResourceDeltaKind.REMOVED) {
            // create a ResourceFile for it.

            resFile = createResourceFile(file);
            resFile.load(context);

            // add it to the folder
            addFile(resFile);
        }
    } else {
        if (kind == ResourceDeltaKind.REMOVED) {
            removeFile(resFile, context);
        } else {
            resFile.update(context);
        }
    }

    return resFile;
}
 
Example #11
Source File: ResourceFolder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Processes a file and adds it to its parent folder resource.
 *
 * @param file the underlying resource file.
 * @param kind the file change kind.
 * @param context a context object with state for the current update, such
 *            as a place to stash errors encountered
 * @return the {@link ResourceFile} that was created.
 */
public ResourceFile processFile(IAbstractFile file, ResourceDeltaKind kind,
        ScanningContext context) {
    // look for this file if it's already been created
    ResourceFile resFile = getFile(file, context);

    if (resFile == null) {
        if (kind != ResourceDeltaKind.REMOVED) {
            // create a ResourceFile for it.

            resFile = createResourceFile(file);
            resFile.load(context);

            // add it to the folder
            addFile(resFile);
        }
    } else {
        if (kind == ResourceDeltaKind.REMOVED) {
            removeFile(resFile, context);
        } else {
            resFile.update(context);
        }
    }

    return resFile;
}
 
Example #12
Source File: ResourceFolder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ResourceFile} matching a {@link IAbstractFile} object.
 *
 * @param file The {@link IAbstractFile} object.
 * @param context a context object with state for the current update, such
 *            as a place to stash errors encountered
 * @return the {@link ResourceFile} or null if no match was found.
 */
private ResourceFile getFile(IAbstractFile file, ScanningContext context) {
    assert mFolder.equals(file.getParentFolder());

    if (mNames != null) {
        ResourceFile resFile = mNames.get(file.getName());
        if (resFile != null) {
            return resFile;
        }
    }

    // If the file actually exists, the resource folder  may not have been
    // scanned yet; add it lazily
    if (file.exists()) {
        ResourceFile resFile = createResourceFile(file);
        resFile.load(context);
        addFile(resFile);
        return resFile;
    }

    return null;
}
 
Example #13
Source File: SingleResourceFile.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
    super(file, folder);

    // we need to infer the type of the resource from the folder type.
    // This is easy since this is a single Resource file.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
    mType = types.get(0);

    // compute the resource name
    mResourceName = getResourceName(mType);

    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    if (qualifier == null) {
        mValue = new ResourceValue(mType, getResourceName(mType),
                file.getOsLocation(), isFramework());
    } else {
        mValue = new DensityBasedResourceValue(
                mType,
                getResourceName(mType),
                file.getOsLocation(),
                qualifier.getValue(),
                isFramework());
    }
}
 
Example #14
Source File: SingleResourceFile.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
    super(file, folder);

    // we need to infer the type of the resource from the folder type.
    // This is easy since this is a single Resource file.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
    mType = types.get(0);

    // compute the resource name
    mResourceName = getResourceName(mType);

    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    if (qualifier == null) {
        mValue = new ResourceValue(mType, getResourceName(mType),
                file.getOsLocation(), isFramework());
    } else {
        mValue = new DensityBasedResourceValue(
                mType,
                getResourceName(mType),
                file.getOsLocation(),
                qualifier.getValue(),
                isFramework());
    }
}
 
Example #15
Source File: SingleResourceFile.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the associated resource file to make sure the attribute references are valid
 *
 * @return true if parsing succeeds and false if it fails
 */
private boolean validateAttributes(ScanningContext context) {
    // We only need to check if it's a non-framework file (and an XML file; skip .png's)
    if (!isFramework() && SdkUtils.endsWith(getFile().getName(), DOT_XML)) {
        ValidatingResourceParser parser = new ValidatingResourceParser(context, false);
        try {
            IAbstractFile file = getFile();
            return parser.parse(file.getOsLocation(), file.getContents());
        } catch (Exception e) {
            context.needsFullAapt();
        }

        return false;
    }

    return true;
}
 
Example #16
Source File: ResourceFolder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private ResourceFile createResourceFile(IAbstractFile file) {
    // check if that's a single or multi resource type folder. For now we define this by
    // the number of possible resource type output by files in the folder.
    // We have a special case for layout/menu folders which can also generate IDs.
    // This does
    // not make the difference between several resource types from a single file or
    // the ability to have 2 files in the same folder generating 2 different types of
    // resource. The former is handled by MultiResourceFile properly while we don't
    // handle the latter. If we were to add this behavior we'd have to change this call.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType);

    ResourceFile resFile = null;
    if (types.size() == 1) {
        resFile = new SingleResourceFile(file, this);
    } else if (types.contains(ResourceType.LAYOUT)) {
        resFile = new IdGeneratingResourceFile(file, this, ResourceType.LAYOUT);
    } else if (types.contains(ResourceType.MENU)) {
        resFile = new IdGeneratingResourceFile(file, this, ResourceType.MENU);
    } else {
        resFile = new MultiResourceFile(file, this);
    }
    return resFile;
}
 
Example #17
Source File: ResourceFolder.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the {@link ResourceFile} matching a {@link IAbstractFile} object.
 *
 * @param file The {@link IAbstractFile} object.
 * @param context a context object with state for the current update, such
 *            as a place to stash errors encountered
 * @return the {@link ResourceFile} or null if no match was found.
 */
private ResourceFile getFile(IAbstractFile file, ScanningContext context) {
    assert mFolder.equals(file.getParentFolder());

    if (mNames != null) {
        ResourceFile resFile = mNames.get(file.getName());
        if (resFile != null) {
            return resFile;
        }
    }

    // If the file actually exists, the resource folder  may not have been
    // scanned yet; add it lazily
    if (file.exists()) {
        ResourceFile resFile = createResourceFile(file);
        resFile.load(context);
        addFile(resFile);
        return resFile;
    }

    return null;
}
 
Example #18
Source File: ResourceFolder.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ResourceFile} matching a {@link IAbstractFile} object.
 *
 * @param file The {@link IAbstractFile} object.
 * @param context a context object with state for the current update, such
 *            as a place to stash errors encountered
 * @return the {@link ResourceFile} or null if no match was found.
 */
private ResourceFile getFile(IAbstractFile file, ScanningContext context) {
    assert mFolder.equals(file.getParentFolder());

    if (mNames != null) {
        ResourceFile resFile = mNames.get(file.getName());
        if (resFile != null) {
            return resFile;
        }
    }

    // If the file actually exists, the resource folder  may not have been
    // scanned yet; add it lazily
    if (file.exists()) {
        ResourceFile resFile = createResourceFile(file);
        resFile.load(context);
        addFile(resFile);
        return resFile;
    }

    return null;
}
 
Example #19
Source File: ResourceFolder.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private ResourceFile createResourceFile(IAbstractFile file) {
    // check if that's a single or multi resource type folder. For now we define this by
    // the number of possible resource type output by files in the folder.
    // We have a special case for layout/menu folders which can also generate IDs.
    // This does
    // not make the difference between several resource types from a single file or
    // the ability to have 2 files in the same folder generating 2 different types of
    // resource. The former is handled by MultiResourceFile properly while we don't
    // handle the latter. If we were to add this behavior we'd have to change this call.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType);

    ResourceFile resFile = null;
    if (types.size() == 1) {
        resFile = new SingleResourceFile(file, this);
    } else if (types.contains(ResourceType.LAYOUT)) {
        resFile = new IdGeneratingResourceFile(file, this, ResourceType.LAYOUT);
    } else if (types.contains(ResourceType.MENU)) {
        resFile = new IdGeneratingResourceFile(file, this, ResourceType.MENU);
    } else {
        resFile = new MultiResourceFile(file, this);
    }
    return resFile;
}
 
Example #20
Source File: IdGeneratingResourceFile.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resource value associated with this whole file as a layout resource
 * @param file the file handler that represents this file
 * @param folder the folder this file is under
 * @return a resource value associated with this layout
 */
private ResourceValue getFileValue(IAbstractFile file, ResourceFolder folder) {
    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    ResourceValue value;
    if (!ResourceQualifier.isValid(qualifier)) {
        value =
                new ResourceValueImpl(
                        new ResourceReference(mFileType, mFileName, isFramework()),
                        file.getOsLocation());
    } else {
        value =
                new DensityBasedResourceValueImpl(
                        new ResourceReference(mFileType, mFileName, isFramework()),
                        file.getOsLocation(),
                        qualifier.getValue());
    }
    return value;
}
 
Example #21
Source File: ResourceFolder.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Processes a file and adds it to its parent folder resource.
 *
 * @param file the underlying resource file.
 * @param kind the file change kind.
 * @param context a context object with state for the current update, such
 *            as a place to stash errors encountered
 * @return the {@link ResourceFile} that was created.
 */
public ResourceFile processFile(IAbstractFile file, ResourceDeltaKind kind,
        ScanningContext context) {
    // look for this file if it's already been created
    ResourceFile resFile = getFile(file, context);

    if (resFile == null) {
        if (kind != ResourceDeltaKind.REMOVED) {
            // create a ResourceFile for it.

            resFile = createResourceFile(file);
            resFile.load(context);

            // add it to the folder
            addFile(resFile);
        }
    } else {
        if (kind == ResourceDeltaKind.REMOVED) {
            removeFile(resFile, context);
        } else {
            resFile.update(context);
        }
    }

    return resFile;
}
 
Example #22
Source File: AndroidManifestParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static ManifestData parse(IAbstractFolder projectFolder)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    IAbstractFile manifestFile = AndroidManifest.getManifest(projectFolder);
    if (manifestFile == null) {
        throw new FileNotFoundException();
    }

    return parse(manifestFile, true, null);
}
 
Example #23
Source File: ProjectProperties.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a project properties file.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 * @return true if success.
 */
public static boolean delete(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            return propFile.delete();
        }
    }

    return false;
}
 
Example #24
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that the repository has been initialized again after a call to
 * {@link ResourceRepository#clear()}
 *
 * @return true if the repository was just re-initialized.
 */
public synchronized boolean ensureInitialized() {
    if (mCleared && !mInitializing) {
        ScanningContext context = new ScanningContext(this);
        mInitializing = true;

        IAbstractResource[] resources = mResourceFolder.listMembers();

        for (IAbstractResource res : resources) {
            if (res instanceof IAbstractFolder) {
                IAbstractFolder folder = (IAbstractFolder)res;
                ResourceFolder resFolder = processFolder(folder);

                if (resFolder != null) {
                    // now we process the content of the folder
                    IAbstractResource[] files = folder.listMembers();

                    for (IAbstractResource fileRes : files) {
                        if (fileRes instanceof IAbstractFile) {
                            IAbstractFile file = (IAbstractFile)fileRes;

                            resFolder.processFile(file, ResourceDeltaKind.ADDED, context);
                        }
                    }
                }
            }
        }

        mInitializing = false;
        mCleared = false;
        return true;
    }

    return false;
}
 
Example #25
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value of the targetSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the integer value or -1 if not set.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getTargetSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_TARGET_SDK_VERSION);
    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #26
Source File: IdGeneratingResourceFile.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public IdGeneratingResourceFile(IAbstractFile file, ResourceFolder folder, ResourceType type) {
    super(file, folder);

    mFileType = type;

    // Set up our resource types
    mResourceTypeList = EnumSet.of(mFileType, ResourceType.ID);

    // compute the resource name
    mFileName = getFileName(type);

    // Get the resource value of this file as a whole layout
    mFileValue = getFileValue(file, folder);
}
 
Example #27
Source File: IdGeneratingResourceFile.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public IdGeneratingResourceFile(IAbstractFile file, ResourceFolder folder, ResourceType type) {
    super(file, folder);

    mFileType = type;

    // Set up our resource types
    mResourceTypeList = EnumSet.of(mFileType, ResourceType.ID);

    // compute the resource name
    mFileName = getFileName(type);

    // Get the resource value of this file as a whole layout
    mFileValue = getFileValue(file, folder);
}
 
Example #28
Source File: ProjectProperties.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Loads a project properties file and return a {@link ProjectProperties} object
 * containing the properties.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 */
public static ProjectProperties load(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                return new ProjectProperties(projectFolder, map, type);
            }
        }
    }
    return null;
}
 
Example #29
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the application icon  for a given manifest.
 * @param manifestFile the manifest to parse.
 * @return the icon or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getApplicationIcon(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    return getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_ICON);
}
 
Example #30
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value of the versionCode attribute or -1 if the value is not set.
 * @param manifestFile the manifest file to read the attribute from.
 * @return the integer value or -1 if not set.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static int getVersionCode(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_VERSIONCODE);

    try {
        return Integer.parseInt(result);
    } catch (NumberFormatException e) {
        return -1;
    }
}