Search in sources :

Example 1 with PortletDescriptorHelper

use of com.liferay.ide.portlet.core.dd.PortletDescriptorHelper in project liferay-ide by liferay.

the class BasePortletFramework method postProjectCreated.

@Override
public IStatus postProjectCreated(IProject project, String frameworkName, String portletName, IProgressMonitor monitor) {
    IStatus status = Status.OK_STATUS;
    if (!CoreUtil.isNullOrEmpty(portletName)) {
        PortletDescriptorHelper portletDH = new PortletDescriptorHelper(project);
        status = portletDH.configurePortletXml(portletName);
        if (!status.isOK()) {
            return status;
        }
        LiferayPortletDescriptorHelper liferayPortletDH = new LiferayPortletDescriptorHelper(project);
        status = liferayPortletDH.configureLiferayPortletXml(portletName);
        if (!status.isOK()) {
            return status;
        }
        LiferayDisplayDescriptorHelper liferayDisplayDH = new LiferayDisplayDescriptorHelper(project);
        status = liferayDisplayDH.configureLiferayDisplayXml(portletName);
    }
    return status;
}
Also used : LiferayPortletDescriptorHelper(com.liferay.ide.portlet.core.dd.LiferayPortletDescriptorHelper) PortletDescriptorHelper(com.liferay.ide.portlet.core.dd.PortletDescriptorHelper) IStatus(org.eclipse.core.runtime.IStatus) LiferayDisplayDescriptorHelper(com.liferay.ide.portlet.core.dd.LiferayDisplayDescriptorHelper) LiferayPortletDescriptorHelper(com.liferay.ide.portlet.core.dd.LiferayPortletDescriptorHelper)

Example 2 with PortletDescriptorHelper

use of com.liferay.ide.portlet.core.dd.PortletDescriptorHelper in project liferay-ide by liferay.

the class NewPortletClassDataModelProvider method validate.

@Override
public IStatus validate(String propertyName) {
    if (PORTLET_NAME.equals(propertyName)) {
        // must have a valid portlet name
        String portletName = getStringProperty(PORTLET_NAME);
        if ((portletName == null) || (portletName.length() == 0)) {
            return PortletCore.createErrorStatus(Msgs.portletNameEmpty);
        }
        PortletDescriptorHelper portletDescriptorHelper = new PortletDescriptorHelper(getTargetProject());
        String[] portletNames = portletDescriptorHelper.getAllPortletNames();
        for (String name : portletNames) {
            if (name.equals(portletName)) {
                return PortletCore.createErrorStatus(Msgs.portletNameExists);
            }
        }
    } else if (CREATE_RESOURCE_BUNDLE_FILE_PATH.equals(propertyName)) {
        if (!getBooleanProperty(CREATE_RESOURCE_BUNDLE_FILE)) {
            return Status.OK_STATUS;
        }
        boolean validPath = false;
        boolean validFileName = false;
        String val = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(val)) {
            return PortletCore.createErrorStatus(Msgs.resourceBundleFilePathValid);
        }
        try {
            IPath path = new Path(val);
            validPath = path.isValidPath(val);
            if ("properties".equals(path.getFileExtension())) {
                validFileName = true;
            }
        } catch (Exception e) {
        // eat errors
        }
        if (!validPath) {
            return PortletCore.createErrorStatus(Msgs.resourceBundleFilePathValid);
        }
        if (validFileName) {
            return super.validate(propertyName);
        } else {
            return PortletCore.createWarningStatus(Msgs.resourceBundleFilePathEndWithProperties);
        }
    } else if (CREATE_JSPS_FOLDER.equals(propertyName)) {
        if (!getBooleanProperty(CREATE_JSPS)) {
            return Status.OK_STATUS;
        }
        String folderValue = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(folderValue)) {
            return PortletCore.createErrorStatus(Msgs.jspFolderNotEmpty);
        }
        IProject targetProject = getTargetProject();
        if (!CoreUtil.isNullOrEmpty(folderValue) && (targetProject != null)) {
            IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
            if (webproject != null) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IStatus validation = _validateFolder(defaultDocroot, folderValue);
                if ((validation != null) && !validation.isOK()) {
                    return validation;
                }
                // make sure path first segment isn't the same as the portlet name
                String path = new Path(folderValue).segment(0);
                if (!CoreUtil.isNullOrEmpty(path) && path.equals(getStringProperty(PORTLET_NAME))) {
                    return PortletCore.createErrorStatus(Msgs.jspFolderNotMatchPortletName);
                }
            }
        }
    } else if (SOURCE_FOLDER.equals(propertyName) && fragment) {
        return Status.OK_STATUS;
    } else if (SUPERCLASS.equals(propertyName)) {
        String superclass = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(superclass)) {
            return PortletCore.createErrorStatus(Msgs.specifyPortletSuperclass);
        }
        if (fragment) {
            return JavaConventions.validateJavaTypeName(superclass, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
        }
        if (!isValidPortletClass(superclass)) {
            return PortletCore.createErrorStatus(Msgs.portletSuperclassValid);
        }
    } else if (CATEGORY.equals(propertyName)) {
        String category = getStringProperty(propertyName);
        if (category.matches("\\s*")) {
            return PortletCore.createErrorStatus(Msgs.categoryNameEmpty);
        }
    } else if (ENTRY_WEIGHT.equals(propertyName)) {
        if (!getBooleanProperty(ADD_TO_CONTROL_PANEL)) {
            return Status.OK_STATUS;
        }
        String entryweight = getStringProperty(propertyName);
        if (!CoreUtil.isNumeric(entryweight)) {
            return PortletCore.createErrorStatus(Msgs.specifyValidDouble);
        }
        return Status.OK_STATUS;
    } else if (ENTRY_CLASS_NAME.equals(propertyName)) {
        if (!getBooleanProperty(ADD_TO_CONTROL_PANEL) || !getBooleanProperty(CREATE_ENTRY_CLASS)) {
            return Status.OK_STATUS;
        }
        String entryclasswrapper = getStringProperty(propertyName);
        if (validateJavaClassName(entryclasswrapper).getSeverity() != IStatus.ERROR) {
            IStatus existsStatus = canCreateTypeInClasspath(entryclasswrapper);
            if (existsStatus.matches(IStatus.ERROR | IStatus.WARNING)) {
                return existsStatus;
            }
        }
        return validateJavaClassName(entryclasswrapper);
    } else if (CLASS_NAME.equals(propertyName)) {
        if (getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) {
            return Status.OK_STATUS;
        }
    }
    return super.validate(propertyName);
}
Also used : PortletDescriptorHelper(com.liferay.ide.portlet.core.dd.PortletDescriptorHelper) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with PortletDescriptorHelper

use of com.liferay.ide.portlet.core.dd.PortletDescriptorHelper in project liferay-ide by liferay.

the class LiferayPortletNameValidationService method compute.

@Override
protected Status compute() {
    Element modelElement = context(Element.class);
    if (!modelElement.disposed()) {
        liferayPortletName = (String) modelElement.property(context(ValueProperty.class)).content();
        IProject project = modelElement.adapt(IProject.class);
        String[] portletNames = new PortletDescriptorHelper(project).getAllPortletNames();
        if (portletNames != null) {
            for (String portletName : portletNames) {
                if (portletName.equals(liferayPortletName)) {
                    return Status.createOkStatus();
                }
            }
        }
    }
    return Status.createErrorStatus(Resources.bind(StringEscapeUtils.unescapeJava(Resources.portletNameInvalid), new Object[] { liferayPortletName }));
}
Also used : PortletDescriptorHelper(com.liferay.ide.portlet.core.dd.PortletDescriptorHelper) Element(org.eclipse.sapphire.Element) IProject(org.eclipse.core.resources.IProject)

Example 4 with PortletDescriptorHelper

use of com.liferay.ide.portlet.core.dd.PortletDescriptorHelper in project liferay-ide by liferay.

the class NewJSFPortletClassDataModelProvider method validate.

@Override
public IStatus validate(String propertyName) {
    if (PORTLET_NAME.equals(propertyName)) {
        IStatus status = super.validate(propertyName);
        if (!status.isOK()) {
            return status;
        }
        String currentPortletName = getStringProperty(PORTLET_NAME);
        PortletDescriptorHelper helper = new PortletDescriptorHelper(getTargetProject());
        for (String portletName : helper.getAllPortletNames()) {
            if (currentPortletName.equals(portletName)) {
                return PortletCore.createErrorStatus(Msgs.duplicatePortletName);
            }
        }
    }
    if (JSF_PORTLET_CLASS.equals(propertyName)) {
        String jsfPortletClass = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(jsfPortletClass)) {
            return PortletCore.createErrorStatus(Msgs.specifyJSFPortletClass);
        }
        if (fragment) {
            return Status.OK_STATUS;
        }
        if (!isValidPortletClass(jsfPortletClass)) {
            return PortletCore.createErrorStatus(Msgs.jsfPortletClassValid);
        }
    }
    if (SUPERCLASS.equals(propertyName)) {
        return Status.OK_STATUS;
    }
    if (CREATE_JSPS_FOLDER.equals(propertyName)) {
        if (!getBooleanProperty(CREATE_JSPS)) {
            return Status.OK_STATUS;
        }
        String jspsFolder = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(jspsFolder)) {
            return PortletCore.createErrorStatus(Msgs.jspFolderNotEmpty);
        }
        if (!jspsFolder.startsWith("/WEB-INF/") && !jspsFolder.startsWith("WEB-INF/")) {
            return PortletCore.createErrorStatus(Msgs.jsfFolderValid);
        }
        IFolder viewFolder = CoreUtil.getDefaultDocrootFolder(getProject()).getFolder(jspsFolder);
        if (viewFolder.exists()) {
            if (viewFolder.getFile("view.xhtml").exists()) {
                return PortletCore.createWarningStatus(Msgs.viewFileAlreadyExists);
            }
        }
    }
    return super.validate(propertyName);
}
Also used : PortletDescriptorHelper(com.liferay.ide.portlet.core.dd.PortletDescriptorHelper) IStatus(org.eclipse.core.runtime.IStatus) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with PortletDescriptorHelper

use of com.liferay.ide.portlet.core.dd.PortletDescriptorHelper in project liferay-ide by liferay.

the class AddResourceBundleFileMarkerResolution method _checkResourceBundleElement.

private void _checkResourceBundleElement(IProject project) {
    PortletDescriptorHelper portletDescriptorHelper = new PortletDescriptorHelper(project);
    String[] resouceBundles = portletDescriptorHelper.getAllResourceBundles();
    if (resouceBundles.length == 0) {
        portletDescriptorHelper.addResourceBundle(_resourceBundlePackage + "." + _resourceBundleName, _portletName);
    } else {
        for (String resouceBundle : resouceBundles) {
            if (!CoreUtil.isNullOrEmpty(resouceBundle)) {
                String[] paths = resouceBundle.split("\\.");
                if (paths.length > 2) {
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < (paths.length - 1); i++) {
                        sb.append(paths[i]);
                        sb.append("/");
                    }
                    _resourceBundlePackage = sb.toString();
                    _resourceBundleName = paths[paths.length - 1];
                } else if (paths.length == 2) {
                    _resourceBundlePackage = paths[0];
                    _resourceBundleName = paths[1];
                } else if (paths.length == 1) {
                    _resourceBundlePackage = "";
                    _resourceBundleName = paths[0];
                }
                break;
            }
        }
    }
}
Also used : PortletDescriptorHelper(com.liferay.ide.portlet.core.dd.PortletDescriptorHelper)

Aggregations

PortletDescriptorHelper (com.liferay.ide.portlet.core.dd.PortletDescriptorHelper)5 IStatus (org.eclipse.core.runtime.IStatus)3 IFolder (org.eclipse.core.resources.IFolder)2 IProject (org.eclipse.core.resources.IProject)2 IWebProject (com.liferay.ide.core.IWebProject)1 LiferayDisplayDescriptorHelper (com.liferay.ide.portlet.core.dd.LiferayDisplayDescriptorHelper)1 LiferayPortletDescriptorHelper (com.liferay.ide.portlet.core.dd.LiferayPortletDescriptorHelper)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 Element (org.eclipse.sapphire.Element)1