Skip to content

Commit

Permalink
LPS-55800 Add servletContext property
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Barros committed Jul 27, 2015
1 parent 05296b6 commit 3bb88f4
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
Expand Up @@ -188,6 +188,12 @@
<rtexprvalue>true</rtexprvalue>
<type>boolean</type>
</attribute>
<attribute>
<name>servletContext</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<dynamic-attributes>true</dynamic-attributes>
</tag>
</taglib>
Expand Up @@ -16,6 +16,9 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import com.liferay.dynamic.data.mapping.taglib.util.ServletContextUtil;

/**
* @author Bruno Basto
Expand Down Expand Up @@ -61,6 +64,10 @@ public java.util.Locale getRequestedLocale() {
public boolean getShowEmptyFieldLabel() {
return _showEmptyFieldLabel;
}

public java.lang.Object getServletContext() {
return _servletContext;
}

public void setClassNameId(long classNameId) {
_classNameId = classNameId;
Expand Down Expand Up @@ -109,6 +116,19 @@ public void setShowEmptyFieldLabel(boolean showEmptyFieldLabel) {

setScopedAttribute("showEmptyFieldLabel", showEmptyFieldLabel);
}

public void setServletContext(java.lang.Object servletContext) {
_servletContext = servletContext;

setScopedAttribute("servletContext", servletContext);
}

@Override
public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);

setServletContext(ServletContextUtil.getServletContext());
}

@Override
protected void cleanUp() {
Expand All @@ -122,6 +142,7 @@ protected void cleanUp() {
_repeatable = true;
_requestedLocale = null;
_showEmptyFieldLabel = true;
_servletContext = null;
}

@Override
Expand All @@ -144,15 +165,16 @@ protected void setAttributes(HttpServletRequest request) {
setNamespacedAttribute(request, "repeatable", _repeatable);
setNamespacedAttribute(request, "requestedLocale", _requestedLocale);
setNamespacedAttribute(request, "showEmptyFieldLabel", _showEmptyFieldLabel);
setNamespacedAttribute(request, "servletContext", _servletContext);
}

protected static final String _ATTRIBUTE_NAMESPACE = "ddm:html-field:";

private static final String _END_PAGE =
"/html/taglib/ddm/html_field/end.jsp";
"/taglib/ui/html_field/end.jsp";

private static final String _START_PAGE =
"/html/taglib/ddm/html_field/start.jsp";
"/taglib/ui/html_field/start.jsp";

private long _classNameId = 0;
private long _classPK = 0;
Expand All @@ -162,5 +184,6 @@ protected void setAttributes(HttpServletRequest request) {
private boolean _repeatable = true;
private java.util.Locale _requestedLocale = null;
private boolean _showEmptyFieldLabel = true;
private java.lang.Object _servletContext = null;

}
Expand Up @@ -16,6 +16,9 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import com.liferay.dynamic.data.mapping.taglib.util.ServletContextUtil;

/**
* @author Bruno Basto
Expand Down Expand Up @@ -119,6 +122,19 @@ public void setShowEmptyFieldLabel(boolean showEmptyFieldLabel) {

setScopedAttribute("showEmptyFieldLabel", showEmptyFieldLabel);
}

public void setServletContext(java.lang.Object servletContext) {
_servletContext = servletContext;

setScopedAttribute("servletContext", servletContext);
}

@Override
public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);

setServletContext(ServletContextUtil.getServletContext());
}

@Override
protected void cleanUp() {
Expand All @@ -133,6 +149,7 @@ protected void cleanUp() {
_repeatable = true;
_requestedLocale = null;
_showEmptyFieldLabel = true;
_servletContext = null;
}

@Override
Expand All @@ -156,15 +173,16 @@ protected void setAttributes(HttpServletRequest request) {
setNamespacedAttribute(request, "repeatable", _repeatable);
setNamespacedAttribute(request, "requestedLocale", _requestedLocale);
setNamespacedAttribute(request, "showEmptyFieldLabel", _showEmptyFieldLabel);
setNamespacedAttribute(request, "servletContext", _servletContext);
}

protected static final String _ATTRIBUTE_NAMESPACE = "ddm:html:";

private static final String _END_PAGE =
"/html/taglib/ddm/html/end.jsp";
"/taglib/ui/html/end.jsp";

private static final String _START_PAGE =
"/html/taglib/ddm/html/start.jsp";
"/taglib/ui/html/start.jsp";

private boolean _checkRequired = true;
private long _classNameId = 0;
Expand All @@ -175,5 +193,6 @@ protected void setAttributes(HttpServletRequest request) {
private boolean _repeatable = true;
private java.util.Locale _requestedLocale = null;
private boolean _showEmptyFieldLabel = true;
private java.lang.Object _servletContext = null;

}
Expand Up @@ -16,6 +16,9 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import com.liferay.dynamic.data.mapping.taglib.util.ServletContextUtil;

/**
* @author Bruno Basto
Expand Down Expand Up @@ -119,6 +122,19 @@ public void setShowEmptyOption(boolean showEmptyOption) {

setScopedAttribute("showEmptyOption", showEmptyOption);
}

public void setServletContext(java.lang.Object servletContext) {
_servletContext = servletContext;

setScopedAttribute("servletContext", servletContext);
}

@Override
public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);

setServletContext(ServletContextUtil.getServletContext());
}

@Override
protected void cleanUp() {
Expand All @@ -133,6 +149,7 @@ protected void cleanUp() {
_label = "display-template";
_refreshURL = null;
_showEmptyOption = false;
_servletContext = null;
}

@Override
Expand All @@ -151,6 +168,7 @@ protected void setAttributes(HttpServletRequest request) {
setNamespacedAttribute(request, "label", _label);
setNamespacedAttribute(request, "refreshURL", _refreshURL);
setNamespacedAttribute(request, "showEmptyOption", _showEmptyOption);
setNamespacedAttribute(request, "servletContext", _servletContext);
}

protected static final String _ATTRIBUTE_NAMESPACE = "ddm:template-selector:";
Expand All @@ -167,5 +185,6 @@ protected void setAttributes(HttpServletRequest request) {
private java.lang.String _label = "display-template";
private java.lang.String _refreshURL = null;
private boolean _showEmptyOption = false;
private java.lang.Object _servletContext = null;

}
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.dynamic.data.mapping.taglib.util;

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;

/**
* @author Leonardo Barros
*/
@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=com.liferay.dynamic.data.mapping.taglib)",
unbind = "-"
)
protected void setServletContext(ServletContext servletContext) {
_servletContext = servletContext;
}

private ServletContext _getServletContext() {
return _servletContext;
}

private static ServletContextUtil _instance;

private ServletContext _servletContext;

}

0 comments on commit 3bb88f4

Please sign in to comment.