Search in sources :

Example 1 with License

use of com.mikepenz.aboutlibraries.entity.License in project AboutLibraries by mikepenz.

the class Libs method genLicense.

/**
 * @param licenseName
 * @return
 */
private License genLicense(Context ctx, String licenseName) {
    licenseName = licenseName.replace("-", "_");
    try {
        License lic = new License();
        lic.setDefinedName(licenseName);
        lic.setLicenseName(getStringResourceByName(ctx, "license_" + licenseName + "_licenseName"));
        lic.setLicenseWebsite(getStringResourceByName(ctx, "license_" + licenseName + "_licenseWebsite"));
        lic.setLicenseShortDescription(getStringResourceByName(ctx, "license_" + licenseName + "_licenseShortDescription"));
        lic.setLicenseDescription(getStringResourceByName(ctx, "license_" + licenseName + "_licenseDescription"));
        return lic;
    } catch (Exception ex) {
        Log.e("aboutlibraries", "Failed to generateLicense from file: " + ex.toString());
        return null;
    }
}
Also used : License(com.mikepenz.aboutlibraries.entity.License)

Example 2 with License

use of com.mikepenz.aboutlibraries.entity.License in project AboutLibraries by mikepenz.

the class Libs method modifyLibraries.

/**
 * @param modifications
 */
public void modifyLibraries(HashMap<String, HashMap<String, String>> modifications) {
    if (modifications != null) {
        for (Map.Entry<String, HashMap<String, String>> entry : modifications.entrySet()) {
            ArrayList<Library> foundLibs = findInExternalLibrary(entry.getKey(), true, 1);
            if (foundLibs == null || foundLibs.size() == 0) {
                foundLibs = findInInternalLibrary(entry.getKey(), true, 1);
            }
            if (foundLibs != null && foundLibs.size() == 1) {
                Library lib = foundLibs.get(0);
                for (Map.Entry<String, String> modification : entry.getValue().entrySet()) {
                    String key = modification.getKey().toUpperCase();
                    String value = modification.getValue();
                    if (key.equals(LibraryFields.AUTHOR_NAME.name())) {
                        lib.setAuthor(value);
                    } else if (key.equals(LibraryFields.AUTHOR_WEBSITE.name())) {
                        lib.setAuthorWebsite(value);
                    } else if (key.equals(LibraryFields.LIBRARY_NAME.name())) {
                        lib.setLibraryName(value);
                    } else if (key.equals(LibraryFields.LIBRARY_DESCRIPTION.name())) {
                        lib.setLibraryDescription(value);
                    } else if (key.equals(LibraryFields.LIBRARY_VERSION.name())) {
                        lib.setLibraryVersion(value);
                    } else if (key.equals(LibraryFields.LIBRARY_WEBSITE.name())) {
                        lib.setLibraryWebsite(value);
                    } else if (key.equals(LibraryFields.LIBRARY_OPEN_SOURCE.name())) {
                        lib.setOpenSource(Boolean.parseBoolean(value));
                    } else if (key.equals(LibraryFields.LIBRARY_REPOSITORY_LINK.name())) {
                        lib.setRepositoryLink(value);
                    } else if (key.equals(LibraryFields.LIBRARY_CLASSPATH.name())) {
                        // note this can be set but won't probably work for autodetect
                        lib.setClassPath(value);
                    } else if (key.equals(LibraryFields.LICENSE_NAME.name())) {
                        if (lib.getLicense() == null) {
                            lib.setLicense(new License());
                        }
                        lib.getLicense().setLicenseName(value);
                    } else if (key.equals(LibraryFields.LICENSE_SHORT_DESCRIPTION.name())) {
                        if (lib.getLicense() == null) {
                            lib.setLicense(new License());
                        }
                        lib.getLicense().setLicenseShortDescription(value);
                    } else if (key.equals(LibraryFields.LICENSE_DESCRIPTION.name())) {
                        if (lib.getLicense() == null) {
                            lib.setLicense(new License());
                        }
                        lib.getLicense().setLicenseDescription(value);
                    } else if (key.equals(LibraryFields.LICENSE_WEBSITE.name())) {
                        if (lib.getLicense() == null) {
                            lib.setLicense(new License());
                        }
                        lib.getLicense().setLicenseWebsite(value);
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) License(com.mikepenz.aboutlibraries.entity.License) Library(com.mikepenz.aboutlibraries.entity.Library) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with License

use of com.mikepenz.aboutlibraries.entity.License in project AboutLibraries by mikepenz.

the class Libs method init.

/**
     * init method
     *
     * @param fields
     */
private void init(Context ctx, String[] fields) {
    ArrayList<String> foundLicenseIdentifiers = new ArrayList<>();
    ArrayList<String> foundInternalLibraryIdentifiers = new ArrayList<>();
    ArrayList<String> foundExternalLibraryIdentifiers = new ArrayList<>();
    if (fields != null) {
        for (String field : fields) {
            if (field.startsWith(DEFINE_LICENSE)) {
                foundLicenseIdentifiers.add(field.replace(DEFINE_LICENSE, ""));
            } else if (field.startsWith(DEFINE_INT)) {
                foundInternalLibraryIdentifiers.add(field.replace(DEFINE_INT, ""));
            } else if (field.startsWith(DEFINE_EXT)) {
                foundExternalLibraryIdentifiers.add(field.replace(DEFINE_EXT, ""));
            }
        }
    }
    //add licenses
    for (String licenseIdentifier : foundLicenseIdentifiers) {
        License license = genLicense(ctx, licenseIdentifier);
        if (license != null) {
            licenses.add(license);
        }
    }
    //add internal libs
    for (String internalIdentifier : foundInternalLibraryIdentifiers) {
        Library library = genLibrary(ctx, internalIdentifier);
        if (library != null) {
            library.setInternal(true);
            internLibraries.add(library);
        }
    }
    //add external libs
    for (String externalIdentifier : foundExternalLibraryIdentifiers) {
        Library library = genLibrary(ctx, externalIdentifier);
        if (library != null) {
            library.setInternal(false);
            externLibraries.add(library);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) License(com.mikepenz.aboutlibraries.entity.License) Library(com.mikepenz.aboutlibraries.entity.Library)

Example 4 with License

use of com.mikepenz.aboutlibraries.entity.License in project AboutLibraries by mikepenz.

the class Libs method genLibrary.

/**
 * @param libraryName
 * @return
 */
private Library genLibrary(Context ctx, String libraryName) {
    libraryName = libraryName.replace("-", "_");
    try {
        Library lib = new Library();
        // Get custom vars to insert into defined areas
        HashMap<String, String> customVariables = getCustomVariables(ctx, libraryName);
        lib.setDefinedName(libraryName);
        lib.setAuthor(getStringResourceByName(ctx, "library_" + libraryName + "_author"));
        lib.setAuthorWebsite(getStringResourceByName(ctx, "library_" + libraryName + "_authorWebsite"));
        lib.setLibraryName(getStringResourceByName(ctx, "library_" + libraryName + "_libraryName"));
        lib.setLibraryDescription(insertVariables(getStringResourceByName(ctx, "library_" + libraryName + "_libraryDescription"), customVariables));
        lib.setLibraryVersion(getStringResourceByName(ctx, "library_" + libraryName + "_libraryVersion"));
        lib.setLibraryWebsite(getStringResourceByName(ctx, "library_" + libraryName + "_libraryWebsite"));
        String licenseId = getStringResourceByName(ctx, "library_" + libraryName + "_licenseId");
        if (TextUtils.isEmpty(licenseId)) {
            License license = new License();
            license.setLicenseName(getStringResourceByName(ctx, "library_" + libraryName + "_licenseVersion"));
            license.setLicenseWebsite(getStringResourceByName(ctx, "library_" + libraryName + "_licenseLink"));
            license.setLicenseShortDescription(insertVariables(getStringResourceByName(ctx, "library_" + libraryName + "_licenseContent"), customVariables));
            lib.setLicense(license);
        } else {
            License license = getLicense(licenseId);
            if (license != null) {
                license = license.copy();
                license.setLicenseShortDescription(insertVariables(license.getLicenseShortDescription(), customVariables));
                license.setLicenseDescription(insertVariables(license.getLicenseDescription(), customVariables));
                lib.setLicense(license);
            }
        }
        lib.setOpenSource(Boolean.valueOf(getStringResourceByName(ctx, "library_" + libraryName + "_isOpenSource")));
        lib.setRepositoryLink(getStringResourceByName(ctx, "library_" + libraryName + "_repositoryLink"));
        lib.setClassPath(getStringResourceByName(ctx, "library_" + libraryName + "_classPath"));
        if (TextUtils.isEmpty(lib.getLibraryName()) && TextUtils.isEmpty(lib.getLibraryDescription())) {
            return null;
        }
        return lib;
    } catch (Exception ex) {
        Log.e("aboutlibraries", "Failed to generateLibrary from file: " + ex.toString());
        return null;
    }
}
Also used : License(com.mikepenz.aboutlibraries.entity.License) Library(com.mikepenz.aboutlibraries.entity.Library)

Aggregations

License (com.mikepenz.aboutlibraries.entity.License)4 Library (com.mikepenz.aboutlibraries.entity.Library)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1