Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed Mar 16, 2023
2 parents 4a6e01a + 67ef479 commit a61210b
Show file tree
Hide file tree
Showing 2,373 changed files with 61,645 additions and 36,418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
package org.exoplatform.resolver;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import javax.portlet.PortletContext;
import javax.servlet.ServletContext;

import org.exoplatform.container.PortalContainer;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

Expand All @@ -35,71 +38,127 @@
*/
public class PortletResourceResolver extends ResourceResolver {

protected static Log log = ExoLogger.getLogger(PortletResourceResolver.class);
protected static Log log = ExoLogger.getLogger(PortletResourceResolver.class);

private PortletContext pcontext_;
private ServletContext portalContext;

private String scheme_;
private PortletContext portletContext;

public PortletResourceResolver(PortletContext context, String scheme) {
pcontext_ = context;
scheme_ = scheme;
}

public URL getResource(String url) throws Exception {
String path = removeScheme(url);
return pcontext_.getResource(path);
}

public InputStream getInputStream(String url) throws Exception {
String path = removeScheme(url);
return pcontext_.getResourceAsStream(path);
}

public List<URL> getResources(String url) throws Exception {
ArrayList<URL> urlList = new ArrayList<URL>();
urlList.add(getResource(url));
return urlList;
}
private String scheme;

public List<InputStream> getInputStreams(String url) throws Exception {
ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
inputStreams.add(getInputStream(url));
return inputStreams;
}
public PortletResourceResolver(PortletContext context, String scheme) {
this.portletContext = context;
this.scheme = scheme;
}

public String getRealPath(String url) {
String path = removeScheme(url);
return pcontext_.getRealPath(path);
@Override
public URL getResource(String url) throws Exception {
ServletContext portalContextResolver = getPortalContext();
if (portalContextResolver != null) {
String relativePath = removeScheme(url);
URL res = portalContextResolver.getResource(relativePath);
if (res != null) {
return res;
}
}

public boolean isModified(String url, long lastAccess) {
try {
URL uri = getResource(url);
URLConnection con = uri.openConnection();
if (log.isDebugEnabled())
log.debug(url + ": " + con.getLastModified() + " " + lastAccess);
if (con.getLastModified() > lastAccess) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
return getPortletResource(url);
}

@Override
public InputStream getInputStream(String url) throws Exception {
ServletContext portalContextResolver = getPortalContext();
if (portalContextResolver != null) {
String relativePath = removeScheme(url);
InputStream inputStream = portalContextResolver.getResourceAsStream(relativePath);
if (inputStream != null) {
return inputStream;
}
}

public String getWebAccessPath(String url) {
return "/" + pcontext_.getPortletContextName() + removeScheme(url);
return getPortletInputStream(url);
}

@Override
public String getRealPath(String url) {
ServletContext portalContextResolver = getPortalContext();
if (portalContextResolver != null) {
String relativePath = removeScheme(url);
String path = portalContextResolver.getRealPath(relativePath);
if (path != null) {
return path;
}
}

public String getResourceScheme() {
return scheme_;
return getPortletRealPath(url);
}

@Override
public List<URL> getResources(String url) throws Exception {
ArrayList<URL> urlList = new ArrayList<>();
urlList.add(getResource(url));
return urlList;
}

@Override
public List<InputStream> getInputStreams(String url) throws Exception {
ArrayList<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(getInputStream(url));
return inputStreams;
}

@Override
public boolean isModified(String url, long lastAccess) {
try {
URL uri = getResource(url);
URLConnection con = uri.openConnection();
if (log.isDebugEnabled())
log.debug(url + ": " + con.getLastModified() + " " + lastAccess);
if (con.getLastModified() > lastAccess) {
return true;
}
} catch (Exception e) {
return false;
}

@Override
public ResourceKey createResourceKey(String url) {
String portletContextName = pcontext_.getPortletContextName();
int resolverId = portletContextName != null ? portletContextName.hashCode() : hashCode();
return new ResourceKey(resolverId, url);
return false;
}

@Override
public String getWebAccessPath(String url) {
return "/" + portletContext.getPortletContextName() + removeScheme(url);
}

@Override
public String getResourceScheme() {
return scheme;
}

@Override
public ResourceKey createResourceKey(String url) {
String portletContextName = portletContext.getPortletContextName();
int resolverId = portletContextName != null ? portletContextName.hashCode() : hashCode();
return new ResourceKey(resolverId, url);
}

private URL getPortletResource(String url) throws MalformedURLException {
String path = removeScheme(url);
return portletContext.getResource(path);
}

private InputStream getPortletInputStream(String url) {
String path = removeScheme(url);
return portletContext.getResourceAsStream(path);
}

private String getPortletRealPath(String url) {
String path = removeScheme(url);
return portletContext.getRealPath(path);
}

private ServletContext getPortalContext() {
if (portalContext == null) {
PortalContainer container = PortalContainer.getInstanceIfPresent();
if (container != null) {
portalContext = container.getPortalContext();
}
}
return portalContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@

import java.io.Serializable;

import lombok.ToString;


/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
@ToString
public class ResourceKey implements Serializable {

private static final long serialVersionUID = -51562811492603221L;

/** . */
private final int resolverId;

Expand Down Expand Up @@ -62,4 +67,5 @@ public boolean equals(Object o) {
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Staff</title>
Expand All @@ -50,7 +50,7 @@
<edit-permission>manager:/organization/management/executive-board</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>OrganizationPortlet</portlet-ref>
</portlet>
<title>Organization Management</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Account</title>
Expand All @@ -48,7 +48,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>OrganizationPortlet</portlet-ref>
</portlet>
<title>Community Management</title>
Expand All @@ -64,7 +64,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>ApplicationRegistryPortlet</portlet-ref>
</portlet>
<title>Application Registry</title>
Expand All @@ -80,7 +80,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>PageManagementPortlet</portlet-ref>
</portlet>
<title>Page Management</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<edit-permission>*:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Account</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<preferences>
<preference>
<name>url</name>
<value>/eXoResources/skin/sharedImages/GroupIcon.png</value>
<value>/resources/skin/sharedImages/GroupIcon.png</value>
<read-only>false</read-only>
</preference>
</preferences>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<edit-permission>*:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
<preferences>
<preference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<container template="system:/groovy/portal/webui/container/UIContainer.gtmpl">
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Account</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<access-permissions>Everyone</access-permissions>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>ApplicationRegistryPortlet</portlet-ref>
</portlet>
<theme>Default:DefaultTheme::Mac:MacTheme::Vista:VistaTheme</theme>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<factory-id>ColumnContainer</factory-id>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<theme>Default:DefaultTheme::Vista:VistaTheme::Mac:MacTheme</theme>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<edit-permission>manager:/organization/management/executive-board</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Staff</title>
Expand All @@ -48,7 +48,7 @@
<edit-permission>manager:/organization/management/executive-board</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>OrganizationPortlet</portlet-ref>
</portlet>
<title>Organization Management</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Account</title>
Expand All @@ -48,7 +48,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>OrganizationPortlet</portlet-ref>
</portlet>
<title>Community Management</title>
Expand All @@ -64,7 +64,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>ApplicationRegistryPortlet</portlet-ref>
</portlet>
<title>Application Registry</title>
Expand All @@ -80,7 +80,7 @@
<edit-permission>manager:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>PageManagementPortlet</portlet-ref>
</portlet>
<title>Page Management</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<edit-permission>*:/platform/administrators</edit-permission>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<application-ref>portletapplication</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<title>New Account</title>
Expand Down

0 comments on commit a61210b

Please sign in to comment.