Subversion Repositories bacoAlunos

Compare Revisions

Ignore whitespace Rev 278 → Rev 279

/impl/conf/WEB-INF/web.xml
13,6 → 13,10
<filter-class>pt.estgp.estgweb.web.filters.UserSessionFilter</filter-class>
</filter>
<filter>
<filter-name>TopImageFilter</filter-name>
<filter-class>pt.estgp.estgweb.web.filters.TopImageFilter</filter-class>
</filter>
<filter>
<filter-name>UserFilter</filter-name>
<filter-class>pt.estgp.estgweb.web.filters.UserFilter</filter-class>
</filter>
42,6 → 46,10
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>TopImageFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>Set-Character-Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
/impl/conf/app.properties
70,9 → 70,10
ionline.pass=baco
ionline.user=Baco_web
 
server.estgp=http://localhost:8080
server.estgp=http://www.estgp.pt
estgp.encoding=ISO-8859-1
server.estgp.start.path=/templates
#server.estgp.start.path=/templates
server.estgp.start.path=/testes/nova_web
 
#server.estgp=http://www.estgp.pt/testes/nova_web
#estgp.encoding=UTF-8
326,3 → 327,19
 
 
 
#########################################################################
#
#TopImage Filter Links
#
 
top.image.1.start.with=/
top.image.1=/imgs/top.jpg
 
top.image.start.with.2=/student.do?role=student&menu=menu.alunos
top.image.url.2=/imgs/topStudents.jpg
 
 
 
 
 
 
/impl/src/java/pt/estgp/estgweb/Globals.java
86,6 → 86,10
public static final List<String> FILTER_IGNORE_EXTENSIONS = ConfigProperties.getListValues("filter.ignore.extension");
public static final List<String> FILTER_IGNORE_PREFIXES = ConfigProperties.getListValues("filter.ignore.prefix");
 
public static final List<String> TOP_IMAGE_FILTER_LINKS = ConfigProperties.getListValues("top.image.start.with");
public static final List<String> TOP_IMAGE_FILTER_IMAGES_URL = ConfigProperties.getListValues("top.image.url");
 
 
public static final String SITE_URL = ConfigProperties.getProperty("site.url");
 
public static final String INTRANET_MESSAGES_PREFIX = "intranet.";
/impl/src/java/pt/estgp/estgweb/web/utils/ProxyUtils.java
1,6 → 1,12
package pt.estgp.estgweb.web.utils;
 
import org.apache.log4j.Logger;
import pt.estgp.estgweb.Globals;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
 
/**
* @author Jorge Machado
10,10 → 16,74
public class ProxyUtils
{
// proxy/accaoSocialAlunosPortalMenu/estgp
private static final Logger logger = Logger.getLogger(ProxyUtils.class);
 
public static String getTopImageLink(HttpServletRequest request)
{
System.out.println(request.getPathInfo());
String pathIfo = request.getPathInfo();
String queryString = request.getQueryString();
 
if(request.getServletPath().equals("/proxy"))
{
String finalFileCandidate1 = pathIfo.substring(0,pathIfo.lastIndexOf("/")) + "/top.jpg";
String finalFileCandidate2 = pathIfo.substring(0,pathIfo.lastIndexOf(".")) + ".jpg";
 
String protocol = request.getRequestURL().substring(0,request.getRequestURL().indexOf("://"));
String finalFileCandidate1total = protocol + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/proxy" + finalFileCandidate1;
String finalFileCandidate2total = protocol + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/proxy" + finalFileCandidate2;
 
try
{
URL url = new URL(finalFileCandidate2total);
url.openConnection().getInputStream();
return request.getContextPath() + "/proxy" + finalFileCandidate2;
}
catch (MalformedURLException e)
{
logger.error("BAD TOP IMAGE URL 2: " + finalFileCandidate2total);
}
catch (IOException e)
{
logger.debug("candidate 2 don't exist: " + finalFileCandidate2total);
}
 
try
{
URL url = new URL(finalFileCandidate1total);
url.openConnection().getInputStream();
return request.getContextPath() + "/proxy" + finalFileCandidate1;
}
catch (MalformedURLException e)
{
logger.error("BAD TOP IMAGE URL 1: " + finalFileCandidate1total);
}
catch (IOException e)
{
logger.debug("candidate 1 don't exist: " + finalFileCandidate1total);
}
}
else
{
String link = request.getServletPath();
if(pathIfo!=null)
link+= pathIfo;
if(queryString!=null)
link+= "?" + queryString;
 
 
for(int i = 0; i < Globals.TOP_IMAGE_FILTER_LINKS.size();i++)
{
String url = Globals.TOP_IMAGE_FILTER_LINKS.get(i);
if(link.startsWith(url))
{
String finalUrl = Globals.TOP_IMAGE_FILTER_IMAGES_URL.get(i);
if(finalUrl.startsWith("/"))
return request.getContextPath() + finalUrl;
else
return finalUrl;
}
}
}
return null;
}
}
/impl/src/java/pt/estgp/estgweb/web/filters/TopImageFilter.java
New file
0,0 → 1,79
package pt.estgp.estgweb.web.filters;
 
import pt.estgp.estgweb.Globals;
import pt.estgp.estgweb.web.utils.RequestUtils;
import pt.estgp.estgweb.web.utils.ProxyUtils;
 
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.io.IOException;
 
/**
*
* @author Jorge Machado
*/
 
public class TopImageFilter implements Filter
{
 
public static final String TOP_IMAGE = "TOP_IMAGE";
 
public TopImageFilter()
{
}
 
public void init(FilterConfig config)
{
 
}
 
/**
*
* @param request The servlet request we are processing
* @param chain The filter chain we are processing
*
* @exception java.io.IOException if an input/output error occurs
* @exception javax.servlet.ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest hrequest = (HttpServletRequest) request;
String relativePath = hrequest.getServletPath();
if (relativePath == null)
relativePath = "";
 
if (hrequest.getPathInfo() != null && hrequest.getPathInfo().length() > 0)
{
relativePath += hrequest.getPathInfo();
}
 
for (String ignore : Globals.FILTER_IGNORE_EXTENSIONS)
{
if (relativePath.endsWith(ignore))
{
chain.doFilter(request, response);
return;
}
}
for (String ignore : Globals.FILTER_IGNORE_PREFIXES)
{
if (relativePath.startsWith(ignore))
{
chain.doFilter(request, response);
return;
}
}
 
String link = ProxyUtils.getTopImageLink((HttpServletRequest) request);
request.setAttribute(TOP_IMAGE,link);
chain.doFilter(request,response);
}
 
public void destroy()
{
// Nothing
}
}
/impl/src/web/layout/header.jsp
1,4 → 1,5
<%@ page import="pt.estgp.estgweb.web.utils.ProxyUtils" %>
<%@ page import="pt.estgp.estgweb.web.filters.TopImageFilter" %>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %>
10,8 → 11,8
<td>
 
<%
String link = ProxyUtils.getTopImageLink(request);
if(link == null)
String link = (String) request.getAttribute(TopImageFilter.TOP_IMAGE);
if (link == null)
{
%>
<img alt="estg" src="<%=request.getContextPath()%>/imgs/top.jpg"/>
24,8 → 25,6
<%
}
%>
 
<img alt="estg" src="<%=request.getContextPath()%>/imgs/top.jpg"/>
</td>
</tr>
</table>