Search in sources :

Example 1 with PortletInfo

use of com.liferay.ide.portlet.core.model.PortletInfo in project liferay-ide by liferay.

the class CreatePortletResourceBundleActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    ITextEditor editor = context.part().adapt(ITextEditor.class);
    editor.doSave(new NullProgressMonitor());
    List<IFile> missingRBFiles = new ArrayList<>();
    Portlet portlet = (Portlet) getModelElement();
    IProject project = portlet.adapt(IProject.class);
    Value<Path> resourceBundle = portlet.getResourceBundle();
    String text = resourceBundle.text();
    String defaultRBFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION);
    int index = text.lastIndexOf(".");
    String packageName = "";
    if (index == -1) {
        index = text.length();
        packageName = "";
    } else {
        packageName = text.substring(0, index);
    }
    IFolder rbSourceFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
    IPath entryPath = rbSourceFolder.getLocation();
    PortletInfo portletInfo = portlet.getPortletInfo();
    StringBuilder rbFileBuffer = _buildDefaultRBContent(portletInfo);
    if (!getFileFromClasspath(project, defaultRBFileName)) {
        IFile drbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
        missingRBFiles.add(drbFile);
    }
    // Create bundles for each supported locale for which the resource bundle is
    // missing
    List<SupportedLocales> supportedLocales = portlet.getSupportedLocales();
    for (SupportedLocales iSupportedLocale : supportedLocales) {
        if (iSupportedLocale != null) {
            String locale = PortletUtil.localeString(iSupportedLocale.getSupportedLocale().text());
            String localizedIOFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION, locale);
            if (!getFileFromClasspath(project, localizedIOFileName)) {
                IFile rbFile = wroot.getFileForLocation(entryPath.append(localizedIOFileName));
                missingRBFiles.add(rbFile);
            }
        }
    }
    createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
    setEnabled(false);
    Portlet p = getModelElement().nearest(Portlet.class);
    for (SupportedLocales sl : p.getSupportedLocales()) {
        Value<String> locale = sl.getSupportedLocale();
        locale.service(LocaleBundleValidationService.class).forceRefresh();
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) Portlet(com.liferay.ide.portlet.core.model.Portlet) IPath(org.eclipse.core.runtime.IPath) SupportedLocales(com.liferay.ide.portlet.core.model.SupportedLocales) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) LocaleBundleValidationService(com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService) PortletInfo(com.liferay.ide.portlet.core.model.PortletInfo) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with PortletInfo

use of com.liferay.ide.portlet.core.model.PortletInfo in project liferay-ide by liferay.

the class PortletXmlTests method portletXmlRead.

@Test
public void portletXmlRead() throws Exception {
    final PortletApp portletApp = portletApp(PORTLET_XML);
    assertNotNull(portletApp);
    final ElementList<Portlet> portlets = portletApp.getPortlets();
    assertNotNull(portlets);
    assertEquals(1, portlets.size());
    final Portlet portlet = portlets.get(0);
    assertNotNull(portlet);
    assertEquals("1", portlet.getPortletName().content());
    assertEquals("Sample JSP", portlet.getDisplayName().content());
    assertEquals("com.liferay.samplejsp.portlet.JSPPortlet", portlet.getPortletClass().text());
    final Param param = portlet.getInitParams().get(0);
    assertNotNull(param);
    assertEquals("view-jsp", param.getName().content());
    assertEquals("/view.jsp", param.getValue().content());
    assertEquals(new Integer(0), portlet.getExpirationCache().content());
    final Supports supports = portlet.getSupports();
    assertNotNull(supports);
    assertEquals("text/html", supports.getMimeType().content());
    final PortletInfo info = portlet.getPortletInfo();
    assertEquals("Sample JSP", info.getTitle().content());
    assertEquals("Sample JSP", info.getShortTitle().content());
    assertEquals("Sample JSP", info.getKeywords().content());
    final ElementList<SecurityRoleRef> roles = portlet.getSecurityRoleRefs();
    assertEquals(4, roles.size());
    final SecurityRoleRef role = roles.get(1);
    assertNotNull(role);
    assertEquals("guest", role.getRoleName().content());
}
Also used : Portlet(com.liferay.ide.portlet.core.model.Portlet) Supports(com.liferay.ide.portlet.core.model.Supports) Param(com.liferay.ide.portlet.core.model.Param) PortletInfo(com.liferay.ide.portlet.core.model.PortletInfo) SecurityRoleRef(com.liferay.ide.portlet.core.model.SecurityRoleRef) PortletApp(com.liferay.ide.portlet.core.model.PortletApp) Test(org.junit.Test)

Aggregations

Portlet (com.liferay.ide.portlet.core.model.Portlet)2 PortletInfo (com.liferay.ide.portlet.core.model.PortletInfo)2 Param (com.liferay.ide.portlet.core.model.Param)1 PortletApp (com.liferay.ide.portlet.core.model.PortletApp)1 SecurityRoleRef (com.liferay.ide.portlet.core.model.SecurityRoleRef)1 SupportedLocales (com.liferay.ide.portlet.core.model.SupportedLocales)1 Supports (com.liferay.ide.portlet.core.model.Supports)1 LocaleBundleValidationService (com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.sapphire.modeling.Path)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1 Test (org.junit.Test)1