Search in sources :

Example 1 with AppPluginSpecification

use of org.openecard.addon.manifest.AppPluginSpecification in project open-ecard by ecsec.

the class AndroidMarshaller method parseAppPluginSpecification.

private AppPluginSpecification parseAppPluginSpecification(XmlPullParser parser) throws XmlPullParserException, IOException {
    AppPluginSpecification appPluginActionDescription = new AppPluginSpecification();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("ClassName")) {
                appPluginActionDescription.setClassName(parser.nextText());
            } else if (parser.getName().equals("LocalizedName")) {
                LocalizedString localizedString = new LocalizedString();
                localizedString.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                localizedString.setValue(parser.nextText());
                appPluginActionDescription.getLocalizedName().add(localizedString);
            } else if (parser.getName().equals("LocalizedDescription")) {
                LocalizedString localizedString = new LocalizedString();
                localizedString.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                localizedString.setValue(parser.nextText());
                appPluginActionDescription.getLocalizedDescription().add(localizedString);
            } else if (parser.getName().equals("ResourceName")) {
                appPluginActionDescription.setResourceName(parser.nextText());
            } else if (parser.getName().equals("ConfigDescription")) {
                appPluginActionDescription.setConfigDescription(parseConfigDescription(parser));
            } else {
                throw new IllegalArgumentException("Unexpected Tag found: " + parser.getName());
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("AppPluginSpecification")));
    return appPluginActionDescription;
}
Also used : AppPluginSpecification(org.openecard.addon.manifest.AppPluginSpecification) LocalizedString(org.openecard.addon.manifest.LocalizedString)

Example 2 with AppPluginSpecification

use of org.openecard.addon.manifest.AppPluginSpecification in project open-ecard by ecsec.

the class ManagementDialog method createAddonPaneFromAddonSpec.

private void createAddonPaneFromAddonSpec(AddonSpecification desc, AddonSelectionModel model, boolean coreAddon) {
    String description = desc.getLocalizedDescription(LANGUAGE_CODE);
    String name = desc.getLocalizedName(LANGUAGE_CODE);
    Image logo;
    if (coreAddon) {
        logo = loadLogo(null, desc.getLogo());
    } else {
        try {
            ClassLoader loader = manager.getRegistry().downloadAddon(desc);
            logo = loadLogo(loader, "META-INF/" + desc.getLogo());
        } catch (AddonException ex) {
            logger.error("Failed to load logo from Add-on bundle.");
            logo = null;
        }
    }
    // setup about panel but just if we don't have a core addon
    String about = desc.getAbout(LANGUAGE_CODE);
    String licenseText = desc.getLicenseText(LANGUAGE_CODE);
    AboutPanel aboutPanel = null;
    if ((!about.equals("") || !licenseText.equals("")) && !coreAddon) {
        aboutPanel = new AboutPanel(desc, coreAddon, manager, this);
    }
    // inital setup of settings panel if the addon has general settings in the non protocol/action specific
    // declaration
    DefaultSettingsPanel settingsPanel = null;
    ArrayList<DefaultSettingsGroup> settingsGroups = new ArrayList<>();
    AddonProperties addonProps = new AddonProperties(desc);
    Settings settings = SettingsFactory.getInstance(addonProps);
    if (desc.getConfigDescription() != null && !desc.getConfigDescription().getEntries().isEmpty()) {
        DefaultSettingsGroup group = new DefaultSettingsGroup(lang.translationForKey("addon.settings.general"), settings, desc.getConfigDescription().getEntries());
        settingsGroups.add(group);
    }
    // AppExtensionActions
    if (!desc.getApplicationActions().isEmpty()) {
        for (AppExtensionSpecification appExtSpec : desc.getApplicationActions()) {
            if (appExtSpec.getConfigDescription() != null && !appExtSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(appExtSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, appExtSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // Binding actions
    if (!desc.getBindingActions().isEmpty()) {
        for (AppPluginSpecification appPluginSpec : desc.getBindingActions()) {
            if (appPluginSpec.getConfigDescription() != null && !appPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(appPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, appPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // IFD Actions
    if (!desc.getIfdActions().isEmpty()) {
        for (ProtocolPluginSpecification protPluginSpec : desc.getIfdActions()) {
            if (protPluginSpec.getConfigDescription() != null && !protPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(protPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, protPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // SAL Actions
    if (!desc.getSalActions().isEmpty()) {
        for (ProtocolPluginSpecification protPluginSpec : desc.getSalActions()) {
            if (protPluginSpec.getConfigDescription() != null && !protPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(protPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, protPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    if (!settingsGroups.isEmpty()) {
        settingsPanel = new DefaultSettingsPanel(settingsGroups.toArray(new DefaultSettingsGroup[settingsGroups.size()]));
    }
    // create the actions panel
    ActionPanel actionPanel = null;
    if (!desc.getApplicationActions().isEmpty()) {
        actionPanel = new ActionPanel();
        for (AppExtensionSpecification appExtSpec : desc.getApplicationActions()) {
            ActionEntryPanel entry = new ActionEntryPanel(desc, appExtSpec, manager);
            actionPanel.addActionEntry(entry);
        }
    }
    AddonPanel nextPanel = null;
    // check whether to use a tabbed pane or not
    if (actionPanel != null && settingsPanel == null && aboutPanel == null) {
        nextPanel = new AddonPanel(actionPanel, name, description, logo);
    } else if (actionPanel == null && settingsPanel != null && aboutPanel == null) {
        nextPanel = new AddonPanel(settingsPanel, name, description, logo);
    } else if (actionPanel == null && settingsPanel == null && aboutPanel != null) {
        nextPanel = new AddonPanel(aboutPanel, name, description, logo);
    } else if (actionPanel != null || settingsPanel != null || aboutPanel != null) {
        nextPanel = new AddonPanel(actionPanel, settingsPanel, aboutPanel, name, description, logo);
    }
    if (nextPanel != null) {
        model.addElement(name, nextPanel);
    }
}
Also used : AddonProperties(org.openecard.addon.AddonProperties) ArrayList(java.util.ArrayList) Image(java.awt.Image) DefaultSettingsPanel(org.openecard.richclient.gui.manage.addon.DefaultSettingsPanel) DefaultSettingsGroup(org.openecard.richclient.gui.manage.addon.DefaultSettingsGroup) AppPluginSpecification(org.openecard.addon.manifest.AppPluginSpecification) AddonException(org.openecard.addon.AddonException) AppExtensionSpecification(org.openecard.addon.manifest.AppExtensionSpecification) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Example 3 with AppPluginSpecification

use of org.openecard.addon.manifest.AppPluginSpecification in project open-ecard by ecsec.

the class AddonManager method getAppPluginAction.

/**
 * Get a specific AppPluginAction.
 *
 * @param addonSpec {@link AddonSpecification} which contains the description of the {@link AppPluginAction}.
 * @param resourceName The {@link AppPluginSpecification#resourceName} to identify the @{@link AppPluginAction} to
 * return.
 * @return A AppPluginAction which corresponds to the {@link AddonSpecification} and the {@code resourceName}. If no
 * such AppPluginAction exists NULL is returned.
 */
public AppPluginAction getAppPluginAction(@Nonnull AddonSpecification addonSpec, @Nonnull String resourceName) {
    AppPluginAction appPluginAction = cache.getAppPluginAction(addonSpec, resourceName);
    if (appPluginAction != null) {
        // AppExtensionAction cached so return it
        return appPluginAction;
    }
    AppPluginSpecification protoSpec = addonSpec.searchByResourceName(resourceName);
    if (protoSpec == null) {
        LOG.error("Plugin for resource {} does not exist in Add-on {}.", resourceName, addonSpec.getId());
    } else {
        String className = protoSpec.getClassName();
        try {
            ClassLoader cl = registry.downloadAddon(addonSpec);
            AppPluginActionProxy protoFactory = new AppPluginActionProxy(className, cl);
            Context aCtx = createContext(addonSpec);
            protoFactory.init(aCtx);
            cache.addAppPluginAction(addonSpec, resourceName, protoFactory);
            return protoFactory;
        } catch (ActionInitializationException e) {
            LOG.error("Initialization of AppPluginAction failed", e);
        } catch (AddonException ex) {
            LOG.error("Failed to download Add-on.", ex);
        }
    }
    return null;
}
Also used : AppPluginSpecification(org.openecard.addon.manifest.AppPluginSpecification) AppPluginActionProxy(org.openecard.addon.bind.AppPluginActionProxy) AppPluginAction(org.openecard.addon.bind.AppPluginAction)

Aggregations

AppPluginSpecification (org.openecard.addon.manifest.AppPluginSpecification)3 Image (java.awt.Image)1 ArrayList (java.util.ArrayList)1 AddonException (org.openecard.addon.AddonException)1 AddonProperties (org.openecard.addon.AddonProperties)1 AppPluginAction (org.openecard.addon.bind.AppPluginAction)1 AppPluginActionProxy (org.openecard.addon.bind.AppPluginActionProxy)1 AppExtensionSpecification (org.openecard.addon.manifest.AppExtensionSpecification)1 LocalizedString (org.openecard.addon.manifest.LocalizedString)1 ProtocolPluginSpecification (org.openecard.addon.manifest.ProtocolPluginSpecification)1 DefaultSettingsGroup (org.openecard.richclient.gui.manage.addon.DefaultSettingsGroup)1 DefaultSettingsPanel (org.openecard.richclient.gui.manage.addon.DefaultSettingsPanel)1