/impl/conf/directories/directory.xsd |
---|
38,6 → 38,22 |
<xs:documentation>Grouping purposes in styling</xs:documentation> |
</xs:annotation> |
</xs:attribute> |
<xs:attribute name="showNav" type="xs:boolean" use="optional"> |
<xs:annotation> |
<xs:documentation>Show link to this node in navigation menus, true by default</xs:documentation> |
</xs:annotation> |
</xs:attribute> |
<xs:attribute name="type" use="optional"> |
<xs:annotation> |
<xs:documentation>Type of node, by default HTTP link</xs:documentation> |
</xs:annotation> |
<xs:simpleType> |
<xs:restriction base="xs:string"> |
<xs:enumeration value="ftp"/> |
<xs:enumeration value="http"/> |
</xs:restriction> |
</xs:simpleType> |
</xs:attribute> |
<xs:attribute name="id" type="xs:ID" use="required"/> |
</xs:complexType> |
<xs:complexType name="leafT"> |
45,6 → 61,13 |
<xs:documentation>A leaf is an URL for an external or internal WEB site</xs:documentation> |
</xs:annotation> |
<xs:sequence> |
<xs:choice minOccurs="0" maxOccurs="unbounded"> |
<xs:annotation> |
<xs:documentation>A leaf can be a root of some diferent system like FTP server Directory</xs:documentation> |
</xs:annotation> |
<xs:element name="node" type="nodeT"/> |
<xs:element name="leaf" type="leafT"/> |
</xs:choice> |
<xs:element name="rights" type="rightsT" minOccurs="0"/> |
</xs:sequence> |
<xs:attribute name="url" type="xs:string" use="required"/> |
81,6 → 104,33 |
<xs:documentation>Grouping purposes in styling</xs:documentation> |
</xs:annotation> |
</xs:attribute> |
<xs:attribute name="ftpDirectory" type="xs:boolean"/> |
<xs:attribute name="size" use="optional"> |
<xs:annotation> |
<xs:documentation>Size of content in Kb</xs:documentation> |
</xs:annotation> |
</xs:attribute> |
<xs:attribute name="mimeType" use="optional"> |
<xs:annotation> |
<xs:documentation>Mime Type of content in Kb</xs:documentation> |
</xs:annotation> |
</xs:attribute> |
<xs:attribute name="lastModification" use="optional"> |
<xs:annotation> |
<xs:documentation>Last Modification of content in Kb</xs:documentation> |
</xs:annotation> |
</xs:attribute> |
<xs:attribute name="visualization" use="optional"> |
<xs:annotation> |
<xs:documentation>Type of node, by default HTTP link</xs:documentation> |
</xs:annotation> |
<xs:simpleType> |
<xs:restriction base="xs:string"> |
<xs:enumeration value="filesystem"/> |
<xs:enumeration value="normal"/> |
</xs:restriction> |
</xs:simpleType> |
</xs:attribute> |
</xs:complexType> |
<xs:complexType name="groupDeclarationT"> |
<xs:sequence> |
/impl/conf/directories/style1.xsl |
---|
10,7 → 10,8 |
<xsl:param name="roles">professor,administrador</xsl:param> |
<!--<xsl:param name="ACTUAL">pagina_a1.2.1</xsl:param>--> |
<!--<xsl:param name="ACTUAL">ficha_trabalhoIncluido</xsl:param>--> |
<xsl:param name="ACTUAL">pagina_teste.html</xsl:param> |
<xsl:param name="ACTUAL">ionline</xsl:param> |
<xsl:param name="ACTUAL_REMOTE_CHILD"></xsl:param> |
<xsl:param name="includeXML">oai_dc.xml</xsl:param> |
<xsl:template match="/"> |
380,12 → 381,77 |
<xsl:apply-templates select=".." mode="latNav"/> |
</td> |
<td class="contentPortal"> |
<xsl:apply-templates select="." mode="bodyContent"/> |
<xsl:choose> |
<xsl:when test="not(./d:leaf)"> |
<xsl:apply-templates select="." mode="bodyContent"/> |
</xsl:when> |
<xsl:otherwise> |
<xsl:choose> |
<xsl:when test="//*[@id=$ACTUAL_REMOTE_CHILD]"> |
<xsl:apply-templates select="//*[@id=$ACTUAL_REMOTE_CHILD]" mode="remoteChildsContent"/> |
</xsl:when> |
<xsl:otherwise> |
<xsl:apply-templates select="." mode="remoteChildsContent"/> |
</xsl:otherwise> |
</xsl:choose> |
</xsl:otherwise> |
</xsl:choose> |
</td> |
</tr> |
</table> |
</xsl:template> |
<xsl:template match="d:node" mode="remoteChildsContent"> |
<xsl:apply-templates select="." mode="topNavRemote"/> |
</xsl:template> |
<xsl:template match="d:leaf" mode="remoteChildsContent"> |
<xsl:apply-templates select="." mode="topNavRemote"/> |
<div class="files"> |
<table cellpadding="0" cellspacing="0"> |
<tr> |
<th> |
Nome do ficheiro/pasta |
</th> |
<th> |
Data de Modificação |
</th> |
<th> |
Tamanho |
</th> |
</tr> |
<xsl:apply-templates select="./d:leaf[@d:ftpDirectory='true']" mode="ftpLine"/> |
<xsl:apply-templates select="./d:leaf[@d:ftpDirectory='false']" mode="ftpLine"/> |
</table> |
</div> |
</xsl:template> |
<xsl:template match="d:leaf" mode="ftpLine"> |
<xsl:choose> |
<xsl:when test="./@d:ftpDirectory='true'"> |
<tr> |
<td colspan="3"> |
<img> |
<xsl:attribute name="src"><xsl:value-of select="$contextPath"/>/imgs/folder.gif</xsl:attribute> |
</img> |
<xsl:value-of select="@d:label"/> |
</td> |
</tr> |
</xsl:when> |
<xsl:otherwise> |
<tr> |
<td> |
<xsl:value-of select="./@d:label"/> |
</td> |
<td> |
<xsl:value-of select="./@d:lastModification"/> |
</td> |
<td> |
<xsl:value-of select="./@d:size"/> |
</td> |
</tr> |
</xsl:otherwise> |
</xsl:choose> |
</xsl:template> |
<!--<xsl:function name="d:parse" as="document-node()"> |
<xsl:param name="s" as="xs:string"/> |
<xsl:sequence select="doc(concat('data:text/xml','<ola>teste</ola>'))"/> |
439,7 → 505,29 |
</div>--> |
</xsl:template> |
<xsl:template match="d:leaf" mode="topNavRemote"> |
<div id="topnav"> |
<ul> |
<li class="navPlace"> |
raiz |
</li> |
</ul> |
</div> |
</xsl:template> |
<xsl:template match="d:node" mode="topNavRemote"> |
<div id="topnav"> |
<ul> |
<xsl:apply-templates select=".." mode="navBackRemote"/> |
<li class="navPlace"> |
> |
<xsl:apply-templates select="." mode="label"/> |
</li> |
</ul> |
</div> |
</xsl:template> |
<xsl:template match="d:directory" mode="navBack"> |
<li class="navPlace"> |
<xsl:call-template name="homeLink"/> |
459,6 → 547,21 |
</li> |
</xsl:template> |
<xsl:template match="d:leaf" mode="navBackRemote"> |
<li class="navPlace"> |
> |
<xsl:apply-templates select="." mode="link"/> |
</li> |
</xsl:template> |
<xsl:template match="d:node" mode="navBackRemote"> |
<xsl:apply-templates select=".." mode="navBack"/> |
<li class="navPlace"> |
> |
<xsl:apply-templates select="." mode="link"/> |
</li> |
</xsl:template> |
<!-- |
=========================================================== |
| Barra de Navegação Lateral Esquerda |
/impl/src/java/jomm/web/ftp/impl/FtpFile.java |
---|
141,4 → 141,18 |
} |
return navPlaces; |
} |
public static List<IFile> init(FTPFile[] files, String server, String path) throws URIException |
{ |
List<IFile> iFiles = new ArrayList<IFile>(); |
for (FTPFile ftpFile : files) |
{ |
IFile iFile; |
if (path.endsWith("/")) |
iFile = new FtpFile(ftpFile, server + URIUtil.encodePath(path +ftpFile.getName(),"ISO-8859-1"), path); |
else iFile = new FtpFile(ftpFile, server + URIUtil.encodePath(path + "/" + ftpFile.getName(),"ISO-8859-1"), path); |
iFiles.add(iFile); |
} |
return iFiles; |
} |
} |
/impl/src/java/pt/estgp/estgweb/utils/Dom4jUtil.java |
---|
13,6 → 13,7 |
import java.net.URL; |
import java.util.Hashtable; |
import java.util.Map; |
import java.util.HashMap; |
import pt.estgp.estgweb.Globals; |
import javax.xml.transform.TransformerFactory; |
65,9 → 66,51 |
}); |
} |
private static Map<String,byte[]> sourceXmls = new HashMap<String,byte[]>(); |
/** |
* Search for Source Document in cache |
* |
* @param file in src tree |
* @return bytes |
* @throws java.io.IOException on read error |
*/ |
public static byte[] getSourceFile(String file) throws IOException |
{ |
byte[] bytes; |
if((bytes = sourceXmls.get(file)) != null) |
{ |
return bytes; |
} |
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); |
ByteArrayOutputStream output = new ByteArrayOutputStream(); |
int read; |
byte[] buffer = new byte[1024]; |
while((read = stream.read(buffer)) > 0) |
{ |
output.write(buffer,0,read); |
} |
output.close(); |
stream.close(); |
bytes = output.toByteArray(); |
sourceXmls.put(file, bytes); |
return bytes; |
} |
public static Document parseSourceFileFromCache(String file) throws DocumentException, IOException |
{ |
byte[] bytes = getSourceFile(file); |
SAXReader reader = new SAXReader(); |
reader.setValidation(false); |
createIgnoreErrorHandler(reader); |
return reader.read(new ByteArrayInputStream(bytes)); |
} |
public static Document parseSourceFile(String file) throws DocumentException, IOException |
{ |
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); |
SAXReader reader = new SAXReader(); |
reader.setValidation(false); |
createIgnoreErrorHandler(reader); |
/impl/src/java/pt/estgp/estgweb/services/common/impl/DefaultResult.java |
---|
11,6 → 11,7 |
public class DefaultResult implements IResult |
{ |
private String title; |
private String subTitle; |
21,8 → 22,10 |
private boolean subTitleKey = false; |
private boolean textKey = false; |
private LabelGroup subTitlesGroup = null; |
public DefaultResult() { |
} |
90,4 → 93,15 |
public void setSubTitleKey(boolean subTitleKey) { |
this.subTitleKey = subTitleKey; |
} |
public LabelGroup getSubTitlesGroup() |
{ |
return subTitlesGroup; |
} |
public void setSubTitlesGroup(LabelGroup subTitlesGroup) |
{ |
this.subTitlesGroup = subTitlesGroup; |
} |
} |
/impl/src/java/pt/estgp/estgweb/services/common/IResult.java |
---|
1,5 → 1,8 |
package pt.estgp.estgweb.services.common; |
import java.util.List; |
import java.util.ArrayList; |
/** |
* @author Jorge Machado |
* @date 24/Abr/2008 |
16,4 → 19,85 |
public String getText(); |
public boolean isTextKey(); |
public String getUrl(); |
public LabelGroup getSubTitlesGroup(); |
/** |
* Class to support groups of labels |
* usefull to add groups of message keys |
*/ |
public static class LabelGroup |
{ |
private String title; |
private boolean key; |
private List<Label> labels; |
public LabelGroup() |
{ |
labels = new ArrayList<Label>(); |
} |
public List<Label> getLabels() |
{ |
return labels; |
} |
public void setLabels(List<Label> labels) |
{ |
this.labels = labels; |
} |
public String getTitle() |
{ |
return title; |
} |
public void setTitle(String title) |
{ |
this.title = title; |
} |
public boolean isKey() |
{ |
return key; |
} |
public void setKey(boolean key) |
{ |
this.key = key; |
} |
} |
public static class Label |
{ |
private String label; |
private boolean key; |
public Label(String label, boolean key) |
{ |
this.label = label; |
this.key = key; |
} |
public String getLabel() |
{ |
return label; |
} |
public void setLabel(String label) |
{ |
this.label = label; |
} |
public boolean isKey() |
{ |
return key; |
} |
public void setKey(boolean key) |
{ |
this.key = key; |
} |
} |
} |
/impl/src/java/pt/estgp/estgweb/services/profile/ProfileCommonServices.java |
---|
8,6 → 8,7 |
import pt.estgp.estgweb.services.courseunits.CourseUnitsCommonServices; |
import pt.estgp.estgweb.domain.*; |
import pt.estgp.estgweb.domain.dao.DaoFactory; |
import pt.estgp.estgweb.Globals; |
import org.apache.log4j.Logger; |
import java.util.List; |
57,6 → 58,25 |
{ |
DefaultResult defaultResult = new DefaultResult(); |
defaultResult.setTitle(u.getName()); |
defaultResult.setSubTitleKey(true); |
if(u.hasRole(Globals.TEACHER_ROLE)) |
{ |
defaultResult.setSubTitle("user.role." + Globals.TEACHER_ROLE); |
} |
else if(u.hasRole(Globals.STUDENT_ROLE)) |
{ |
defaultResult.setSubTitle("user.role." + Globals.STUDENT_ROLE); |
}else if(u.isSuperuser()) |
{ |
defaultResult.setSubTitle("superuser"); |
} |
else if(u.isAdmin()) |
{ |
defaultResult.setSubTitle("user.role." + Globals.ADMIN_ROLE); |
} |
if (from == null) |
defaultResult.setUrl("/startProfile.do?userView.id=" + u.getId()); |
else |
/impl/src/java/pt/estgp/estgweb/domain/GenericUserImpl.java |
---|
9,6 → 9,10 |
import org.apache.log4j.Logger; |
import javax.servlet.http.HttpServletRequest; |
import jomm.utils.MessageResources; |
/** |
* @author Jorge Machado |
* @date 2/Mar/2008 |
97,4 → 101,19 |
{ |
return isSuperuser() || isAdmin(); |
} |
public String getRolesDescription(HttpServletRequest request,String separator) |
{ |
String sep = ""; |
StringBuilder strBuilder = new StringBuilder(); |
for (String role : getRolesList()) |
{ |
if (!role.equals(Globals.SUPER_USER_ROLE)) |
{ |
strBuilder.append(sep + MessageResources.getMessage(request, "user.role." + role)); |
sep = separator; |
} |
} |
return strBuilder.toString(); |
} |
} |
/impl/src/java/pt/estgp/estgweb/web/DirWebProxy.java |
---|
2,8 → 2,9 |
import org.apache.log4j.Logger; |
import org.apache.commons.httpclient.util.URIUtil; |
import org.dom4j.Document; |
import org.dom4j.DocumentException; |
import org.apache.commons.net.ftp.FTPClient; |
import org.apache.commons.net.ftp.FTPFile; |
import org.dom4j.*; |
import org.dom4j.io.OutputFormat; |
import javax.servlet.http.HttpServlet; |
13,9 → 14,7 |
import javax.servlet.jsp.JspWriter; |
import java.io.*; |
import java.net.*; |
import java.util.Date; |
import java.util.Map; |
import java.util.HashMap; |
import java.util.*; |
import java.util.zip.ZipInputStream; |
import java.util.zip.GZIPInputStream; |
import java.util.zip.InflaterInputStream; |
25,6 → 24,10 |
import pt.estgp.estgweb.domain.UserSession; |
import freemarker.template.utility.HtmlEscape; |
import com.lowagie.text.html.HtmlEncoder; |
import jomm.web.ftp.IFile; |
import jomm.web.ftp.FileType; |
import jomm.web.ftp.impl.FtpFile; |
import jomm.web.utils.NavPlace; |
/** |
* @author Jorge Machado |
50,19 → 53,18 |
{ |
String element = (String) request.getAttribute("element"); |
if(element.equals("node")) |
if (element.equals("node")) |
{ |
processNode(request,response); |
processNode(request, response); |
} |
else |
{ |
processLeaf(request,response); |
processLeaf(request, response); |
} |
} |
/** |
* |
* @param request |
* @param response |
* @throws ServletException |
72,16 → 74,19 |
protected static void processNode(HttpServletRequest request, HttpServletResponse response) |
throws ServletException, IOException |
{ |
styleDirectory(request,response); |
styleDirectory(request, response); |
} |
protected static void processLeaf(HttpServletRequest request, HttpServletResponse response) |
throws ServletException, IOException |
{ |
String path = (String) request.getAttribute("path"); |
String startPath = (String) request.getAttribute("startPath"); |
String leafUrl = (String) request.getAttribute("leaf.url"); |
String server = (String) request.getAttribute("server"); |
String useOutputStream = (String) request.getAttribute("useOutputStream"); |
String encoding = (String) request.getAttribute("encoding"); |
String proxyKey = (String) request.getAttribute("proxyKey"); |
String proxyHost = (String) request.getAttribute("proxy.host"); |
String proxyPort = (String) request.getAttribute("proxy.port"); |
boolean style = Boolean.parseBoolean((String) request.getAttribute("style")); |
90,6 → 95,7 |
logger.info("server:" + server); |
logger.info("path:" + path); |
logger.info("proxyKey:" + proxyKey); |
logger.info("proxyHost:" + proxyHost); |
logger.info("proxyPort:" + proxyPort); |
logger.info("xml:" + xml); |
108,35 → 114,44 |
String finalURL = server + URIUtil.encodePath(path, "ISO-8859-1"); |
URL url = new URL(finalURL); |
if (!finalURL.startsWith("ftp://")) |
{ |
URL url = new URL(finalURL); |
if (useOutputStream != null && useOutputStream.equals("true")) |
{ |
InputStream stream = openStream(finalURL,proxy); |
URLConnection con = url.openConnection(); |
response.setContentType(con.getContentType()); |
if(xml == null || xml.equals("false")) |
response.setCharacterEncoding(encoding); |
response.setContentLength(con.getContentLength()); |
writeDirectStream(response,stream); |
} |
else if(xml == null || xml.equals("false")) |
{ |
InputStream stream = openStream(finalURL,proxy); |
String content = readContent2String(stream,encoding); |
generateOutputLeaf(response,request,content,style); |
} |
else |
{ |
URLConnection con = new URL(finalURL).openConnection(); |
con.connect(); |
if(con.getContentLength()>0) |
if (useOutputStream != null && useOutputStream.equals("true")) |
{ |
InputStream stream = openStream(finalURL, proxy); |
URLConnection con = url.openConnection(); |
response.setContentType(con.getContentType()); |
if (xml == null || xml.equals("false")) |
response.setCharacterEncoding(encoding); |
response.setContentLength(con.getContentLength()); |
writeDirectStream(response, stream); |
} |
else if (xml == null || xml.equals("false")) |
{ |
InputStream stream = openStream(finalURL, proxy); |
String content = readContent2String(stream, encoding); |
generateOutputLeaf(response, request, content, style); |
} |
else |
{ |
URLConnection con = new URL(finalURL).openConnection(); |
con.connect(); |
if (con.getContentLength() > 0) |
{ |
// Document dom = Dom4jUtil.parse(stream); |
generateOutputLeafXml(response,request,finalURL,proxy,style); |
generateOutputLeafXml(response, request, finalURL, proxy, style); |
} |
} |
} |
else |
{ |
Document directoryDocument = (Document) request.getAttribute("directoryDocument"); |
extendDiretoryDocument(request, path, proxyKey, server, startPath + leafUrl, directoryDocument); |
styleDirectory(request, response); |
} |
} |
catch (FileNotFoundException e) |
{ |
153,15 → 168,199 |
logger.warn("url not found for server:" + server + " and path:" + path); |
response.sendError(404); |
} |
} |
public static String FTP_FILE_PREFIX = "FTP_"; |
public static void addAttribute(Element element, String name, String value) |
{ |
element.addAttribute(new QName(name, DirLayoutController.dirNamespace), value); |
} |
private static void generateOutputLeafXml(HttpServletResponse response,HttpServletRequest request, String finalURL,Proxy proxy, boolean style) throws IOException, DocumentException |
protected static void extendDiretoryDocument(HttpServletRequest request, String path, String serverStr, String server, String startPath, Document directoryDocument) |
throws ServletException, IOException |
{ |
if(style) |
try |
{ |
Map<String,Object> parameters = new HashMap<String,Object>(); |
String user = ConfigProperties.getProperty(serverStr + ".user"); |
String pass = ConfigProperties.getProperty(serverStr + ".pass"); |
if (path != null) |
{ |
FtpServer ftpServer = FtpServer.getServer(server, user, pass); |
FTPClient client = ftpServer.getClient(); |
Element actualNode = (Element) request.getAttribute("actualNode"); |
if(startPath.equals("/")) |
startPath = ""; |
if (path.equals(startPath)) |
{ |
client.changeWorkingDirectory(path); |
FTPFile[] files = client.listFiles(); |
List<IFile> iFiles = FtpFile.init(files, server, path); |
//root |
for (IFile iFile : iFiles) |
{ |
Element iFileElem = actualNode.addElement(DirLayoutController.leafDir); |
addAttribute(iFileElem, "id", FTP_FILE_PREFIX + "0_" + iFile.getName()); |
addAttribute(iFileElem, "label", iFile.getName()); |
addAttribute(iFileElem, "visualization", "filesystem"); |
addAttribute(iFileElem, "size", "" + iFile.getSize()); |
addAttribute(iFileElem, "lastModification", "" + iFile.getLastUpdate().toString()); |
if (iFile.getType() == FileType.DIRECTORY) |
{ |
addAttribute(iFileElem, "ftpDirectory", "true"); |
} |
else |
{ |
addAttribute(iFileElem, "ftpDirectory", "false"); |
addAttribute(iFileElem, "absolute", "true"); |
addAttribute(iFileElem, "url", iFile.getCompleteUrl()); |
} |
} |
} |
else |
{ |
String pathAux = path.substring(startPath.length()); |
String[] pathFragments = pathAux.split("/"); |
client.changeWorkingDirectory(startPath); |
FTPFile[] files = client.listFiles(); |
List<IFile> iFiles = FtpFile.init(files, server, path); |
Element goDeepElement = null; |
for (IFile iFile : iFiles) |
{ |
Element iFileElem = actualNode.addElement(DirLayoutController.nodeDir); |
addAttribute(iFileElem, "id", FTP_FILE_PREFIX + "0_" + iFile.getName()); |
addAttribute(iFileElem, "label", iFile.getName()); |
addAttribute(iFileElem, "visualization", "filesystem"); |
addAttribute(iFileElem, "size", "" + iFile.getSize()); |
addAttribute(iFileElem, "lastModification", "" + iFile.getLastUpdate().toString()); |
if (iFile.getType() == FileType.DIRECTORY) |
{ |
addAttribute(iFileElem, "ftpDirectory", "true"); |
} |
else |
{ |
addAttribute(iFileElem, "ftpDirectory", "false"); |
addAttribute(iFileElem, "absolute", "true"); |
addAttribute(iFileElem, "url", iFile.getCompleteUrl()); |
} |
if (iFile.getName().equals(pathFragments[0])) |
goDeepElement = iFileElem; |
} |
for (int i = 0; i < pathFragments.length; i++) |
{ |
Element nextGoDeepElement = null; |
String d = pathFragments[i]; |
String startPathAux = startPath + "/" + d; |
client.changeWorkingDirectory(startPathAux); |
files = client.listFiles(); |
iFiles = FtpFile.init(files, server, path); |
for (IFile iFile : iFiles) |
{ |
Element iFileElem; |
if(i == pathFragments.length - 1) |
iFileElem = goDeepElement.addElement(DirLayoutController.leafDir); |
else |
iFileElem = goDeepElement.addElement(DirLayoutController.nodeDir); |
addAttribute(iFileElem, "id", FTP_FILE_PREFIX + (i+1) + "_" + iFile.getName()); |
addAttribute(iFileElem, "label", iFile.getName()); |
addAttribute(iFileElem, "visualization", "filesystem"); |
addAttribute(iFileElem, "size", "" + iFile.getSize()); |
addAttribute(iFileElem, "lastModification", "" + iFile.getLastUpdate().toString()); |
if (iFile.getType() == FileType.DIRECTORY) |
{ |
addAttribute(iFileElem, "ftpDirectory", "true"); |
} |
else |
{ |
addAttribute(iFileElem, "ftpDirectory", "false"); |
addAttribute(iFileElem, "absolute", "true"); |
addAttribute(iFileElem, "url", iFile.getCompleteUrl()); |
} |
if (i < pathFragments.length - 1 && iFile.getName().equals(pathFragments[i + 1])) |
nextGoDeepElement = iFileElem; |
} |
goDeepElement = nextGoDeepElement; |
} |
request.setAttribute("ACTUAL_REMOTE_CHILD",pathFragments[pathFragments.length - 1]); |
} |
client.quit(); |
client.disconnect(); |
} |
else |
{ |
throw new FileNotFoundException("url not found for server:" + server + " and path:" + path); |
} |
} |
catch (Throwable e) |
{ |
logger.error(e, e); |
} |
} |
protected void processRequestFtp(HttpServletRequest request, String path, String serverStr, String server, String startPath) |
throws ServletException, IOException |
{ |
try |
{ |
String user = ConfigProperties.getProperty(serverStr + ".user"); |
String pass = ConfigProperties.getProperty(serverStr + ".pass"); |
if (path != null) |
{ |
FtpServer ftpServer = FtpServer.getServer(server, user, pass); |
FTPClient client = ftpServer.getClient(); |
client.changeWorkingDirectory(path); |
FTPFile[] files = client.listFiles(); |
List<IFile> iFiles = new ArrayList<IFile>(); |
for (FTPFile ftpFile : files) |
{ |
IFile iFile; |
if (path.endsWith("/")) |
iFile = new FtpFile(ftpFile, server + URIUtil.encodePath(path + ftpFile.getName(), "ISO-8859-1"), path); |
else |
iFile = new FtpFile(ftpFile, server + URIUtil.encodePath(path + "/" + ftpFile.getName(), "ISO-8859-1"), path); |
iFiles.add(iFile); |
} |
List<NavPlace> navPlaces = FtpFile.getNavPlaces(path, startPath); |
request.setAttribute("NavPlaces", navPlaces); |
request.setAttribute("files", iFiles); |
client.quit(); |
client.disconnect(); |
} |
else |
{ |
throw new FileNotFoundException("url not found for server:" + server + " and path:" + path); |
} |
} |
catch (Throwable e) |
{ |
logger.error(e, e); |
} |
} |
private static void generateOutputLeafXml(HttpServletResponse response, HttpServletRequest request, String finalURL, Proxy proxy, boolean style) throws IOException, DocumentException |
{ |
if (style) |
{ |
Map<String, Object> parameters = new HashMap<String, Object>(); |
// OutputFormat outputFormat = new OutputFormat(); |
// outputFormat.setSuppressDeclaration(true); |
// outputFormat.setEncoding("UTF-8"); |
169,24 → 368,24 |
// Dom4jUtil.write(dom,writer, outputFormat); |
// org.w3c.dom.Document d = new org.dom4j.io.DOMWriter().write(dom); |
// parameters.put("body",dom.selectSingleNode("/")); |
parameters.put("includeXML",finalURL); |
styleDirectory(request,response,parameters,null); |
parameters.put("includeXML", finalURL); |
styleDirectory(request, response, parameters, null); |
} |
else |
{ |
InputStream stream = openStream(finalURL,proxy); |
InputStream stream = openStream(finalURL, proxy); |
Document dom = Dom4jUtil.parse(stream); |
Dom4jUtil.write(dom,response.getWriter()); |
Dom4jUtil.write(dom, response.getWriter()); |
} |
} |
private static void generateOutputLeaf(HttpServletResponse response,HttpServletRequest request, String content, boolean style) throws IOException |
private static void generateOutputLeaf(HttpServletResponse response, HttpServletRequest request, String content, boolean style) throws IOException |
{ |
if(style) |
if (style) |
{ |
// Map<String,Object> parameters = new HashMap<String,Object>(); |
// parameters.put("body",content); |
styleDirectory(request,response,new HashMap<String,Object>(),content); |
styleDirectory(request, response, new HashMap<String, Object>(), content); |
} |
else |
{ |
196,35 → 395,37 |
private static void styleDirectory(HttpServletRequest request, HttpServletResponse response) throws IOException |
{ |
styleDirectory(request,response,new HashMap<String,Object>(),null); |
styleDirectory(request, response, new HashMap<String, Object>(), null); |
} |
private static void styleDirectory(HttpServletRequest request, HttpServletResponse response, Map<String,Object> parameters, String bodyContent) throws IOException |
private static void styleDirectory(HttpServletRequest request, HttpServletResponse response, Map<String, Object> parameters, String bodyContent) throws IOException |
{ |
String stylesheet = (String) request.getAttribute("stylesheet"); |
Document directoryDocument = (Document) request.getAttribute("directoryDocument"); |
String actualNodeId = (String) request.getAttribute("actualNodeId"); |
String actualRemoteNodeId = (String) request.getAttribute("ACTUAL_REMOTE_CHILD"); |
UserSession userSession = UserSessionProxy.loadUserSessionFromRequest(request); |
parameters.put("contextPath",request.getContextPath()); |
if(userSession.getUsername() != null) |
parameters.put("username",userSession.getUsername()); |
if(userSession.getName() != null) |
parameters.put("name",userSession.getName()); |
if(userSession.getUser() != null) |
parameters.put("roles",userSession.getUser().getRoles()); |
parameters.put("ACTUAL",actualNodeId); |
parameters.put("contextPath", request.getContextPath()); |
if (userSession.getUsername() != null) |
parameters.put("username", userSession.getUsername()); |
if (userSession.getName() != null) |
parameters.put("name", userSession.getName()); |
if (userSession.getUser() != null) |
parameters.put("roles", userSession.getUser().getRoles()); |
parameters.put("ACTUAL", actualNodeId); |
parameters.put("ACTUAL_REMOTE_CHILD", actualRemoteNodeId); |
try |
{ |
String html = Dom4jUtil.styleDocument(directoryDocument,stylesheet,parameters); |
if(bodyContent != null) |
html = html.replace("@@BODY_CONTENT@@",bodyContent); |
String html = Dom4jUtil.styleDocument(directoryDocument, stylesheet, parameters); |
if (bodyContent != null) |
html = html.replace("@@BODY_CONTENT@@", bodyContent); |
response.getWriter().write(html); |
} |
catch (Exception e) |
{ |
logger.error(e,e); |
logger.error(e, e); |
response.sendError(500); |
} |
} |
/impl/src/java/pt/estgp/estgweb/web/DirLayoutController.java |
---|
13,8 → 13,7 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.ServletException; |
import java.io.IOException; |
import java.io.FileNotFoundException; |
import java.io.*; |
import java.util.List; |
import java.util.ArrayList; |
import java.util.HashMap; |
41,7 → 40,13 |
private static final Logger logger = Logger.getLogger(DirLayoutController.class); |
public static Map<String, String> namespaces = new HashMap<String, String>(); |
static |
{ |
namespaces.put("d", "http://www.estgp.pt/baco/directory/"); |
} |
private static enum DirectoryNodeType |
{ |
node, |
104,15 → 109,14 |
String directory = request.getParameter("directory"); |
String path = request.getParameter("path"); |
try |
{ |
Document directoryDocument = Dom4jUtil.parseSourceFile("/pt/estgp/estgweb/directories/" + directory + ".xml"); |
Document directoryDocument = Dom4jUtil.parseSourceFileFromCache("/pt/estgp/estgweb/directories/" + directory + ".xml"); |
if (path.startsWith("/")) |
path = path.substring(1); |
String[] ids = path.split("/"); |
Map<String, String> namespaces = new HashMap<String, String>(); |
DirectoryNodeType directoryNodeType = null; |
String actualNodeId = null; |
Element actualNode = null; |
121,7 → 125,7 |
for (String id : ids) |
{ |
XPath idXpath = directoryDocument.createXPath("//*[@id='" + id + "']"); |
namespaces.put("d", "http://www.estgp.pt/baco/directory/"); |
idXpath.setNamespaceURIs(namespaces); |
Element idElem = (Element) idXpath.selectSingleNode(directoryDocument); |
if (idElem == null) |
173,7 → 177,7 |
} |
String externalFile = buildExternalFile(stopName, ids); |
putInRequestCommonAttributes(request, actualNodeId, directoryDocument); |
putInRequestCommonAttributes(request,actualNode, actualNodeId, directoryDocument); |
Attribute layoutStrAtt = directoryDocument.getRootElement().attribute("layout"); |
Attribute layoutRootStrAtt = directoryDocument.getRootElement().attribute("layoutRoot"); |
213,7 → 217,7 |
boolean layoutDo = true; |
if (layout != null && layout.length() > 0) layoutDo = Boolean.parseBoolean(layout); |
if (!layoutDo) layoutChoosed = "layoutEmpty"; |
putProxyAttributes(request, proxy, externalFile,xml); |
putProxyAttributes(request, proxy, externalFile,xml,url); |
request.setAttribute("label", label); |
request.setAttribute("style", style); |
request.setAttribute("xml", xml); |
249,19 → 253,23 |
return (actualNode.attribute(name) != null ? actualNode.attribute(name).getValue() : null); |
} |
private void putProxyAttributes(HttpServletRequest request, String proxy, String externalFile, String xml) |
private void putProxyAttributes(HttpServletRequest request, String proxy, String externalFile, String xml, String url) |
{ |
String server = ConfigProperties.getProperty("server." + proxy); |
String proxyHost = ConfigProperties.getProperty(proxy + ".proxy.host"); |
String proxyPort = ConfigProperties.getProperty(proxy + ".proxy.port"); |
String confStartPath = ConfigProperties.getProperty("server." + proxy + ".start.path"); |
request.setAttribute("leaf.url", url); |
request.setAttribute("server", server); |
request.setAttribute("proxyKey", proxy); |
request.setAttribute("proxy.host", proxyHost); |
request.setAttribute("proxy.port", proxyPort); |
if (confStartPath != null) |
externalFile = confStartPath + externalFile; |
request.setAttribute("path", externalFile); |
request.setAttribute("startPath", confStartPath); |
if(xml != null && xml.equals("true")) |
{ |
280,10 → 288,11 |
return; |
} |
} |
request.setAttribute("useOutputStream", "true"); |
if(!server.startsWith("ftp://")) |
request.setAttribute("useOutputStream", "true"); |
} |
private void putInRequestCommonAttributes(HttpServletRequest request, String actualNameId, Document directoryDocument) |
private void putInRequestCommonAttributes(HttpServletRequest request,Element actualNode, String actualNameId, Document directoryDocument) |
{ |
/** |
* Attributes used in Nodes and Leafs |
301,6 → 310,7 |
request.setAttribute("stylesheet", "/pt/estgp/estgweb/directories/" + styleChoosed); |
request.setAttribute("directoryDocument", directoryDocument); |
request.setAttribute("actualNodeId", actualNameId); |
request.setAttribute("actualNode", actualNode); |
request.setAttribute("targetRole", targetRoleChoosed); |
} |
335,9 → 345,9 |
return null; |
} |
Namespace dirNamespace = new Namespace("d", "http://www.estgp.pt/baco/directory/"); |
QName nodeDir = new QName("node", dirNamespace); |
QName leafDir = new QName("leaf", dirNamespace); |
public static Namespace dirNamespace = new Namespace("d", "http://www.estgp.pt/baco/directory/"); |
public static QName nodeDir = new QName("node", dirNamespace); |
public static QName leafDir = new QName("leaf", dirNamespace); |
private boolean pruneDocument(Element startElem, Map namespaces, UserSession userSession) |
{ |
503,165 → 513,6 |
} |
protected void processRequestFtp(HttpServletRequest request, String path, String serverStr, String server, String startPath) |
throws ServletException, IOException |
{ |
try |
{ |
String user = ConfigProperties.getProperty(serverStr + ".user"); |
String pass = ConfigProperties.getProperty(serverStr + ".pass"); |
if (path != null) |
{ |
DirLayoutController.FtpServer ftpServer = getServer(server, user, pass); |
FTPClient client = ftpServer.getClient(); |
client.changeWorkingDirectory(path); |
FTPFile[] files = client.listFiles(); |
List<IFile> iFiles = new ArrayList<IFile>(); |
for (FTPFile ftpFile : files) |
{ |
IFile iFile; |
if (path.endsWith("/")) |
iFile = new FtpFile(ftpFile, server + URIUtil.encodePath(path + ftpFile.getName(), "ISO-8859-1"), path); |
else |
iFile = new FtpFile(ftpFile, server + URIUtil.encodePath(path + "/" + ftpFile.getName(), "ISO-8859-1"), path); |
iFiles.add(iFile); |
} |
List<NavPlace> navPlaces = FtpFile.getNavPlaces(path, startPath); |
request.setAttribute("NavPlaces", navPlaces); |
request.setAttribute("files", iFiles); |
client.quit(); |
client.disconnect(); |
} |
else |
{ |
throw new FileNotFoundException("url not found for server:" + server + " and path:" + path); |
} |
} |
catch (Throwable e) |
{ |
logger.error(e, e); |
} |
} |
private static HashMap<String, FtpServer> servers = new HashMap<String, DirLayoutController.FtpServer>(); |
/** |
* Add a ftpServer to Cache |
* |
* @param urlStr to parse |
* @param user username |
* @param pass password |
* @return ftpServer |
*/ |
private static synchronized DirLayoutController.FtpServer addServer(String urlStr, String user, String pass) |
{ |
try |
{ |
URL url = new URL(urlStr); |
String host = url.getHost(); |
int port = url.getPort(); |
if (port <= 0) |
port = 21; |
logger.info("Connecting to " + host + "in port:" + port); |
DirLayoutController.FtpServer ftpServer = new DirLayoutController.FtpServer(host, port, user, pass); |
servers.put(urlStr, ftpServer); |
return ftpServer; |
} |
catch (MalformedURLException e) |
{ |
logger.error(e, e); |
} |
catch (IOException e) |
{ |
logger.error(e, e); |
} |
return null; |
} |
private static DirLayoutController.FtpServer getServer(String urlStr, String user, String pass) |
{ |
DirLayoutController.FtpServer ftpServer = servers.get(urlStr); |
if (ftpServer == null) |
ftpServer = addServer(urlStr, user, pass); |
return ftpServer; |
} |
public static class FtpServer |
{ |
String host = null; |
int port = 21; |
String username = null; |
String password = null; |
public FtpServer(String host, int port) |
{ |
this.host = host; |
if (port > 0) |
this.port = port; |
} |
public FtpServer(String host, int port, String username, String password) |
{ |
this.host = host; |
this.port = port; |
this.username = username; |
this.password = password; |
} |
public FTPClient getClient() throws IOException |
{ |
FTPClient ftp = new FTPClient(); |
ftp.connect(host, port); |
if (username != null) |
ftp.user(username); |
if (password != null) |
ftp.pass(password); |
return ftp; |
} |
public String getHost() |
{ |
return host; |
} |
public void setHost(String host) |
{ |
this.host = host; |
} |
public int getPort() |
{ |
return port; |
} |
public void setPort(int port) |
{ |
this.port = port; |
} |
public String getUsername() |
{ |
return username; |
} |
public void setUsername(String username) |
{ |
this.username = username; |
} |
public String getPassword() |
{ |
return password; |
} |
public void setPassword(String password) |
{ |
this.password = password; |
} |
} |
} |
/impl/src/java/pt/estgp/estgweb/web/FtpServer.java |
---|
New file |
0,0 → 1,138 |
package pt.estgp.estgweb.web; |
import org.apache.commons.net.ftp.FTPClient; |
import org.apache.log4j.Logger; |
import java.util.HashMap; |
import java.net.URL; |
import java.net.MalformedURLException; |
import java.io.IOException; |
/** |
* @author Jorge |
* @date 18/Jan/2009 |
* @time 18:35:11 |
*/ |
public class FtpServer |
{ |
private static final Logger logger = Logger.getLogger(FtpServer.class); |
private static HashMap<String, FtpServer> servers = new HashMap<String, FtpServer>(); |
String host = null; |
int port = 21; |
String username = null; |
String password = null; |
public FtpServer(String host, int port) |
{ |
this.host = host; |
if (port > 0) |
this.port = port; |
} |
public FtpServer(String host, int port, String username, String password) |
{ |
this.host = host; |
this.port = port; |
this.username = username; |
this.password = password; |
} |
public FTPClient getClient() throws IOException |
{ |
FTPClient ftp = new FTPClient(); |
ftp.connect(host, port); |
if (username != null) |
ftp.user(username); |
if (password != null) |
ftp.pass(password); |
return ftp; |
} |
public String getHost() |
{ |
return host; |
} |
public void setHost(String host) |
{ |
this.host = host; |
} |
public int getPort() |
{ |
return port; |
} |
public void setPort(int port) |
{ |
this.port = port; |
} |
public String getUsername() |
{ |
return username; |
} |
public void setUsername(String username) |
{ |
this.username = username; |
} |
public String getPassword() |
{ |
return password; |
} |
public void setPassword(String password) |
{ |
this.password = password; |
} |
public static FtpServer getServer(String urlStr, String user, String pass) |
{ |
FtpServer ftpServer = servers.get(urlStr); |
if (ftpServer == null) |
ftpServer = addServer(urlStr, user, pass); |
return ftpServer; |
} |
/** |
* Add a ftpServer to Cache |
* |
* @param urlStr to parse |
* @param user username |
* @param pass password |
* @return ftpServer |
*/ |
private static synchronized FtpServer addServer(String urlStr, String user, String pass) |
{ |
try |
{ |
URL url = new URL(urlStr); |
String host = url.getHost(); |
int port = url.getPort(); |
if (port <= 0) |
port = 21; |
logger.info("Connecting to " + host + "in port:" + port); |
FtpServer ftpServer = new FtpServer(host, port, user, pass); |
servers.put(urlStr, ftpServer); |
return ftpServer; |
} |
catch (MalformedURLException e) |
{ |
logger.error(e, e); |
} |
catch (IOException e) |
{ |
logger.error(e, e); |
} |
return null; |
} |
} |
/impl/src/java/pt/estgp/estgweb/web/LayoutController.java |
---|
122,7 → 122,7 |
if (path != null) |
{ |
FtpServer ftpServer = getServer(server, user, pass); |
FtpServer ftpServer = FtpServer.getServer(server, user, pass); |
FTPClient client = ftpServer.getClient(); |
client.changeWorkingDirectory(path); |
FTPFile[] files = client.listFiles(); |
151,124 → 151,4 |
logger.error(e, e); |
} |
} |
private static HashMap<String, FtpServer> servers = new HashMap<String, FtpServer>(); |
/** |
* Add a ftpServer to Cache |
* |
* @param urlStr to parse |
* @param user username |
* @param pass password |
* @return ftpServer |
*/ |
private static synchronized FtpServer addServer(String urlStr, String user, String pass) |
{ |
try |
{ |
URL url = new URL(urlStr); |
String host = url.getHost(); |
int port = url.getPort(); |
if (port <= 0) |
port = 21; |
logger.info("Connecting to " + host + "in port:" + port); |
FtpServer ftpServer = new FtpServer(host, port, user, pass); |
servers.put(urlStr, ftpServer); |
return ftpServer; |
} |
catch (MalformedURLException e) |
{ |
logger.error(e, e); |
} |
catch (IOException e) |
{ |
logger.error(e, e); |
} |
return null; |
} |
private static FtpServer getServer(String urlStr, String user, String pass) |
{ |
FtpServer ftpServer = servers.get(urlStr); |
if (ftpServer == null) |
ftpServer = addServer(urlStr, user, pass); |
return ftpServer; |
} |
public static class FtpServer |
{ |
String host = null; |
int port = 21; |
String username = null; |
String password = null; |
public FtpServer(String host, int port) |
{ |
this.host = host; |
if (port > 0) |
this.port = port; |
} |
public FtpServer(String host, int port, String username, String password) |
{ |
this.host = host; |
this.port = port; |
this.username = username; |
this.password = password; |
} |
public FTPClient getClient() throws IOException |
{ |
FTPClient ftp = new FTPClient(); |
ftp.connect(host, port); |
if (username != null) |
ftp.user(username); |
if (password != null) |
ftp.pass(password); |
return ftp; |
} |
public String getHost() |
{ |
return host; |
} |
public void setHost(String host) |
{ |
this.host = host; |
} |
public int getPort() |
{ |
return port; |
} |
public void setPort(int port) |
{ |
this.port = port; |
} |
public String getUsername() |
{ |
return username; |
} |
public void setUsername(String username) |
{ |
this.username = username; |
} |
public String getPassword() |
{ |
return password; |
} |
public void setPassword(String password) |
{ |
this.password = password; |
} |
} |
} |
/impl/src/java/pt/estgp/estgweb/web/UserSessionProxy.java |
---|
56,6 → 56,7 |
IServiceManager sm = ServiceManager.getInstance(); |
Object[] args = new Object[]{RequestUtils.getRequester(request, response)}; |
UserSession userSession = (UserSession) sm.execute(RequestUtils.getRequester(request, response),"LoadUserSession",args); |
userSession.setRequest(request); |
request.setAttribute(Globals.USER_SESSION_KEY,userSession); |
return userSession; |
} |
/impl/src/java/pt/estgp/estgweb/web/filters/UserSessionFilter.java |
---|
76,8 → 76,6 |
} |
} |
String path =((HttpServletRequest)request).getServletPath(); |
if(((HttpServletRequest)request).getServletPath().indexOf("errorNoCookies.do")>=0 || !hrequest.isRequestedSessionIdFromCookie()) |
chain.doFilter(request,response); |
try |
/impl/src/doc/Programas0809.doc |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+ application/octet-stream |
/impl/src/web/layout/navigationTop.jsp |
---|
21,15 → 21,16 |
<li class="submenu"><a href="#">Apresentação</a> |
<div class="shadow "> |
<ul class="menu"> |
<li><a href="#">Mensagem do Presidente</a></li> |
<li><a href="<%=request.getContextPath()%>/proxy/layout4/estgp/public/portal/estgMensagemPresidente.html">Mensagem do Presidente</a></li> |
<li><a href="#">A ESTG e a sua missão</a></li> |
<li><a href="#">História</a></li> |
<li><a href="#">Localização</a></li> |
<li><a href="#">Factos e números</a></li> |
<li><a href="<%=request.getContextPath()%>/proxy/layout4/estgp/public/portal/estgComoChegarEstg.html">Localização</a></li> |
<li><a href="<%=request.getContextPath()%>/proxy/estgFuturosAlunosPortalMenu/estgp/public/portal/estgNumeros.html">Factos e números</a></li> |
<li><a href="#">A ESTG em Fotografias</a></li> |
</ul> |
</div> |
</li> |
<li class="submenu"><a href="<%=request.getContextPath()%>/proxy/layout4/estgp/public/portal/contactosContactosGeraisEstg.html">Contactos</a></li> |
<li class="submenu"><a href="#"><bean:message key="organization"/> </a> |
<div class="shadow"> |
/impl/src/web/public/search/searchResults.jsp |
---|
1,6 → 1,4 |
<%@ page import="pt.estgp.estgweb.services.common.*" %> |
<%@ page import="pt.estgp.estgweb.web.Globals" %> |
<%@ page import="jomm.utils.ConfigProperties" %> |
<%@ 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" %> |
181,6 → 179,26 |
</logic:notEqual> |
) |
</logic:notEmpty> |
<logic:notEmpty name="result" property="subTitlesGroup"> |
( |
<% |
String subTitleSeparator = ""; |
%> |
<logic:iterate id="subTitleLabel" name="result" property="subTitlesGroup.labels"> |
<%=subTitleSeparator%> |
<logic:equal value="true" name="subTitleLabel" property="key"> |
<bean:message key="${subTitleLabel.label}"/> |
</logic:equal> |
<logic:notEqual value="true" name="subTitleLabel" property="key"> |
${subTitleLabel.label} |
</logic:notEqual> |
<% |
subTitleSeparator = ", "; |
%> |
</logic:iterate> |
) |
</logic:notEmpty> |
</h2> |
<p>${result.bestFragments} ...</p> |