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;
}
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]);
}
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;
}
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);
}
}
}
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;
}
Aggregations