From: <rv...@us...> - 2009-06-23 11:09:07
|
Revision: 81 http://treebase.svn.sourceforge.net/treebase/?rev=81&view=rev Author: rvos Date: 2009-06-23 11:08:34 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Adding AbstractDownloadController, a superclass for MVC controllers that generate downloadable files (nexus,nexml) Added Paths: ----------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Added: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java (rev 0) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-23 11:08:34 UTC (rev 81) @@ -0,0 +1,119 @@ +package org.cipres.treebase.web.controllers; + +import java.io.File; +import java.io.FileWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.cipres.treebase.TreebaseUtil; +import org.cipres.treebase.domain.nexus.NexusService; +import org.cipres.treebase.web.util.WebUtil; +import org.springframework.web.servlet.mvc.Controller; + +public abstract class AbstractDownloadController implements Controller { + protected String mFormatParameter = "format"; + protected static final int FORMAT_NEXUS = 1; + protected static final int FORMAT_NEXML = 2; + private NexusService mNexmlService; + private static String mNexmlContentType = "application/xml"; + + /** + * + * @param request + * @return + */ + protected int getFormat (HttpServletRequest request) { + String requestedFormat = request.getParameter(mFormatParameter); + if ( null != requestedFormat ) { + if ( requestedFormat.equalsIgnoreCase("nexml") ) { + return FORMAT_NEXML; + } + else { + return FORMAT_NEXUS; // default + } + } + else { + return FORMAT_NEXUS; // default + } + } + + /** + * + * @param objectId + * @param request + * @return + */ + protected String getFileName(long id,HttpServletRequest request) { + if ( getFormat(request) == FORMAT_NEXML ) { + return getFileNamePrefix() + id + ".xml"; + } + return getFileNamePrefix() + id + ".nex"; + } + + /** + * + * @return a context-dependent prefix (e.g. "M" for a matrix) + */ + protected abstract String getFileNamePrefix(); + + /** + * + * @return a context-dependent serialization (e.g. a nexus string) + */ + protected abstract String getFileContent(long objectId,HttpServletRequest request); + + protected String getDownloadDir (HttpServletRequest request) { + String downloadDir = request.getSession().getServletContext().getRealPath( + TreebaseUtil.FILESEP + "NexusFileDownload") + + TreebaseUtil.FILESEP + request.getRemoteUser(); + return downloadDir; + } + + /** + * + * @param request + * @param pFileContent + * @param objectId + * @param downloadDirName + */ + protected void generateAFileDynamically(HttpServletRequest request, HttpServletResponse response, long objectId) { + String downloadDirName = getDownloadDir(request); + File dirPath = new File(downloadDirName); + if (!dirPath.exists()) { + dirPath.mkdirs(); + } + String fileName = getFileName(objectId,request); + try { + File file = new File(downloadDirName + TreebaseUtil.FILESEP + fileName); + FileWriter out = new FileWriter(file); + out.write(getFileContent(objectId,request)); + out.close(); + if ( getFormat(request) == FORMAT_NEXML ) { + WebUtil.downloadFile(response, downloadDirName, fileName, mNexmlContentType); + } + else { + WebUtil.downloadFile(response, downloadDirName, fileName); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * + * @return + */ + public NexusService getNexmlService() { + return mNexmlService; + } + + /** + * + * @param nexmlService + */ + public void setNexmlService(NexusService nexmlService) { + mNexmlService = nexmlService; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-06-25 02:26:46
|
Revision: 98 http://treebase.svn.sourceforge.net/treebase/?rev=98&view=rev Author: rvos Date: 2009-06-25 02:26:45 +0000 (Thu, 25 Jun 2009) Log Message: ----------- Added NeXML->RDF serialization Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-24 04:50:43 UTC (rev 97) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-25 02:26:45 UTC (rev 98) @@ -15,8 +15,11 @@ protected String mFormatParameter = "format"; protected static final int FORMAT_NEXUS = 1; protected static final int FORMAT_NEXML = 2; + protected static final int FORMAT_RDF = 3; private NexusService mNexmlService; + private NexusService mRdfaService; private static String mNexmlContentType = "application/xml"; + private static String mRdfContentType = "application/rdf+xml"; /** * @@ -29,6 +32,9 @@ if ( requestedFormat.equalsIgnoreCase("nexml") ) { return FORMAT_NEXML; } + else if ( requestedFormat.equalsIgnoreCase("rdf") ) { + return FORMAT_RDF; + } else { return FORMAT_NEXUS; // default } @@ -92,6 +98,9 @@ if ( getFormat(request) == FORMAT_NEXML ) { WebUtil.downloadFile(response, downloadDirName, fileName, mNexmlContentType); } + else if ( getFormat(request) == FORMAT_RDF ) { + WebUtil.downloadFile(response, downloadDirName, fileName, mRdfContentType); + } else { WebUtil.downloadFile(response, downloadDirName, fileName); } @@ -116,4 +125,12 @@ mNexmlService = nexmlService; } + public NexusService getRdfaService() { + return mRdfaService; + } + + public void setRdfaService(NexusService rdfaService) { + mRdfaService = rdfaService; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-06-28 10:16:55
|
Revision: 141 http://treebase.svn.sourceforge.net/treebase/?rev=141&view=rev Author: rvos Date: 2009-06-28 10:15:53 +0000 (Sun, 28 Jun 2009) Log Message: ----------- $baseURI =~ s/PhyloWS/phylows/; Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-28 10:14:15 UTC (rev 140) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2009-06-28 10:15:53 UTC (rev 141) @@ -29,7 +29,7 @@ .append(request.getServerName()) .append(':') .append(request.getServerPort()) - .append("/treebase-web/PhyloWS/"); + .append("/treebase-web/phylows/"); properties.setProperty("nexml.uri.base", baseURI.toString()); return properties; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-02-15 13:31:03
|
Revision: 499 http://treebase.svn.sourceforge.net/treebase/?rev=499&view=rev Author: rvos Date: 2010-02-15 13:30:56 +0000 (Mon, 15 Feb 2010) Log Message: ----------- Added isSubmitter() method, which checks whether the current user has access to the download by virtue of being a submitter (as opposed to a reviewer), this is needed to address issue 2949853 Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-02-15 13:28:43 UTC (rev 498) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-02-15 13:30:56 UTC (rev 499) @@ -8,9 +8,12 @@ import javax.servlet.http.HttpServletResponse; import org.cipres.treebase.TreebaseUtil; +import org.cipres.treebase.domain.admin.UserRole.TBPermission; import org.cipres.treebase.domain.nexus.NexusService; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.study.StudyService; +import org.cipres.treebase.domain.study.Submission; +import org.cipres.treebase.domain.study.SubmissionService; import org.cipres.treebase.web.util.ControllerUtil; import org.cipres.treebase.web.util.WebUtil; import org.springframework.web.servlet.mvc.Controller; @@ -22,6 +25,7 @@ protected static final int FORMAT_RDF = 3; private NexusService mNexmlService; private NexusService mRdfaService; + private SubmissionService mSubmissionService; private static String mNexmlContentType = "application/xml"; private static String mRdfContentType = "application/rdf+xml"; @@ -122,7 +126,7 @@ * @param downloadDirName */ protected void generateAFileDynamically(HttpServletRequest request, HttpServletResponse response, long objectId) { - if ( ! ControllerUtil.isReviewerAccessGranted(request) && ! getStudy(objectId,request).isPublished() ) { + if ( ! isSubmitter(objectId,request) && ! ControllerUtil.isReviewerAccessGranted(request) && ! getStudy(objectId,request).isPublished() ) { response.setStatus(HttpServletResponse.SC_SEE_OTHER); response.setHeader("Location", "/treebase-web/accessviolation.html"); } @@ -152,6 +156,18 @@ } } } + + private boolean isSubmitter (long objectId,HttpServletRequest request) { + Study study = getStudy(objectId,request); + Submission submission = study.getSubmission(); + TBPermission tbp = getSubmissionService().getPermission(request.getRemoteUser(), submission.getId()); + if (tbp == TBPermission.WRITE || tbp == TBPermission.READ_ONLY || tbp == TBPermission.SUBMITTED_WRITE) { + return true; + } + else { + return false; + } + } /** * @@ -176,5 +192,13 @@ public void setRdfaService(NexusService rdfaService) { mRdfaService = rdfaService; } + + public void setSubmissionService(SubmissionService submissionService) { + mSubmissionService = submissionService; + } + + public SubmissionService getSubmissionService() { + return mSubmissionService; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-06-01 16:28:09
|
Revision: 700 http://treebase.svn.sourceforge.net/treebase/?rev=700&view=rev Author: rvos Date: 2010-06-01 16:28:03 +0000 (Tue, 01 Jun 2010) Log Message: ----------- Added UTF-8 specifier in content-type header Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-05-28 08:03:51 UTC (rev 699) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-06-01 16:28:03 UTC (rev 700) @@ -26,8 +26,8 @@ private NexusService mNexmlService; private NexusService mRdfaService; private SubmissionService mSubmissionService; - private static String mNexmlContentType = "application/xml"; - private static String mRdfContentType = "application/rdf+xml"; + private static String mNexmlContentType = "application/xml; charset=UTF-8"; + private static String mRdfContentType = "application/rdf+xml; charset=UTF-8"; /** * Return the StudyService field. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-01-19 18:02:23
|
Revision: 474 http://treebase.svn.sourceforge.net/treebase/?rev=474&view=rev Author: rvos Date: 2010-01-19 18:02:17 +0000 (Tue, 19 Jan 2010) Log Message: ----------- Added access control for the download controllers. This has two moving parts: 1) a call to ControllerUtil.isReviewerAccessGranted which verifies that access has been granted to the focal study (i.e. the study that contains the object for which a serialization is being requested) during this session; 2) a check that the focal study has been published (in which case access is always granted). Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-01-19 17:59:08 UTC (rev 473) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-01-19 18:02:17 UTC (rev 474) @@ -9,6 +9,9 @@ import org.cipres.treebase.TreebaseUtil; import org.cipres.treebase.domain.nexus.NexusService; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.study.StudyService; +import org.cipres.treebase.web.util.ControllerUtil; import org.cipres.treebase.web.util.WebUtil; import org.springframework.web.servlet.mvc.Controller; @@ -21,6 +24,18 @@ private NexusService mRdfaService; private static String mNexmlContentType = "application/xml"; private static String mRdfContentType = "application/rdf+xml"; + + /** + * Return the StudyService field. + * + * @return StudyService mStudyService + */ + public abstract StudyService getStudyService(); + + /** + * Set the StudyService field. + */ + public abstract void setStudyService(StudyService pNewStudyService); protected Properties getDefaultProperties(HttpServletRequest request) { Properties properties = new Properties(); @@ -85,6 +100,13 @@ */ protected abstract String getFileContent(long objectId,HttpServletRequest request); + /** + * + * @param objectId - the id of the focal object (e.g. a tree) + * @return the study to which the focal object belongs + */ + protected abstract Study getStudy(long objectId,HttpServletRequest request); + protected String getDownloadDir (HttpServletRequest request) { String downloadDir = request.getSession().getServletContext().getRealPath( TreebaseUtil.FILESEP + "NexusFileDownload") @@ -100,29 +122,35 @@ * @param downloadDirName */ protected void generateAFileDynamically(HttpServletRequest request, HttpServletResponse response, long objectId) { - String downloadDirName = getDownloadDir(request); - File dirPath = new File(downloadDirName); - if (!dirPath.exists()) { - dirPath.mkdirs(); - } - String fileName = getFileName(objectId,request); - try { - File file = new File(downloadDirName + TreebaseUtil.FILESEP + fileName); - FileWriter out = new FileWriter(file); - out.write(getFileContent(objectId,request)); - out.close(); - if ( getFormat(request) == FORMAT_NEXML ) { - WebUtil.downloadFile(response, downloadDirName, fileName, mNexmlContentType); + if ( ! ControllerUtil.isReviewerAccessGranted(request) && ! getStudy(objectId,request).isPublished() ) { + response.setStatus(HttpServletResponse.SC_SEE_OTHER); + response.setHeader("Location", "/treebase-web/accessviolation.html"); + } + else { + String downloadDirName = getDownloadDir(request); + File dirPath = new File(downloadDirName); + if (!dirPath.exists()) { + dirPath.mkdirs(); } - else if ( getFormat(request) == FORMAT_RDF ) { - WebUtil.downloadFile(response, downloadDirName, fileName, mRdfContentType); - } - else { - WebUtil.downloadFile(response, downloadDirName, fileName); + String fileName = getFileName(objectId,request); + try { + File file = new File(downloadDirName + TreebaseUtil.FILESEP + fileName); + FileWriter out = new FileWriter(file); + out.write(getFileContent(objectId,request)); + out.close(); + if ( getFormat(request) == FORMAT_NEXML ) { + WebUtil.downloadFile(response, downloadDirName, fileName, mNexmlContentType); + } + else if ( getFormat(request) == FORMAT_RDF ) { + WebUtil.downloadFile(response, downloadDirName, fileName, mRdfContentType); + } + else { + WebUtil.downloadFile(response, downloadDirName, fileName); + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); - } + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-02-15 13:52:46
|
Revision: 501 http://treebase.svn.sourceforge.net/treebase/?rev=501&view=rev Author: rvos Date: 2010-02-15 13:52:32 +0000 (Mon, 15 Feb 2010) Log Message: ----------- Obtaining the Study in a different way, this should address an NPE I've been having. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-02-15 13:32:51 UTC (rev 500) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-02-15 13:52:32 UTC (rev 501) @@ -158,7 +158,8 @@ } private boolean isSubmitter (long objectId,HttpServletRequest request) { - Study study = getStudy(objectId,request); + Study study = ControllerUtil.findStudy(request, getStudyService()); + //Study study = getStudy(objectId,request); Submission submission = study.getSubmission(); TBPermission tbp = getSubmissionService().getPermission(request.getRemoteUser(), submission.getId()); if (tbp == TBPermission.WRITE || tbp == TBPermission.READ_ONLY || tbp == TBPermission.SUBMITTED_WRITE) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-03-15 01:43:13
|
Revision: 592 http://treebase.svn.sourceforge.net/treebase/?rev=592&view=rev Author: rvos Date: 2010-03-15 01:43:07 +0000 (Mon, 15 Mar 2010) Log Message: ----------- The "nexml.uri.base" property is now the purl domain by default. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-03-15 01:34:45 UTC (rev 591) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/AbstractDownloadController.java 2010-03-15 01:43:07 UTC (rev 592) @@ -43,13 +43,13 @@ protected Properties getDefaultProperties(HttpServletRequest request) { Properties properties = new Properties(); - StringBuffer baseURI = new StringBuffer("http://"); - baseURI - .append(request.getServerName()) - .append(':') - .append(request.getServerPort()) - .append("/treebase-web/phylows/"); - properties.setProperty("nexml.uri.base", baseURI.toString()); +// StringBuffer baseURI = new StringBuffer("http://"); +// baseURI +// .append(request.getServerName()) +// .append(':') +// .append(request.getServerPort()) +// .append("/treebase-web/phylows/"); + properties.setProperty("nexml.uri.base", TreebaseUtil.getPurlDomain()); return properties; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |