This recipe will guide you through the process of modifying the default category of an existing gadget.
Follow these to change the category of a gadget:
portal/WEB-INF/conf/portal/application-registry-configuration.xml
and manually add the new category and a definition of the application for the created gadget. Here is an example that adds the Skype Talk gadget definition in the Application Registry Service:<object-param> <name>GadgetsMine</name> <description>GadgetsMine</description> <object type="org.exoplatform.application.registry.ApplicationCategory"> <field name="name"> <string>GadgetsMine</string> </field> <field name="displayName"> <string>GadgetsMine</string> </field> <field name="description"> <string>GadgetsMine</string> </field> <field name="accessPermissions"> <collection type="java.util.ArrayList" item-type="java.lang.String"> <value> <string>*:/platform/users</string> </value> </collection> </field> <field name="applications"> <collection type="java.util.ArrayList"> <value> <object type="org.exoplatform.application.registry.Application"> <field name="categoryName"> <string>GadgetsMine</string> </field> <field name="applicationName"> <string>SkypeTalk</string> </field> <field name="displayName"> <string>Skype Talk</string> </field> <field name="description"> <string>Skype Talk Gadget, easily manage and track your daily to-do list.</string> </field> <field name="type"> <string>gadget</string> </field> <field name="contentId"> <string>SkypeTalk</string> </field> <field name="accessPermissions"> <collection type="java.util.ArrayList" item-type="java.lang.String"> <value> <string>*:/platform/users</string> </value> </collection> </field> </object> </value> </collection> </field> </object> </object-param>
The categories defined in the Application Registry Service configuration are created only when you start GateIn for the first time, and when the JCR repository is empty. Pay attention to this feature, because if the repository is just created, you can only modify the categories by using the API. Here is an example of code that modifies a category with an API:
import org.exoplatform.application.registry.Application; import org.exoplatform.application.registry.ApplicationCategory; import org.exoplatform.application.registry.ApplicationRegistryService; ... PortalRequestContext context = (PortalRequestContext) WebuiRequestContext.getCurrentInstance(); ExoContainer pcontainer = context.getApplication() .getApplicationServiceContainer(); ApplicationRegistryService applicationRegistryService = (ApplicationRegistryService) pcontainer .getComponentInstanceOfType(ApplicationRegistryService.class); try { if (applicationRegistryService .getApplication("GadgetsMine/SkypeTalk") == null) { ApplicationCategory applicationCategory = new ApplicationCategory(); applicationCategory.setName("GadgetsMine"); applicationCategory.setDisplayName("GadgetsMine"); Application application = applicationRegistryService .getApplication("Gadgets/SkypeTalk"); applicationRegistryService .save(applicationCategory, application); } } catch (Exception e) { e.printStackTrace(); }
This code can be put in a new WEBUI component of the web application or in a simple servlet filter. For WEBUI, see Chapter 7, Developing Using Components API for more details.
When you click on the
Import Applications button of the Application Registry, the default category for the gadgets is applied, so all gadgets that are still not installed, usually those inside an application and deployed, will take that category. It's the code in the org.exoplatform.application.registry.impl.ApplicationRegistryServiceImpl
class that is executed:
public void importExoGadgets() throws Exception { ContentRegistry registry = getContentRegistry(); // ExoContainer container = ExoContainerContext.getCurrentContainer(); GadgetRegistryService gadgetService = (GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class); List<Gadget> eXoGadgets = gadgetService.getAllGadgets(); // if (eXoGadgets != null) { ArrayList<String> permissions = new ArrayList<String>(); permissions.add(UserACL.EVERYONE); String categoryName = "Gadgets"; // CategoryDefinition category = registry.getCategory(categoryName); if (category == null) { category = registry.createCategory(categoryName);
18.117.231.15