Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUI-1949 - Import portal dependencies. #16

Closed
wants to merge 6 commits into from
Closed
11 changes: 11 additions & 0 deletions alloy-taglib/src/com/liferay/alloy/tools/model/Component.java
Expand Up @@ -98,6 +98,10 @@ public boolean isBodyContent() {
return _bodyContent;
}

public boolean isComponentTaglibOSGIModule() {
return _componentTaglibOSGIModule;
}

public boolean isDynamicAttributes() {
return _dynamicAttributes;
}
Expand Down Expand Up @@ -142,6 +146,12 @@ public void setEvents(List<Attribute> events) {
}
}

public void setComponentTaglibOSGIModule(
boolean componentTaglibOSGIModule) {

_componentTaglibOSGIModule = componentTaglibOSGIModule;
}

public void setModule(String type) {
_module = type;
}
Expand All @@ -168,6 +178,7 @@ public void setWriteJSP(boolean writeJSP) {
private String _description;
private boolean _dynamicAttributes;
private List<Attribute> _events;
private boolean _componentTaglibOSGIModule;
private String _module;
private String _package;
private String _parentClass;
Expand Down
100 changes: 87 additions & 13 deletions alloy-taglib/src/com/liferay/alloy/tools/tagbuilder/TagBuilder.java
Expand Up @@ -51,6 +51,8 @@ public static void main(String[] args) throws Exception {
String jspCommonInitPath = System.getProperty(
"tagbuilder.jsp.common.init.path");
String jspDir = System.getProperty("tagbuilder.jsp.dir");
String OSGIModuleSymbolicName = System.getProperty(
"tagbuilder.osgi.module.symbolic.name");
String templatesDir = System.getProperty("tagbuilder.templates.dir");
String tldDir = System.getProperty("tagbuilder.tld.dir");

Expand All @@ -64,13 +66,14 @@ public static void main(String[] args) throws Exception {

new TagBuilder(
componentsXML, templatesDir, javaDir, docrootDir, javaPackage,
jspDir, jspCommonInitPath, tldDir);
jspDir, jspCommonInitPath, OSGIModuleSymbolicName, tldDir);
}

public TagBuilder(
String componentsXML, String templatesDir, String javaDir,
String docrootDir, String javaPackage, String jspDir,
String jspCommonInitPath, String tldDir)
String jspCommonInitPath, String OSGIModuleSymbolicName,
String tldDir)
throws Exception {

if (PropsUtil.getProps() == null) {
Expand All @@ -88,11 +91,13 @@ public TagBuilder(
_javaPackage = javaPackage;
_jspDir = jspDir;
_jspCommonInitPath = jspCommonInitPath;
_OSGIModuleSymbolicName = OSGIModuleSymbolicName;
_tldDir = tldDir;

_tplTld = _templatesDir + "tld.ftl";
_tplTag = _templatesDir + "tag.ftl";
_tplTagBase = _templatesDir + "tag_base.ftl";
_tplServletContextUtil = _templatesDir + "servlet_context_util.ftl";
_tplCommonInitJsp = _templatesDir + "common_init_jsp.ftl";
_tplJsp = _templatesDir + "jsp.ftl";
_tplInitJsp = _templatesDir + "init_jsp.ftl";
Expand Down Expand Up @@ -121,10 +126,18 @@ protected List<Component> getAllComponents() throws Exception {
for (Document extDoc : _componentsExtDoc) {
Element extRoot = extDoc.getRootElement();

boolean OSGIModule = GetterUtil.getBoolean(
extRoot.attributeValue("osgi-module"));

String extComponentTaglibOSGIModule = String.valueOf(OSGIModule);

String defaultPackage = extRoot.attributeValue("short-name");
List<Element> extComponentNodes = extRoot.elements("component");

for (Element extComponent : extComponentNodes) {
extComponent.addAttribute(
"componentTaglibOSGIModule", extComponentTaglibOSGIModule);

String extComponentPackage = GetterUtil.getString(
extComponent.attributeValue("package"), defaultPackage);

Expand Down Expand Up @@ -258,6 +271,9 @@ protected List<Component> getComponents(Document doc) throws Exception {
List<Element> allComponentNodes = root.elements("component");

for (Element node : allComponentNodes) {
boolean componentTaglibOSGIModule = GetterUtil.getBoolean(
node.attributeValue("componentTaglibOSGIModule"));

String componentPackage = GetterUtil.getString(
node.attributeValue("package"), defaultPackage);

Expand Down Expand Up @@ -296,6 +312,7 @@ protected List<Component> getComponents(Document doc) throws Exception {
component.setAuthors(authors);
component.setBodyContent(bodyContent);
component.setClassName(className);
component.setComponentTaglibOSGIModule(componentTaglibOSGIModule);
component.setDescription(description);
component.setDynamicAttributes(dynamicAttributes);
component.setEvents(events);
Expand Down Expand Up @@ -359,8 +376,15 @@ protected String getJavaOutputDir(Component component) {
StringBuilder sb = new StringBuilder();

sb.append(_javaDir);
sb.append(component.getPackage());
sb.append(StringPool.SLASH);

if (component.isComponentTaglibOSGIModule()) {
sb.append(_TAGLIB);
sb.append(StringPool.SLASH);
}
else {
sb.append(component.getPackage());
sb.append(StringPool.SLASH);
}

return sb.toString();
}
Expand All @@ -369,20 +393,24 @@ protected String getJspDir(Component component) {
StringBuilder sb = new StringBuilder();

sb.append(_jspDir);
sb.append(component.getPackage());
sb.append(StringPool.SLASH);

if (!component.isComponentTaglibOSGIModule()) {
sb.append(component.getPackage());
sb.append(StringPool.SLASH);
}

return sb.toString();
}

protected String getJspOutputDir(Component component) {
StringBuilder sb = new StringBuilder();

sb.append(_docrootDir);
sb.append(StringPool.SLASH);
sb.append(_jspDir);
sb.append(component.getPackage());
sb.append(StringPool.SLASH);
if (Validator.isNotNull(_docrootDir)) {
sb.append(_docrootDir);
sb.append(StringPool.SLASH);
}

sb.append(getJspDir(component));

return sb.toString();
}
Expand Down Expand Up @@ -614,6 +642,7 @@ private void _create() throws Exception {

_createCommonInitJSP();
_createTld();
_createServletContextUtil();
}

private void _createBaseTag(
Expand Down Expand Up @@ -642,8 +671,11 @@ private void _createCommonInitJSP() throws Exception {

StringBuilder sb = new StringBuilder();

sb.append(_docrootDir);
sb.append(StringPool.SLASH);
if (Validator.isNotNull(_docrootDir)) {
sb.append(_docrootDir);
sb.append(StringPool.SLASH);
}

sb.append(_jspCommonInitPath);

File commonInitFile = new File(sb.toString());
Expand Down Expand Up @@ -681,6 +713,42 @@ private void _createPageJSP(
}
}

private void _createServletContextUtil() throws Exception {
for (Document doc : _componentsExtDoc) {
Element root = doc.getRootElement();

boolean OSGIModule = GetterUtil.getBoolean(
root.attributeValue("osgi-module"));

if (OSGIModule) {
Map<String, Object> context = getDefaultTemplateContext();

String OSGIModuleSymbolicName = GetterUtil.get(
_OSGIModuleSymbolicName, StringPool.BLANK);

context.put("OSGIModuleSymbolicName", OSGIModuleSymbolicName);
context.put("taglibAuthors", getAuthorList(root));

StringBuilder sb = new StringBuilder();

sb.append(_javaDir);
sb.append(_SERVLET_CONTEXT_UTIL);
sb.append(_CLASS_SUFFIX);

String content = processTemplate(
_tplServletContextUtil, context);

File servletContextUtilFile = new File(sb.toString());

writeFile(servletContextUtilFile, content, false);

if (servletContextUtilFile.exists()) {
break;
}
}
}
}

private void _createTag(Component component, Map<String, Object> context)
throws Exception {

Expand Down Expand Up @@ -782,8 +850,12 @@ private void _createTld() throws Exception {

private static final String _PAGE = "/page.jsp";

private static final String _SERVLET_CONTEXT_UTIL = "ServletContextUtil";

private static final String _START_PAGE = "/start.jsp";

private static final String _TAGLIB = "taglib";

private static final String _TLD_EXTENSION = ".tld";

private static final String _TLD_XPATH_PREFIX = "tld";
Expand All @@ -800,11 +872,13 @@ private void _createTld() throws Exception {
private String _javaPackage;
private String _jspCommonInitPath;
private String _jspDir;
private String _OSGIModuleSymbolicName;
private String _templatesDir;
private String _tldDir;
private String _tplCommonInitJsp;
private String _tplInitJsp;
private String _tplJsp;
private String _tplServletContextUtil;
private String _tplStartJsp;
private String _tplTag;
private String _tplTagBase;
Expand Down
@@ -0,0 +1,57 @@
<#include "copyright.ftl">

package ${packagePath};

import com.liferay.portal.kernel.util.Validator;

import javax.servlet.ServletContext;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

/**
<#list taglibAuthors as taglibAuthor>
* @author ${taglibAuthor}
</#list>
* @generated
*/
@Component(immediate = true)
public class ServletContextUtil {

public static final ServletContext getServletContext() {
if (Validator.isNotNull(_instance)) {
return _instance._getServletContext();
}

return null;
}

@Activate
protected void activate() {
_instance = this;
}

@Deactivate
protected void deactivate() {
_instance = null;
}

@Reference(
target = "(osgi.web.symbolicname=${OSGIModuleSymbolicName})",
unbind = "-"
)
protected void setServletContext(ServletContext servletContext) {
_servletContext = servletContext;
}

private ServletContext _getServletContext() {
return _servletContext;
}

private static ServletContextUtil _instance;

private ServletContext _servletContext;

}
@@ -1,9 +1,16 @@
<#include "copyright.ftl">

<#if component.isComponentTaglibOSGIModule() == true>
package ${packagePath}.taglib;

import ${packagePath}.taglib.base.Base${component.getClassName()};

<#else>
package ${packagePath}.${component.getPackage()};

import ${packagePath}.${component.getPackage()}.base.Base${component.getClassName()};

</#if>
/**
<#list component.getAuthors() as author>
* @author ${author}
Expand Down
@@ -1,12 +1,22 @@
<#include "init.ftl">
<#include "copyright.ftl">

<#if component.isComponentTaglibOSGIModule() == true>
package ${packagePath}.taglib.base;

import ${packagePath}.ServletContextUtil;

<#else>
package ${packagePath}.${component.getPackage()}.base;

</#if>
<#if component.getWriteJSP() == true>
import javax.servlet.http.HttpServletRequest;
</#if>
import javax.servlet.jsp.JspException;
<#if component.isComponentTaglibOSGIModule() == true>
import javax.servlet.jsp.PageContext;
</#if>

/**
<#list component.getAuthors() as author>
Expand Down Expand Up @@ -53,6 +63,19 @@ public abstract class Base${component.getClassName()} extends ${component.getPar

</#if>
</#list>
<#if component.isComponentTaglibOSGIModule() == true>
<#if typeUtil.hasMethod(component.getParentClass(), "setPageContext", ["javax.servlet.jsp.PageContext"]) == true>
@Override
</#if>
public void setPageContext(PageContext pageContext) {
<#if typeUtil.hasMethod(component.getParentClass(), "setPageContext", ["javax.servlet.jsp.PageContext"]) == true>
super.setPageContext(pageContext);

</#if>
setServletContext(ServletContextUtil.getServletContext());
}

</#if>
<#if typeUtil.hasMethod(component.getParentClass(), "cleanUp", []) == true>
@Override
</#if>
Expand Down
Expand Up @@ -18,7 +18,11 @@
<description><![CDATA[${component.getDescription()}]]></description>
</#if>
<name>${component.getUncamelizedName()}</name>
<#if component.isComponentTaglibOSGIModule() == true>
<tag-class>${packagePath}.taglib.${component.getClassName()}</tag-class>
<#else>
<tag-class>${packagePath}.${component.getPackage()}.${component.getClassName()}</tag-class>
</#if>
<body-content>JSP</body-content>
<#list component.getAttributesAndEvents() as attribute>
<attribute>
Expand Down
Binary file modified lib/application/portal-impl.jar
Binary file not shown.
Binary file modified lib/application/portal-service.jar
Binary file not shown.
Binary file modified lib/application/util-java.jar
Binary file not shown.
Binary file modified lib/application/util-taglib.jar
Binary file not shown.