Search in sources :

Example 1 with CustomJsp

use of com.liferay.ide.hook.core.model.CustomJsp 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 2 with CustomJsp

use of com.liferay.ide.hook.core.model.CustomJsp 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)

Aggregations

CustomJsp (com.liferay.ide.hook.core.model.CustomJsp)2 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)2 Hook (com.liferay.ide.hook.core.model.Hook)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.sapphire.modeling.Path)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 IWebProject (com.liferay.ide.core.IWebProject)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 PartInitException (org.eclipse.ui.PartInitException)1