so they work now; added the HTML Reference (originally from CW); added the post output filtering to turn the "pseudo-URIs" in the database into real URIs
162 lines
5.7 KiB
Java
162 lines
5.7 KiB
Java
/*
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
* (the "License"); you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
|
* language governing rights and limitations under the License.
|
|
*
|
|
* The Original Code is the Venice Web Communities System.
|
|
*
|
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
*/
|
|
package com.silverwrist.venice.servlets;
|
|
|
|
import java.io.*;
|
|
import javax.servlet.*;
|
|
import javax.servlet.http.*;
|
|
import com.silverwrist.venice.ValidationException;
|
|
import com.silverwrist.venice.core.*;
|
|
import com.silverwrist.venice.db.PostLinkDecoder;
|
|
import com.silverwrist.venice.servlets.format.*;
|
|
|
|
public class PostShortcut extends VeniceServlet
|
|
{
|
|
/*--------------------------------------------------------------------------------
|
|
* Overrides from class HttpServlet
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
public String getServletInfo()
|
|
{
|
|
String rc = "PostShortcut servlet - Decodes a post link and redirects to it\n"
|
|
+ "Part of the Venice Web Communities System\n";
|
|
return rc;
|
|
|
|
} // end getServletInfo
|
|
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
throws ServletException, IOException
|
|
{
|
|
UserContext user = getUserContext(request);
|
|
RenderData rdat = createRenderData(request,response);
|
|
String raw_link = request.getPathInfo().substring(1);
|
|
PostLinkDecoder decoder;
|
|
|
|
try
|
|
{ // attempt to decode the path link information
|
|
decoder = new PostLinkDecoder(raw_link);
|
|
if (decoder.getSIG()==null) // it must include the SIG
|
|
throw new ValidationException("ambiguous post link (no SIG)");
|
|
|
|
} // end try
|
|
catch (ValidationException e)
|
|
{ // display an error message for validation
|
|
String page_title = "Invalid Post Link";
|
|
ContentRender content = new ErrorBox(page_title,"Invalid post link \"" + raw_link + "\": "
|
|
+ e.getMessage(),null);
|
|
new BaseJSPData(page_title,"top",content).transfer(getServletContext(),rdat);
|
|
return;
|
|
|
|
} // end catch
|
|
|
|
SIGContext sig;
|
|
try
|
|
{ // get the SIG represented by that alias
|
|
sig = user.getSIGContext(decoder.getSIG());
|
|
|
|
} // end try
|
|
catch (DataException e)
|
|
{ // can't find the SIG - we're screwed
|
|
String page_title = "Invalid Post Link";
|
|
ContentRender content = new ErrorBox(page_title,"Invalid post link \"" + raw_link
|
|
+ "\": cannot find SIG: " + e.getMessage(),null);
|
|
new BaseJSPData(page_title,"top",content).transfer(getServletContext(),rdat);
|
|
return;
|
|
|
|
} // end catch
|
|
|
|
if (decoder.getConference()==null)
|
|
{ // it's a SIG link only - redirect to the SIG's default page
|
|
rdat.redirectTo("sig/" + decoder.getSIG());
|
|
return;
|
|
|
|
} // end if
|
|
|
|
ConferenceContext conf;
|
|
try
|
|
{ // get the conference represented by that alias
|
|
conf = sig.getConferenceContext(decoder.getConference());
|
|
|
|
} // end try
|
|
catch (DataException e)
|
|
{ // can't find the conference - we're screwed
|
|
String page_title = "Invalid Post Link";
|
|
ContentRender content = new ErrorBox(page_title,"Invalid post link \"" + raw_link
|
|
+ "\": cannot find conference: " + e.getMessage(),null);
|
|
new BaseJSPData(page_title,"top",content).transfer(getServletContext(),rdat);
|
|
return;
|
|
|
|
} // end catch
|
|
catch (AccessError ae)
|
|
{ // we can't get to the conference...
|
|
String page_title = "Access Error";
|
|
ContentRender content = new ErrorBox(page_title,ae.getMessage(),null);
|
|
new BaseJSPData(page_title,"top",content).transfer(getServletContext(),rdat);
|
|
return;
|
|
|
|
} // end catch
|
|
|
|
// compute an elementary "locator"
|
|
String locator = "sig=" + String.valueOf(sig.getSIGID()) + "&conf=" + String.valueOf(conf.getConfID());
|
|
|
|
if (decoder.getTopic()==-1)
|
|
{ // just a conference link - go to the top-level display
|
|
rdat.redirectTo("confdisp?" + locator);
|
|
return;
|
|
|
|
} // end if
|
|
|
|
TopicContext topic;
|
|
try
|
|
{ // get the topic number specified within that topic
|
|
topic = conf.getTopic(decoder.getTopic());
|
|
|
|
} // end try
|
|
catch (DataException e)
|
|
{ // we can't find the topic - we're screwed
|
|
String page_title = "Invalid Post Link";
|
|
ContentRender content = new ErrorBox(page_title,"Invalid post link \"" + raw_link
|
|
+ "\": cannot find topic: " + e.getMessage(),null);
|
|
new BaseJSPData(page_title,"top",content).transfer(getServletContext(),rdat);
|
|
return;
|
|
|
|
} // end catch
|
|
catch (AccessError ae)
|
|
{ // we can't get to the topic...
|
|
String page_title = "Access Error";
|
|
ContentRender content = new ErrorBox(page_title,ae.getMessage(),null);
|
|
new BaseJSPData(page_title,"top",content).transfer(getServletContext(),rdat);
|
|
return;
|
|
|
|
} // end catch
|
|
|
|
// add the topic to our locator
|
|
locator += "&top=" + String.valueOf(decoder.getTopic());
|
|
|
|
if (decoder.getFirstPost()==-1) // we're just referencing the topic
|
|
rdat.redirectTo("confdisp?" + locator + "&rnm=1");
|
|
else // we're referencing a post range within the topic
|
|
rdat.redirectTo("confdisp?" + locator + "&p1=" + String.valueOf(decoder.getFirstPost()) + "&p2="
|
|
+ String.valueOf(decoder.getLastPost()));
|
|
|
|
} // end doGet
|
|
|
|
} // end class PostShortcut
|
|
|