Search in sources :

Example 1 with ParamValue

use of org.eclipse.jst.j2ee.common.ParamValue in project liferay-ide by liferay.

the class PortletDescriptorHelper method doAddNewPortlet.

public IStatus doAddNewPortlet(IDOMDocument document, IDataModel model) {
    // <portlet-app> element
    Element rootElement = document.getDocumentElement();
    // new <portlet> element
    Element newPortletElement = document.createElement("portlet");
    NodeUtil.appendChildElement(newPortletElement, "portlet-name", model.getStringProperty(PORTLET_NAME));
    NodeUtil.appendChildElement(newPortletElement, "display-name", model.getStringProperty(DISPLAY_NAME));
    NodeUtil.appendChildElement(newPortletElement, "portlet-class", getPortletClassText(model));
    // add <init-param> elements as needed
    List<ParamValue> initParams = (List<ParamValue>) model.getProperty(INIT_PARAMS);
    for (ParamValue initParam : initParams) {
        Element newInitParamElement = NodeUtil.appendChildElement(newPortletElement, "init-param");
        NodeUtil.appendChildElement(newInitParamElement, "name", initParam.getName());
        NodeUtil.appendChildElement(newInitParamElement, "value", initParam.getValue());
    }
    // expiration cache
    NodeUtil.appendChildElement(newPortletElement, "expiration-cache", "0");
    // supports node
    Element newSupportsElement = NodeUtil.appendChildElement(newPortletElement, "supports");
    NodeUtil.appendChildElement(newSupportsElement, "mime-type", "text/html");
    for (String portletMode : ALL_PORTLET_MODES) {
        if (model.getBooleanProperty(portletMode)) {
            NodeUtil.appendChildElement(newSupportsElement, "portlet-mode", model.getPropertyDescriptor(portletMode).getPropertyDescription());
        }
    }
    if (model.getBooleanProperty(CREATE_RESOURCE_BUNDLE_FILE)) {
        // need to remove .properties off the end of the bundle_file_path
        String bundlePath = model.getStringProperty(CREATE_RESOURCE_BUNDLE_FILE_PATH);
        String bundleValue = bundlePath.replaceAll("\\.properties$", StringPool.EMPTY);
        String validBuildValue = bundleValue.replaceAll("\\/", ".");
        NodeUtil.appendChildElement(newPortletElement, "resource-bundle", validBuildValue);
    }
    // add portlet-info
    Element newPortletInfoElement = NodeUtil.appendChildElement(newPortletElement, "portlet-info");
    NodeUtil.appendChildElement(newPortletInfoElement, "title", model.getStringProperty(TITLE));
    NodeUtil.appendChildElement(newPortletInfoElement, "short-title", model.getStringProperty(SHORT_TITLE));
    NodeUtil.appendChildElement(newPortletInfoElement, "keywords", model.getStringProperty(KEYWORDS));
    for (String roleName : DEFAULT_SECURITY_ROLE_NAMES) {
        NodeUtil.appendChildElement(NodeUtil.appendChildElement(newPortletElement, "security-role-ref"), "role-name", roleName);
    }
    // check for event-definition elements
    Node refNode = null;
    String[] refElementNames = { "custom-portlet-mode", "custom-window-state", "user-attribute", "security-constraint", "resource-bundle", "filter", "filter-mapping", "default-namespace", "event-definition", "public-render-parameter", "listener", "container-runtime-option" };
    for (int i = 0; i < refElementNames.length; i++) {
        refNode = NodeUtil.findFirstChild(rootElement, refElementNames[i]);
        if (refNode != null) {
            break;
        }
    }
    rootElement.insertBefore(newPortletElement, refNode);
    // append a newline text node
    rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
    // format the new node added to the model;
    FormatProcessorXML processor = new FormatProcessorXML();
    processor.formatNode(newPortletElement);
    return Status.OK_STATUS;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ParamValue(org.eclipse.jst.j2ee.common.ParamValue) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 2 with ParamValue

use of org.eclipse.jst.j2ee.common.ParamValue in project liferay-ide by liferay.

the class NewPortletClassDataModelProvider method createDefaultParamValuesForModes.

protected ParamValue[] createDefaultParamValuesForModes(String[] modes, String[] names, String[] values) {
    Assert.isTrue(modes != null && names != null && values != null && (modes.length == names.length) && (names.length == values.length));
    List<ParamValue> defaultParams = new ArrayList<>();
    // for each path value need to prepend a path that will be specific to
    // the portlet being created
    String prependPath = getDataModel().getStringProperty(CREATE_JSPS_FOLDER);
    for (int i = 0; i < modes.length; i++) {
        if (getBooleanProperty(modes[i])) {
            ParamValue paramValue = CommonFactory.eINSTANCE.createParamValue();
            paramValue.setName(names[i]);
            if (CoreUtil.isNullOrEmpty(prependPath)) {
                paramValue.setValue(values[i]);
            } else {
                if (CoreUtil.isNullOrEmpty(prependPath) || !prependPath.startsWith("/")) {
                    prependPath = "/" + prependPath;
                }
                paramValue.setValue(prependPath + values[i]);
            }
            defaultParams.add(paramValue);
        }
    }
    return defaultParams.toArray(new ParamValue[0]);
}
Also used : ArrayList(java.util.ArrayList) ParamValue(org.eclipse.jst.j2ee.common.ParamValue)

Example 3 with ParamValue

use of org.eclipse.jst.j2ee.common.ParamValue in project liferay-ide by liferay.

the class NewPortletClassDataModelProvider method getInitParams.

protected Object getInitParams() {
    List<ParamValue> initParams = new ArrayList<>();
    if (/* getStringProperty(SUPERCLASS).equals(QUALIFIED_MVC_PORTLET) && */
    getBooleanProperty(CREATE_JSPS)) {
        String[] modes = ALL_PORTLET_MODES;
        ParamValue[] paramVals = null;
        try {
            ILiferayProject liferayProject = LiferayCore.create(getProject());
            ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
            String version = portal.getVersion();
            Version portalVersion = Version.parseVersion(version);
            if (CoreUtil.compareVersions(portalVersion, ILiferayConstants.V610) >= 0) {
                paramVals = createDefaultParamValuesForModes(modes, initNames61, initValues);
            }
        } catch (Exception e) {
        }
        if (paramVals == null) {
            paramVals = createDefaultParamValuesForModes(modes, initNames60, initValues);
        }
        Collections.addAll(initParams, paramVals);
    }
    return initParams;
}
Also used : Version(org.osgi.framework.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) ArrayList(java.util.ArrayList) ParamValue(org.eclipse.jst.j2ee.common.ParamValue) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException)

Example 4 with ParamValue

use of org.eclipse.jst.j2ee.common.ParamValue in project liferay-ide by liferay.

the class AddPortletOperation method createResourceForMode.

@SuppressWarnings("unchecked")
protected void createResourceForMode(String initParamName, String templateId, TemplateContext context) {
    Template template = templateStore.findTemplateById(templateId);
    String templateString = null;
    try {
        TemplateBuffer buffer = context.evaluate(template);
        templateString = buffer.getString();
    } catch (Exception ex) {
        PortletCore.logError(ex);
        return;
    }
    // need to get the path in the web app for the new jsp mode file
    IFile viewJspFile = null;
    List<ParamValue> initParams = (List<ParamValue>) getDataModel().getProperty(INIT_PARAMS);
    for (ParamValue paramValue : initParams) {
        if (paramValue.getName().equals(initParamName)) {
            viewJspFile = getProjectFile(paramValue.getValue());
            break;
        }
    }
    if (viewJspFile != null) {
        try {
            if (viewJspFile.exists()) {
                viewJspFile.setContents(new ByteArrayInputStream(templateString.getBytes("UTF-8")), IResource.FORCE, null);
            } else {
                // make sure that full path to jspfile is available
                CoreUtil.prepareFolder((IFolder) viewJspFile.getParent());
                viewJspFile.create(new ByteArrayInputStream(templateString.getBytes("UTF-8")), IResource.FORCE, null);
            }
        } catch (Exception ex) {
            PortletCore.logError(ex);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ParamValue(org.eclipse.jst.j2ee.common.ParamValue) List(java.util.List) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) Template(org.eclipse.jface.text.templates.Template)

Example 5 with ParamValue

use of org.eclipse.jst.j2ee.common.ParamValue in project liferay-ide by liferay.

the class AddPortletOperation method createModeJSPFiles.

@SuppressWarnings("unchecked")
protected IStatus createModeJSPFiles() {
    IDataModel dm = getDataModel();
    TemplateContext context = new DocumentTemplateContext(portletContextType, new Document(), 0, 0);
    context.setVariable("portlet_display_name", getDataModel().getStringProperty(DISPLAY_NAME));
    List<ParamValue> initParams = (List<ParamValue>) getDataModel().getProperty(INIT_PARAMS);
    String initParamSuffix = null;
    if (initNames61[0].equals(initParams.get(0).getName())) {
        initParamSuffix = "template";
    } else {
        initParamSuffix = "jsp";
    }
    if (dm.getBooleanProperty(ABOUT_MODE)) {
        createResourceForMode("about-" + initParamSuffix, ABOUT_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(CONFIG_MODE)) {
        createResourceForMode("config-" + initParamSuffix, CONFIG_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(EDIT_MODE)) {
        createResourceForMode("edit-" + initParamSuffix, EDIT_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(EDITDEFAULTS_MODE)) {
        createResourceForMode("edit-defaults-" + initParamSuffix, EDITDEFAULTS_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(EDITGUEST_MODE)) {
        createResourceForMode("edit-guest-" + initParamSuffix, EDITGUEST_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(HELP_MODE)) {
        createResourceForMode("help-" + initParamSuffix, HELP_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(PREVIEW_MODE)) {
        createResourceForMode("preview-" + initParamSuffix, PREVIEW_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(PRINT_MODE)) {
        createResourceForMode("print-" + initParamSuffix, PRINT_MODE_TEMPLATE, context);
    }
    if (dm.getBooleanProperty(VIEW_MODE)) {
        createResourceForMode("view-" + initParamSuffix, VIEW_MODE_TEMPLATE, context);
    }
    return Status.OK_STATUS;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) ParamValue(org.eclipse.jst.j2ee.common.ParamValue) List(java.util.List) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateContext(org.eclipse.jface.text.templates.TemplateContext) Document(org.eclipse.jface.text.Document)

Aggregations

ParamValue (org.eclipse.jst.j2ee.common.ParamValue)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 CoreException (org.eclipse.core.runtime.CoreException)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 Document (org.eclipse.jface.text.Document)1 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)1 Template (org.eclipse.jface.text.templates.Template)1 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)1 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)1 IDataModel (org.eclipse.wst.common.frameworks.datamodel.IDataModel)1 FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)1 Version (org.osgi.framework.Version)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1