Search in sources :

Example 1 with Hook

use of com.liferay.ide.hook.core.model.Hook in project liferay-ide by liferay.

the class PortalPropertiesFileListener method handleTypedEvent.

@Override
protected void handleTypedEvent(PropertyContentEvent event) {
    Property prop = event.property();
    if (Hook.PROP_PORTAL_PROPERTIES_FILE.equals(prop.definition())) {
        Hook hook = prop.element().nearest(Hook.class);
        PortalPropertiesFile ppf = hook.getPortalPropertiesFile().content(false);
        if (ppf != null) {
            Value<Path> value = ppf.getValue();
            if (value != null) {
                Path path = value.content(false);
                if (path == null) {
                    ppf.initialize();
                }
            }
        }
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) PortalPropertiesFile(com.liferay.ide.hook.core.model.PortalPropertiesFile) Property(org.eclipse.sapphire.Property)

Example 2 with Hook

use of com.liferay.ide.hook.core.model.Hook in project liferay-ide by liferay.

the class HookXmlEditor method _copyCustomJspsToProject.

private void _copyCustomJspsToProject(IPath portalDir, ElementList<CustomJsp> customJsps) {
    try {
        Hook hook = getModelElement().nearest(Hook.class);
        ElementHandle<CustomJspDir> element = hook.getCustomJspDir();
        CustomJspDir customJspDirElement = element.content();
        if ((customJspDirElement != null) && customJspDirElement.validation().ok()) {
            Path customJspDir = customJspDirElement.getValue().content();
            IWebProject webproject = LiferayCore.create(IWebProject.class, getProject());
            if (webproject != null) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IFolder customJspFolder = defaultDocroot.getFolder(customJspDir.toPortableString());
                for (CustomJsp customJsp : customJsps) {
                    String content = customJsp.getValue().content();
                    if (!empty(content)) {
                        IFile customJspFile = customJspFolder.getFile(content);
                        if (!customJspFile.exists()) {
                            IPath portalJsp = portalDir.append(content);
                            try {
                                CoreUtil.makeFolders((IFolder) customJspFile.getParent());
                                if (portalJsp.toFile().exists()) {
                                    customJspFile.create(Files.newInputStream(portalJsp.toFile().toPath()), true, null);
                                } else {
                                    CoreUtil.createEmptyFile(customJspFile);
                                }
                            } catch (Exception e) {
                                HookUI.logError(e);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        HookUI.logError(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) CustomJsp(com.liferay.ide.hook.core.model.CustomJsp) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with Hook

use of com.liferay.ide.hook.core.model.Hook in project liferay-ide by liferay.

the class HookXmlEditor method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    if (customModelDirty) {
        Hook hook = getModelElement().nearest(Hook.class);
        ElementList<CustomJsp> customJsps = hook.getCustomJsps();
        ILiferayProject liferayProject = LiferayCore.create(getProject());
        ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
        if (portal != null) {
            IPath portalDir = portal.getAppServerPortalDir();
            if (portalDir != null) {
                _copyCustomJspsToProject(portalDir, customJsps);
            }
        }
        customModelDirty = false;
        super.doSave(monitor);
        firePropertyChange(IEditorPart.PROP_DIRTY);
        ElementHandle<CustomJspDir> customJspDir = hook.getCustomJspDir();
        if ((customJspDir != null) && !customJspDir.empty()) {
            Value<Path> customJspPath = customJspDir.content().getValue();
            Path path = customJspPath.content().makeRelative();
            String customeJspValue = path.toPortableString();
            _configureCustomJspValidation(getProject(), customeJspValue);
        }
    } else {
        super.doSave(monitor);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) IPath(org.eclipse.core.runtime.IPath) CustomJsp(com.liferay.ide.hook.core.model.CustomJsp) ILiferayProject(com.liferay.ide.core.ILiferayProject) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 4 with Hook

use of com.liferay.ide.hook.core.model.Hook in project liferay-ide by liferay.

the class CustomJspDirListener method handleTypedEvent.

@Override
protected void handleTypedEvent(PropertyContentEvent event) {
    Property prop = event.property();
    Hook hook = prop.element().nearest(Hook.class);
    if (hook != null) {
        if (CustomJspDir.PROP_VALUE.equals(prop.definition())) {
            // IDE-1132, Listen the change of Property CustomJspDir, and refresh the
            // Property CustomJsps.
            hook.property(Hook.PROP_CUSTOM_JSPS).refresh();
        } else if (Hook.PROP_CUSTOM_JSP_DIR.equals(prop.definition())) {
            // IDE-1251 listen for changes to custom_jsp_dir and if it is empty initialize
            // initial content @InitialValue
            CustomJspDir customJspDir = hook.getCustomJspDir().content(false);
            if (customJspDir != null) {
                Value<Path> value = customJspDir.getValue();
                if (value != null) {
                    Path path = value.content(false);
                    if (path == null) {
                        customJspDir.initialize();
                    }
                }
            }
        }
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) Value(org.eclipse.sapphire.Value) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) Property(org.eclipse.sapphire.Property)

Example 5 with Hook

use of com.liferay.ide.hook.core.model.Hook in project liferay-ide by liferay.

the class LiferayHookModelTests method strutsActionPathPossibleValuesService.

/**
 * @throws Exception
 */
@Test
public void strutsActionPathPossibleValuesService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final NewLiferayPluginProjectOp op = newProjectOp("testPossibleValues");
    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 XmlResourceStore store = new XmlResourceStore(hookXml.getContents()) {

        public <A> A adapt(Class<A> adapterType) {
            if (IProject.class.equals(adapterType)) {
                return adapterType.cast(hookProject);
            }
            return super.adapt(adapterType);
        }
    };
    final Hook hook = Hook6xx.TYPE.instantiate(new RootXmlResource(store));
    assertNotNull(hook);
    final StrutsAction strutsAction = hook.getStrutsActions().insert();
    final Value<String> strutsActionPath = strutsAction.getStrutsActionPath();
    final Set<String> values = strutsActionPath.service(StrutsActionPathPossibleValuesService.class).values();
    assertNotNull(values);
    assertTrue(values.size() > 10);
}
Also used : Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) 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) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) StrutsActionPathPossibleValuesService(com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesService) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

Hook (com.liferay.ide.hook.core.model.Hook)9 Path (org.eclipse.sapphire.modeling.Path)6 IFolder (org.eclipse.core.resources.IFolder)5 IWebProject (com.liferay.ide.core.IWebProject)4 IProject (org.eclipse.core.resources.IProject)4 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)3 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)2 ILiferayProject (com.liferay.ide.core.ILiferayProject)2 CustomJsp (com.liferay.ide.hook.core.model.CustomJsp)2 StrutsAction (com.liferay.ide.hook.core.model.StrutsAction)2 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)2 ArrayList (java.util.ArrayList)2 Property (org.eclipse.sapphire.Property)2 RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)2 XmlResourceStore (org.eclipse.sapphire.modeling.xml.XmlResourceStore)2 Test (org.junit.Test)2 PortalPropertiesFile (com.liferay.ide.hook.core.model.PortalPropertiesFile)1 StrutsActionPathPossibleValuesCacheService (com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesCacheService)1