Skip to content

Commit

Permalink
LEP-2493
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.liferay.com/repos/public/portal/trunk@5314 05bdf26c-840f-0410-9ced-eb539d925f36
  • Loading branch information
brianchandotcom committed Mar 30, 2007
1 parent 8161e76 commit 8070d82
Show file tree
Hide file tree
Showing 28 changed files with 1,184 additions and 111 deletions.
46 changes: 43 additions & 3 deletions definitions/liferay-look-and-feel_4_3_0.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
This is the DTD for the Look and Feel parameters for Liferay Portal.

<!DOCTYPE look-and-feel PUBLIC
"-//Liferay//DTD Look and Feel 4.0.0//EN"
"http://www.liferay.com/dtd/liferay-look-and-feel_4_0_0.dtd">
"-//Liferay//DTD Look and Feel 4.3.0//EN"
"http://www.liferay.com/dtd/liferay-look-and-feel_4_3_0.dtd">
-->

<!--
The look-and-feel element is the root of the deployment descriptor for
a Liferay look and feel archive. The look and feel archive will hereafter
be referred to as a LAF archive.
-->
<!ELEMENT look-and-feel (compatibility, company-limit?, theme*)>
<!ELEMENT look-and-feel (compatibility, company-limit?, group-limit?, theme*)>

<!--
The compatibility element specifies a list of Liferay Portal versions that will
Expand Down Expand Up @@ -68,6 +68,46 @@ See the comments in the company-id element.
pattern CDATA #IMPLIED
>

<!--
The group-limit element specifies a list of group ids that can access the themes
in this LAF archive. If group-limit is not set, then every group in the portal
has access to all of the themes in this LAF archive. If group-limit is set, then
the group ids will be included or excluded based on the group-includes and
group-excludes elements. If there is a disagreement between group-includes and
group-excludes, group-excludes takes precedence.
-->
<!ELEMENT group-limit (group-includes?, group-excludes?)>

<!--
The group-includes element specifies a list of group ids that will have access
to the themes in this LAF archive.
-->
<!ELEMENT group-includes (group-id*)>

<!--
The group-excludes element specifies a list of group ids that will not have
access to the themes in this LAF archive.
-->
<!ELEMENT group-excludes (group-id*)>

<!--
The group-id element must have either the name or pattern attributes specified.
If the name attribute is specified, then the exact group id is either included
or excluded, depending on whether the group-id element is inside the
group-includes element or group-excludes element. If the pattern attribute is
specified, then a regular expression match is applied to the pattern which will
determine whether a group id is included or excluded.
-->
<!ELEMENT group-id (#PCDATA)>

<!--
See the comments in the group-id element.
-->
<!ATTLIST group-id
name CDATA #IMPLIED
pattern CDATA #IMPLIED
>

<!--
The theme element contains the declarative data of a theme.
-->
Expand Down
8 changes: 8 additions & 0 deletions portal-ejb/classes/META-INF/portal-log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<priority value="INFO" />
</category>

<category name="com.liferay.portal.deploy.hot.ThemeLoaderHotDeployListener">
<priority value="DEBUG" />
</category>

<category name="com.liferay.portal.editor">
<priority value="ERROR" />
</category>
Expand Down Expand Up @@ -260,6 +264,10 @@
<priority value="ERROR" />
</category>

<category name="com.liferay.portal.theme.ThemeLoader">
<priority value="DEBUG" />
</category>

<category name="com.liferay.portal.upgrade">
<priority value="INFO" />
</category>
Expand Down
3 changes: 2 additions & 1 deletion portal-ejb/classes/portal.properties
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@
com.liferay.portal.deploy.hot.PluginPackageHotDeployListener,\
com.liferay.portal.deploy.hot.LayoutTemplateHotDeployListener,\
com.liferay.portal.deploy.hot.PortletHotDeployListener,\
com.liferay.portal.deploy.hot.ThemeHotDeployListener
com.liferay.portal.deploy.hot.ThemeHotDeployListener,\
com.liferay.portal.deploy.hot.ThemeLoaderHotDeployListener

##
## Plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.liferay.portal.deploy.hot;

import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
import com.liferay.portal.kernel.deploy.hot.HotDeployException;
import com.liferay.portal.kernel.deploy.hot.HotDeployListener;
import com.liferay.portal.theme.ThemeLoader;
import com.liferay.portal.velocity.VelocityContextPool;
import com.liferay.util.Http;

import javax.servlet.ServletContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* <a href="ThemeLoaderHotDeployListener.java.html"><b><i>View Source</i></b>
* </a>
*
* @author Brian Wing Shun Chan
*
*/
public class ThemeLoaderHotDeployListener implements HotDeployListener {

public void invokeDeploy(HotDeployEvent event) throws HotDeployException {
String servletContextName = null;

try {
ServletContext ctx = event.getServletContext();

servletContextName = ctx.getServletContextName();

if (_log.isDebugEnabled()) {
_log.debug("Invoking deploy for " + servletContextName);
}

String[] xmls = new String[] {
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-theme-loader.txt"))
};

if (xmls[0] == null) {
return;
}

if (_log.isInfoEnabled()) {
_log.info("Registering theme loader for " + servletContextName);
}

ThemeLoader.init(servletContextName, ctx);
}
catch (Exception e) {
throw new HotDeployException(
"Error registering theme loader for " + servletContextName, e);
}
}

public void invokeUndeploy(HotDeployEvent event) throws HotDeployException {
String servletContextName = null;

try {
ServletContext ctx = event.getServletContext();

servletContextName = ctx.getServletContextName();

if (_log.isDebugEnabled()) {
_log.debug("Invoking undeploy for " + servletContextName);
}

boolean value = ThemeLoader.destroy(servletContextName);

if (value) {
if (_log.isInfoEnabled()) {
_log.info(
"Unregistering theme loader for " + servletContextName);
}

VelocityContextPool.remove(servletContextName);

if (_log.isInfoEnabled()) {
_log.info(
"Theme loader for " + servletContextName +
" unregistered successfully");
}
}
}
catch (Exception e2) {
throw new HotDeployException(
"Error unregistering theme loader for " + servletContextName,
e2);
}
}

private static Log _log =
LogFactory.getLog(ThemeLoaderHotDeployListener.class);

}
105 changes: 105 additions & 0 deletions portal-ejb/src/com/liferay/portal/model/impl/ThemeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.Theme;
import com.liferay.portal.theme.ThemeCompanyLimit;
import com.liferay.portal.theme.ThemeGroupLimit;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.util.PropsUtil;
import com.liferay.util.ListUtil;
Expand All @@ -35,6 +37,9 @@
import java.util.Map;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* <a href="ThemeImpl.java.html"><b><i>View Source</i></b></a>
*
Expand Down Expand Up @@ -74,6 +79,30 @@ public String getPluginType() {
return PLUGIN_TYPE;
}

public ThemeCompanyLimit getThemeCompanyLimit() {
return _themeCompanyLimit;
}

public void setThemeCompanyLimit(ThemeCompanyLimit themeCompanyLimit) {
_themeCompanyLimit = themeCompanyLimit;
}

public boolean isCompanyAvailable(String companyId) {
return isAvailable(getThemeCompanyLimit(), companyId);
}

public ThemeGroupLimit getThemeGroupLimit() {
return _themeGroupLimit;
}

public void setThemeGroupLimit(ThemeGroupLimit themeGroupLimit) {
_themeGroupLimit = themeGroupLimit;
}

public boolean isGroupAvailable(long groupId) {
return isAvailable(getThemeGroupLimit(), String.valueOf(groupId));
}

public String getName() {
return _name;
}
Expand Down Expand Up @@ -226,7 +255,83 @@ public boolean equals(Object obj) {
}
}

protected boolean isAvailable(ThemeCompanyLimit limit, String id) {
boolean available = true;

if (_log.isDebugEnabled()) {
_log.debug(
"Check if theme " + getThemeId() + " is available for " + id);
}

if (limit != null) {
List includes = limit.getIncludes();
List excludes = limit.getExcludes();

if ((includes.size() != 0) && (excludes.size() != 0)) {

// Since includes and excludes are specified, check to
// make sure the current company id is included and also
// not excluded

if (_log.isDebugEnabled()) {
_log.debug("Check includes and excludes");
}

available = limit.isIncluded(id);

if (available) {
available = !limit.isExcluded(id);
}
}
else if ((includes.size() == 0) && (excludes.size() != 0)) {

// Since no includes are specified, check to make sure
// the current company id is not excluded

if (_log.isDebugEnabled()) {
_log.debug("Check excludes");
}

available = !limit.isExcluded(id);
}
else if ((includes.size() != 0) && (excludes.size() == 0)) {

// Since no excludes are specified, check to make sure
// the current company id is included

if (_log.isDebugEnabled()) {
_log.debug("Check includes");
}

available = limit.isIncluded(id);
}
else {

// Since no includes or excludes are specified, this
// theme is available for every company

if (_log.isDebugEnabled()) {
_log.debug("No includes or excludes set");
}

available = true;
}
}

if (_log.isDebugEnabled()) {
_log.debug(
"Theme " + getThemeId() + " is " +
(!available ? "NOT " : "") + "available for " + id);
}

return available;
}

private static Log _log = LogFactory.getLog(ThemeImpl.class);

private String _themeId;
private ThemeCompanyLimit _themeCompanyLimit;
private ThemeGroupLimit _themeGroupLimit;
private String _name;
private String _rootPath = "/";
private String _templatesPath = "${root-path}/templates";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* <a href="LocalPluginPackageRepository.java.html"><b><i>View Source</i></b>
* </a>
Expand All @@ -48,9 +51,11 @@ public LocalPluginPackageRepository() {

public void addPluginPackage(PluginPackage pluginPackage) {
if (pluginPackage.getContext() == null) {
System.out.println(
"Plugin package cannot be registered because it does not have" +
"an installation context");
if (_log.isDebugEnabled()) {
_log.debug(
"Plugin package cannot be registered because it does not " +
"have an installation context");
}

return;
}
Expand Down Expand Up @@ -174,6 +179,9 @@ public void unregisterPluginPackageInstallation(String context) {
_pendingPackages.remove(context);
}

private static Log _log =
LogFactory.getLog(LocalPluginPackageRepository.class);

private Map _pluginPackages = new HashMap();
private Map _pendingPackages = new HashMap();

Expand Down
Loading

0 comments on commit 8070d82

Please sign in to comment.