Search in sources :

Example 21 with ILiferayPortal

use of com.liferay.ide.core.ILiferayPortal in project liferay-ide by liferay.

the class CustomJspPossibleValuesService method compute.

@Override
protected void compute(final Set<String> values) {
    if (_possibleValues == null) {
        IProject project = project();
        ILiferayProject liferayProject = LiferayCore.create(project);
        if (liferayProject != null) {
            ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
            if (portal != null) {
                _portalDir = new Path(portal.getAppServerPortalDir().toPortableString());
                if (_portalDir != null) {
                    File portalDirFile = _portalDir.toFile();
                    File htmlDirFile = new File(portalDirFile, "html");
                    List<File> fileValues = new LinkedList<>();
                    if (FileUtil.exists(htmlDirFile)) {
                        _findJSPFiles(new File[] { htmlDirFile }, fileValues);
                    } else {
                        File[] files = portalDirFile.listFiles(_jspfilter);
                        _findJSPFiles(files, fileValues);
                    }
                    _possibleValues = fileValues.toArray(new File[0]);
                }
            }
        }
    }
    if (_possibleValues != null) {
        for (File file : _possibleValues) {
            values.add(new Path(file.getAbsolutePath()).makeRelativeTo(_portalDir).toPortableString());
        }
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList)

Example 22 with ILiferayPortal

use of com.liferay.ide.core.ILiferayPortal in project liferay-ide by liferay.

the class NewPortletClassDataModelProvider method getEntryCategories.

protected Properties getEntryCategories() {
    // removed if not null return directly, because it won't update when switch
    // projects of different portal versions
    ILiferayProject liferayProject = LiferayCore.create(getProject());
    if (liferayProject == null) {
        try {
            liferayProject = LiferayCore.create(getRuntime());
        } catch (CoreException ce) {
            PortletCore.logError(ce);
        }
    }
    ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
    if (portal != null) {
        return portal.getPortletEntryCategories();
    } else {
        return null;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 23 with ILiferayPortal

use of com.liferay.ide.core.ILiferayPortal in project liferay-ide by liferay.

the class NewPortletClassDataModelProvider method getDefaultProperty.

@Override
public Object getDefaultProperty(String propertyName) {
    if (SUPERCLASS.equals(propertyName)) {
        return QUALIFIED_MVC_PORTLET;
    } else if (CONSTRUCTOR.equals(propertyName)) {
        return false;
    } else if (INIT_OVERRIDE.equals(propertyName) || DOVIEW_OVERRIDE.equals(propertyName)) {
        return true;
    } else if (DESTROY_OVERRIDE.equals(propertyName)) {
        return false;
    } else if (JAVA_PACKAGE.equals(propertyName)) {
        return "com.test";
    } else if (CLASS_NAME.equals(propertyName)) {
        return "NewPortlet";
    } else if (PORTLET_NAME.equals(propertyName) || LIFERAY_PORTLET_NAME.equals(propertyName)) {
        return getPortletNameFromClassName(getStringProperty(CLASS_NAME));
    } else if (DISPLAY_NAME.equals(propertyName) || TITLE.equals(propertyName) || SHORT_TITLE.equals(propertyName)) {
        return _getDisplayNameFromPortletName(getStringProperty(PORTLET_NAME));
    } else if (KEYWORDS.equals(propertyName)) {
        return StringPool.EMPTY;
    } else if (INIT_PARAMS.equals(propertyName)) {
        return getInitParams();
    } else if (VIEW_MODE.equals(propertyName)) {
        return true;
    } else if (CREATE_JSPS.equals(propertyName)) {
        return true;
    } else if (CREATE_JSPS_FOLDER.equals(propertyName)) {
        if (getBooleanProperty(CREATE_NEW_PORTLET_CLASS)) {
            String tempStr = getProperty(CLASS_NAME).toString();
            String property = tempStr.toLowerCase();
            return "/html/" + property.replaceAll(_PORTLET_SUFFIX_PATTERN, "");
        } else {
            String tempStr = getProperty(PORTLET_NAME).toString();
            String property = tempStr.toLowerCase();
            return "/html/" + property.replaceAll(_PORTLET_SUFFIX_PATTERN, "");
        }
    } else if (ICON_FILE.equals(propertyName)) {
        return "/icon.png";
    } else if (CREATE_RESOURCE_BUNDLE_FILE.equals(propertyName)) {
        return false;
    } else if (CREATE_RESOURCE_BUNDLE_FILE_PATH.equals(propertyName)) {
        return "content/Language.properties";
    } else if (ALLOW_MULTIPLE.equals(propertyName)) {
        return false;
    } else if (CSS_FILE.equals(propertyName)) {
        return "/css/main.css";
    } else if (JAVASCRIPT_FILE.equals(propertyName)) {
        return "/js/main.js";
    } else if (CSS_CLASS_WRAPPER.equals(propertyName)) {
        String property = getProperty(PORTLET_NAME).toString();
        return property.toLowerCase() + "-portlet";
    } else if (ID.equals(propertyName)) {
        return getProperty(PORTLET_NAME);
    } else if (CATEGORY.equals(propertyName)) {
        return "category.sample";
    } else if (ENTRY_CATEGORY.equals(propertyName)) {
        return "category.my";
    } else if (ENTRY_WEIGHT.equals(propertyName)) {
        return "1.5";
    } else if (ENTRY_CLASS_NAME.equals(propertyName)) {
        return getStringProperty(CLASS_NAME) + "ControlPanelEntry";
    } else if (SHOW_NEW_CLASS_OPTION.equals(propertyName)) {
        return true;
    } else if (CREATE_NEW_PORTLET_CLASS.equals(propertyName)) {
        return true;
    } else if (USE_DEFAULT_PORTLET_CLASS.equals(propertyName)) {
        return false;
    } else if (QUALIFIED_CLASS_NAME.equals(propertyName)) {
        if (getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) {
            return QUALIFIED_MVC_PORTLET;
        }
    } else if (PROJECT_NAME.equals(propertyName) && (initialProject != null)) {
        return initialProject.getName();
    } else if (INIT_PARAMETER_NAME.equals(propertyName)) {
        String initParameterName = "template";
        ILiferayProject liferayProject = LiferayCore.create(getProject());
        ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
        if (portal != null) {
            String version = portal.getVersion();
            if (version != null) {
                Version portalVersion = Version.parseVersion(version);
                if (CoreUtil.compareVersions(portalVersion, ILiferayConstants.V610) < 0) {
                    initParameterName = "jsp";
                }
                return initParameterName;
            }
        }
    }
    return super.getDefaultProperty(propertyName);
}
Also used : Version(org.osgi.framework.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 24 with ILiferayPortal

use of com.liferay.ide.core.ILiferayPortal in project liferay-ide by liferay.

the class LiferayDescriptorHelper method getDescriptorVersion.

public static String getDescriptorVersion(IProject project, String defaultValue) {
    String retval = defaultValue;
    try {
        ILiferayProject lProject = LiferayCore.create(project);
        if (lProject != null) {
            ILiferayPortal portal = lProject.adapt(ILiferayPortal.class);
            if (portal != null) {
                String versionStr = portal.getVersion();
                retval = getDescriptorVersionFromPortalVersion(versionStr);
            }
        }
    } catch (Exception e) {
        LiferayCore.logError("Could not get liferay runtime.", e);
    }
    if ("0.0.0".equals(retval)) {
        retval = defaultValue;
    }
    return retval;
}
Also used : ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 25 with ILiferayPortal

use of com.liferay.ide.core.ILiferayPortal in project liferay-ide by liferay.

the class LiferayHookModelTests method strutsActionPathPossibleValuesCacheService.

@Test
public void strutsActionPathPossibleValuesCacheService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final NewLiferayPluginProjectOp op = newProjectOp("testPossibleValuesCache");
    op.setPluginType(PluginType.hook);
    final IProject hookProject = createAntProject(op);
    final IFolder webappRoot = LiferayCore.create(IWebProject.class, hookProject).getDefaultDocrootFolder();
    assertNotNull(webappRoot);
    final IFile hookXml = webappRoot.getFile("WEB-INF/liferay-hook.xml");
    assertEquals(true, hookXml.exists());
    final Hook hook = Hook6xx.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(hookXml.getContents())));
    assertNotNull(hook);
    final ILiferayProject liferayProject = LiferayCore.create(hookProject);
    final ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
    final IPath strutsConfigPath = portal.getAppServerPortalDir().append("WEB-INF/struts-config.xml");
    final StrutsAction strutsAction = hook.getStrutsActions().insert();
    final Value<String> strutsActionPath = strutsAction.getStrutsActionPath();
    final TreeSet<String> vals1 = strutsActionPath.service(StrutsActionPathPossibleValuesCacheService.class).getPossibleValuesForPath(strutsConfigPath);
    final TreeSet<String> vals2 = strutsActionPath.service(StrutsActionPathPossibleValuesCacheService.class).getPossibleValuesForPath(strutsConfigPath);
    assertTrue(vals1 == vals2);
}
Also used : Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) StrutsActionPathPossibleValuesCacheService(com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesCacheService) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) StrutsAction(com.liferay.ide.hook.core.model.StrutsAction) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) ILiferayProject(com.liferay.ide.core.ILiferayProject) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

ILiferayPortal (com.liferay.ide.core.ILiferayPortal)32 ILiferayProject (com.liferay.ide.core.ILiferayProject)29 IPath (org.eclipse.core.runtime.IPath)13 IFile (org.eclipse.core.resources.IFile)10 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)8 IOException (java.io.IOException)7 Version (org.osgi.framework.Version)7 ArrayList (java.util.ArrayList)4 IWebProject (com.liferay.ide.core.IWebProject)3 Hook (com.liferay.ide.hook.core.model.Hook)3 File (java.io.File)3 Properties (java.util.Properties)3 JarFile (java.util.jar.JarFile)3 Path (org.eclipse.core.runtime.Path)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 ZipEntry (java.util.zip.ZipEntry)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2