package com.documentum.web.virtuallink;

import com.documentum.fc.client.DfAuthenticationException;
import com.documentum.fc.client.IDfFormat;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.content.DfContentTemporarilyUnavailableException;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.DfPasswordEncoder;
import com.documentum.fc.common.IDfLoginInfo;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class VirtualLink404Handler extends HttpServlet
{
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
private static final String RIGHTSITE_APP_URL_1 = "/rightsite";
  private static final String RIGHTSITE_APP_URL_2 = "/rs-bin/rightsite.dll";
  private static final String CURRENT_DOCBASE = "com.documentum.web.virtuallink.docbase";
  private boolean m_bUseVirtualLinkErrorPage;
  public static final String SERVLET_NAME = "VirtualLink404Handler";
  public static final String LOGIN_COMPONENT_NAME = "/component/virtuallinkconnect";
  public static final String ARG_REDIRECT_URL = "redirectUrl";
  public static final String ARG_VIRTUALLINK_PATH = "virtualLinkPath";
  private static final int FILE_NOT_FOUND = 404;
  private static final int INTERNAL_SERVER_ERROR = 500;
  private static final int UN_AUTHORIZED = 401;
  private static final int CONTENT_TEMPORARILY_UNAVAILABLE = -1;
  private static final String PARAM_FORMAT = "format";
  private static final String ARG_APPNAME = "appname";
  private static final String ARG_DOCBASE = "docbase";
  private static final String ARG_USERNAME = "username";
  private static final String ARG_PASSWORD = "password";
  private static final String ARG_TICKET = "ticket";
  private static final String ARG_ROOTPATHS = "rootpaths";
  private static final String ARG_DOMAIN = "domain";
  private static final String ARG_ROOTPATHS_TABLE = "rptable";
  private static final String ARG_DEFAULT_APP_NANE = "DefaultWdkAppName";
  private static final String ARG_USE_VIRTUALLINKERROR_PAGE = "UseVirtualLinkErrorPage";
  private static final String DEFAULT_APP_NAME = "webtop";
  private static final String LINE_SEPARATOR = System.getProperty("line.separator");
  protected static final String VIRTUALLINK_STRINGS = "com.documentum.web.virtuallink.VirtualLinkNlsProp";

  public final void doGet(HttpServletRequest request, HttpServletResponse response)
  {
    processRequest(request, response);
  }

  public final void doPost(HttpServletRequest request, HttpServletResponse response)
  {
    processRequest(request, response);
  }

  public final String getServletInfo()
  {
    return getServletConfig().getServletName();
  }

  public void init(ServletConfig servletConfig) throws ServletException
  {
    this.m_bUseVirtualLinkErrorPage = true;
    String useErrorPage = servletConfig.getServletContext().getInitParameter("UseVirtualLinkErrorPage");
    if (useErrorPage == null)
      return;
    this.m_bUseVirtualLinkErrorPage = Boolean.valueOf(useErrorPage).booleanValue();
  }

  private void processRequest(HttpServletRequest request, HttpServletResponse response)
  {
    if (isValid404Error(request) != true)
    {
      sendErrorPage(request, response, 404);
      return;
    }

    IDfSession dfSession = null;
    try
    {
      IDfLoginInfo requestLoginInfo = getIdentity(request);
      boolean hasTicket = hasTicket(request);

      String strDocbase = getDocbaseName(request);

      dfSession = VirtualLinkAuthenticator.getDfSession(request, requestLoginInfo, strDocbase, hasTicket);

      if (dfSession == null)
      {
        authenticateViaWdk(request, response);
      }
      else
      {
        String strVirtualLinkPath = getVirtualLinkPath(request);

        VirtualLinkContent content = ContentResolver.getDocbaseContent(dfSession, strVirtualLinkPath, getRootPaths(request));
        if (content != null)
        {
          if (content.getSysObject() != null)
          {
            String format = getRequestParameter(request, "format");
            ContentResolver.resolveContentFormat(content, format, dfSession);

		StampDoc(content,dfSession);

            sendObjectContent(response, content);
          }
          else
          {
            String strExistingDocbasePath = ContentResolver.getExistingDocbasePath(dfSession, content);

            sendErrorPage(request, response, 404, strExistingDocbasePath);
          }
        }
      }
    }
    catch (DfException dae)
    {
      if (Trace.VIRTUALLINK == true)
      {
        Trace.error(this, "VirtualLink404Handler: Exception : ", dae);
      }

      int errorCode = 500;
      if ((dae instanceof DfAuthenticationException) || (dae.getMessageId().equalsIgnoreCase("DM_SYSOBJECT_E_NO_READ_ACCESS")))
      {
        errorCode = 401;
      }
      else if (dae instanceof DfContentTemporarilyUnavailableException)
      {
        errorCode = -1;
      }
      sendErrorPage(request, response, errorCode);
    }
    catch (Exception e)
    {
      if (Trace.VIRTUALLINK == true)
      {
        Trace.error(this, "VirtualLink404Handler", e);
      }
      sendErrorPage(request, response, 500);
    }
    finally
    {
      releaseDfSession(dfSession);
    }
  }

  private IDfLoginInfo getIdentity(HttpServletRequest request)
  {
    IDfLoginInfo loginInfo = null;

    String strUserName = getRequestParameter(request, "username");

    String strDomain = getRequestParameter(request, "domain");

    String strPasswordTicket = null;
    String strPassword = getRequestParameter(request, "password");
    if (strPassword != null)
    {
      strPasswordTicket = DfPasswordEncoder.decode(strPassword);
    }
    String strTicket = request.getParameter("ticket");
    if ((strTicket != null) && (strTicket.length() > 0))
    {
      strPasswordTicket = strTicket;
    }

    if ((strUserName != null) && (strUserName.length() > 0) && (strPasswordTicket != null))
    {
      loginInfo = new DfLoginInfo();
      loginInfo.setUser(strUserName);
      loginInfo.setPassword(strPasswordTicket);

      if ((strDomain != null) && (strDomain.length() > 0))
      {
        loginInfo.setDomain(strDomain);
      }
    }
    return loginInfo;
  }

  private void releaseDfSession(IDfSession idfSession)
  {
    if (idfSession == null)
      return;
    IDfSessionManager sessionManager = idfSession.getSessionManager();
    if (sessionManager == null)
      return;
    sessionManager.release(idfSession);
  }

  private void authenticateViaWdk(HttpServletRequest request, HttpServletResponse response)
    throws IOException
  {
    String strAppName = getWdkAppName(request);

    doRedirect(request, response, strAppName);
  }

  protected void doRedirect(HttpServletRequest request, HttpServletResponse response, String strAppName) throws IOException
  {
    String virtualLinkPath = getServletErrorRequestUri(request);

    StringBuffer bufRequestUrl = new StringBuffer();

    String strUrlPrefix = bufRequestUrl.toString();
    String requestUrl = strUrlPrefix + virtualLinkPath;

    if ((Trace.VIRTUALLINK == true) && 
      (requestUrl != null) && (requestUrl.length() > 0))
    {
      Trace.println("VirtualLink404Handler: authenticateViaWdk:request url = " + requestUrl);
    }

    bufRequestUrl.append("/" + strAppName + "/component/virtuallinkconnect");

    StringBuffer bufRedirectUrl = new StringBuffer(256);
    bufRedirectUrl.append(requestUrl);

    String strQueryString = request.getQueryString();
    if ((strQueryString != null) && (strQueryString.length() > 0))
    {
      strQueryString = removeAuthInfo(strQueryString);
      if ((strQueryString != null) && (strQueryString.length() > 0))
      {
        bufRedirectUrl.append("?").append(URLDecoder.decode(strQueryString));
      }

    }
    else
    {
      String strFormat = request.getParameter("format");
      if ((strFormat != null) && (strFormat.length() > 0))
      {
        bufRedirectUrl.append("?").append("format").append("=").append(strFormat);
      }

    }

    bufRequestUrl.append("?").append("redirectUrl").append("=").append(URLEncoder.encode(bufRedirectUrl.toString()));

    String relativeVirtualLinkUri = getRelativeVirtualLinkUri(request);
    bufRequestUrl.append("&").append("virtualLinkPath").append("=").append(URLEncoder.encode(relativeVirtualLinkUri));

    if (Trace.VIRTUALLINK == true)
    {
      Trace.println("VirtualLink404Handler: authenticateViaWdk:sendRedirect = " + bufRequestUrl.toString());
    }
    response.sendRedirect(bufRequestUrl.toString());
  }

  private static String getServletErrorRequestUri(HttpServletRequest request)
  {
    String virtualLinkPath = (String)request.getAttribute("javax.servlet.error.request_uri");
    if (virtualLinkPath != null)
    {
      try
      {
        virtualLinkPath = URLDecoder.decode(virtualLinkPath, "UTF-8");
      }
      catch (UnsupportedEncodingException ex)
      {
        Trace.println("javax.serlvet.error.request_uri could not be decoded using UTF-8");
      }
    }
    return virtualLinkPath;
  }

  private static String getRelativeVirtualLinkUri(HttpServletRequest request)
  {
    String virtualLinkPath = getServletErrorRequestUri(request);

    String contextPath = request.getContextPath();
    if ((contextPath.length() > 1) && (virtualLinkPath.startsWith(contextPath)))
    {
      virtualLinkPath = virtualLinkPath.substring(contextPath.length());
    }

    if (virtualLinkPath.toLowerCase().startsWith("/rightsite"))
    {
      virtualLinkPath = virtualLinkPath.substring("/rightsite".length());
    }
    else if (virtualLinkPath.toLowerCase().startsWith("/rs-bin/rightsite.dll"))
    {
      virtualLinkPath = virtualLinkPath.substring("/rs-bin/rightsite.dll".length());
    }

    return virtualLinkPath;
  }

  private String removeAuthInfo(String strQueryString)
  {
    StringTokenizer st = new StringTokenizer(strQueryString, "&");
    StringBuffer strBuf = new StringBuffer(100);
    while (st.hasMoreTokens())
    {
      String strToken = st.nextToken();
      if ((!(strToken.startsWith("ticket"))) && (!(strToken.startsWith("username"))) && (!(strToken.startsWith("docbase"))) && (!(strToken.startsWith("domain"))))
      {
        strBuf.append("&");
        strBuf.append(strToken);
      }
    }
    return strBuf.toString();
  }

  protected String getWdkAppName(HttpServletRequest request)
  {
    String strAppName = request.getSession().getServletContext().getInitParameter("DefaultWdkAppName");
    if ((strAppName == null) || (strAppName.length() < 1))
    {
      strAppName = "webtop";
    }

    Cookie[] arrCookies = request.getCookies();
    if ((arrCookies != null) && (arrCookies.length > 0))
    {
      for (int i = 0; i < arrCookies.length; ++i)
      {
        Cookie objCookie = arrCookies[i];
        if (!(objCookie.getName().equals("appname"))) {
          continue;
        }
        strAppName = objCookie.getValue();
        break;
      }

    }

    if (Trace.VIRTUALLINK == true)
    {
      Trace.println("VirtualLink404Handler: getWdkAppName:appname = " + strAppName);
    }

    return strAppName;
  }

  private String getVirtualLinkPath(HttpServletRequest request)
  {
    String strVirtualLinkPath = getRelativeVirtualLinkUri(request);

    if (Trace.VIRTUALLINKMATCHING == true)
    {
      Trace.println("Virtual link request: " + strVirtualLinkPath);
    }

    int idxDocbasePostSlash = strVirtualLinkPath.indexOf(47, 1);
    if ((idxDocbasePostSlash > 1) && (strVirtualLinkPath.charAt(idxDocbasePostSlash - 1) == ':'))
    {
      strVirtualLinkPath = strVirtualLinkPath.substring(idxDocbasePostSlash);
    }
    return strVirtualLinkPath;
  }

  private boolean isValid404Error(HttpServletRequest request)
  {
    boolean fIsValid404Error = false;
    Integer code = null;
    if (Trace.VIRTUALLINKREQUEST == true)
    {
      logRequestDetails(request);
    }

    code = (Integer)request.getAttribute("javax.servlet.error.status_code");
    if (code != null)
    {
      String reqURI = (String)request.getAttribute("javax.servlet.error.request_uri");

      if ((code.intValue() == 404) && (reqURI != null) && (!(reqURI.equals("/favicon.ico"))) && (!(reqURI.equals("/_vti_inf.html"))) && (!(reqURI.equals("/_vti_bin/shtml.exe/_vti_rpc"))))
      {
        fIsValid404Error = true;
      }
      else if (Trace.VIRTUALLINK == true)
      {
        Trace.println("VirtualLink404Handler: Not a valid 404 error...");
      }
    }

    return fIsValid404Error;
  }

  private void sendErrorPage(HttpServletRequest request, HttpServletResponse response, int errorCode)
  {
    sendErrorPage(request, response, errorCode, null);
  }

  private void sendErrorPage(HttpServletRequest request, HttpServletResponse response, int errorCode, String strResolvedDocbasePath)
  {
    try
    {
      int errorCodeOrignal = errorCode;
      if (errorCode == -1)
      {
        errorCode = 404;
      }
      response.setStatus(errorCode);

      if (response.isCommitted())
      {
        return;
      }

      response.reset();

      if (!(this.m_bUseVirtualLinkErrorPage))
      {
        response.sendError(errorCode);

        return;
      }

      StringBuffer buf = new StringBuffer(1024);
      String strHead = "" + errorCode;
      String strBody = "";
      try
      {
        Locale locale = request.getLocale();

        if ((strResolvedDocbasePath != null) && (strResolvedDocbasePath.length() > 0))
        {
          strHead = getResourceString("MSG_PARTIAL_404_HEAD", locale);
          strBody = MessageFormat.format(getResourceString("MSG_PARTIAL_404_BODY", locale), new Object[] { strResolvedDocbasePath });
        }
        else if (errorCodeOrignal == -1)
        {
          strHead = getResourceString("MSG_TEMPORARY_404_HEAD", locale);
          strBody = getResourceString("MSG_TEMPORARY_404_BODY", locale);
        }
        else
        {
          strHead = getResourceString("MSG_" + errorCode + "_HEAD", locale);
          strBody = getResourceString("MSG_" + errorCode + "_BODY", locale);
        }
      }
      catch (Exception e)
      {
        Trace.error(this, "VirtualLink404Handler", e);
      }

      buf.append("<html><head><title>" + errorCode + "</title></head><body><p><font face='Arial' size='4'>");
      buf.append(strHead);
      buf.append("</font></p><hr/><p><font face='Arial' size='3'>");
      buf.append(strBody);
      buf.append("</font></p></body>");
      for (int i = 0; i < 10; ++i)
      {
        buf.append("                                                  ");
      }
      buf.append("</html>");

      response.setStatus(errorCode);
      response.setLocale(request.getLocale());
      response.setContentType("text/html");
      response.setContentLength(buf.length());
      try
      {
        response.getWriter().print(buf.toString());
      }
      catch (IllegalStateException e)
      {
        response.getOutputStream().print(buf.toString());
      }
      response.flushBuffer();
    }
    catch (IOException e)
    {
      if (Trace.VIRTUALLINK != true) {
        return;
      }
      Trace.error(this, "VirtualLink404Handler", e);
    }
  }

  private void logRequestDetails(HttpServletRequest request)
  {
    if (Trace.VIRTUALLINKREQUEST != true)
      return;
    String message = null; String type = null; String uri = null;
    Object codeObj = null; Object messageObj = null; Object typeObj = null;

    codeObj = request.getAttribute("javax.servlet.error.status_code");
    messageObj = request.getAttribute("javax.servlet.error.message");
    typeObj = request.getAttribute("javax.servlet.error.exception_type");
    Throwable throwable = (Throwable)request.getAttribute("javax.servlet.error.exception");
    uri = (String)request.getAttribute("javax.servlet.error.request_uri");
    if (uri != null)
    {
      Trace.println("VirtualLink404Handler:Request: Uri = " + uri);
    }
    else
    {
      uri = request.getRequestURI();
      Trace.println("VirtualLink404Handler:Request: Uri = " + uri);
    }

    if (codeObj != null)
    {
      Trace.println("VirtualLink404Handler:Request: Error Status Code = " + codeObj.toString());
    }
    if (messageObj != null)
    {
      message = messageObj.toString();
      Trace.println("VirtualLink404Handler:Request: Error Message = " + message);
    }
    if (typeObj != null)
    {
      type = typeObj.toString();
      Trace.println("VirtualLink404Handler:Request: Exception Type = " + type);
    }
    if (throwable == null)
      return;
    Trace.error(this, "VirtualLink404Handler", throwable);
  }

  static String getRequestParameter(HttpServletRequest request, String strParam)
  {
    String strValue = request.getParameter(strParam);
    if ((strValue != null) && (strValue.length() > 0))
    {
      strValue = URLDecoder.decode(strValue);
    }
    else
    {
      strValue = null;
    }
    return strValue;
  }

  private Iterator getRootPaths(HttpServletRequest request)
  {
    String strRootPaths = getRequestParameter(request, "rootpaths");
    if (strRootPaths != null)
    {
      setRootPathsInSession(request, strRootPaths);
    }
    else
    {
      strRootPaths = getRootPathsFromSession(request);
    }

    ArrayList arrListRootPaths = new ArrayList();
    if (strRootPaths != null)
    {
      StringTokenizer st = new StringTokenizer(strRootPaths, LINE_SEPARATOR);
      while (st.hasMoreTokens() == true)
      {
        String strRootPath = st.nextToken();
        arrListRootPaths.add(strRootPath);
      }
    }

    return arrListRootPaths.iterator();
  }

  private String getRootPathsFromSession(HttpServletRequest request)
  {
    String strResult = null;
    String strDocbase = getDocbaseName(request);
    String strAppName = getWdkAppName(request);
    String key = strDocbase + "." + strAppName;
    HttpSession session = request.getSession();
    HashMap rootPaths = (HashMap)session.getAttribute("rptable");
    if (rootPaths != null)
    {
      strResult = (String)rootPaths.get(key);
    }

    return strResult;
  }

  private void setRootPathsInSession(HttpServletRequest request, String strRootPaths)
  {
    String strDocbase = getDocbaseFromRequest(request);
    String strAppName = getWdkAppName(request);
    String key = strDocbase + "." + strAppName;
    HttpSession session = request.getSession();

    HashMap rootPaths = (HashMap)session.getAttribute("rptable");
    if (rootPaths == null)
    {
      synchronized (session)
      {
        rootPaths = (HashMap)session.getAttribute("rptable");
        if (rootPaths == null)
        {
          rootPaths = new HashMap();
          session.setAttribute("rptable", rootPaths);
        }
      }
    }

    rootPaths.put(key, strRootPaths);
  }

  private void sendObjectContent(HttpServletResponse response, VirtualLinkContent content)
    throws DfException, IOException
  {
    IDfFormat format = content.getFormat();
    String strMimeType = format.getMIMEType();
    if ((strMimeType == null) || (strMimeType.trim().equals("")))
    {
      strMimeType = "text/plain";
    }

    response.setStatus(200);

    response.setContentType(strMimeType);

    String strFilename = content.getFilePath();
    File fileContent = new File(strFilename);
    FileInputStream fileInputStream = new FileInputStream(fileContent);
    try
    {
      OutputStream responseOutputStream = response.getOutputStream();
      byte[] buffer = new byte[2048];
      int nRead = fileInputStream.read(buffer);
      while (nRead >= 0)
      {
        responseOutputStream.write(buffer, 0, nRead);
        nRead = fileInputStream.read(buffer);

        responseOutputStream.flush();
      }
      responseOutputStream.flush();
    }
    finally
    {
      fileInputStream.close();
    }
  }

  protected String getResourceString(String strResourceKey, Locale locale)
  {
    ResourceBundle bundle = ResourceBundle.getBundle("com.documentum.web.virtuallink.VirtualLinkNlsProp", locale);

    return bundle.getString(strResourceKey);
  }

  private static String getDocbaseName(HttpServletRequest request)
  {
    String strDocbase = null;

    strDocbase = getDocbaseFromRequest(request);
    if (strDocbase == null)
    {
      strDocbase = (String)request.getSession().getAttribute("com.documentum.web.virtuallink.docbase");
    }

    if ((strDocbase != null) && (strDocbase.length() > 0))
    {
      setDocbaseName(request, strDocbase);
    }
    return strDocbase;
  }

  private static String getDocbaseFromRequest(HttpServletRequest request)
  {
    String strDocbaseName = null;

    strDocbaseName = getRequestParameter(request, "docbase");
    if ((strDocbaseName == null) || (strDocbaseName.length() < 1))
    {
      String strVirtualLinkPath = getRelativeVirtualLinkUri(request);

      if ((strVirtualLinkPath != null) && (strVirtualLinkPath.length() > 0))
      {
        int idxDocbasePostSlash = strVirtualLinkPath.indexOf(47, 1);
        if ((idxDocbasePostSlash > 1) && (strVirtualLinkPath.charAt(idxDocbasePostSlash - 1) == ':'))
        {
          strDocbaseName = strVirtualLinkPath.substring(1, idxDocbasePostSlash - 1);
        }
      }
    }
    return strDocbaseName;
  }

  private static void setDocbaseName(HttpServletRequest request, String strDocbase)
  {
    request.getSession().setAttribute("com.documentum.web.virtuallink.docbase", strDocbase);
  }

  private static boolean hasTicket(HttpServletRequest request)
  {
    String strTicket = getRequestParameter(request, "ticket");
    return ((strTicket != null) && (strTicket.length() > 0));
  }

private void StampDoc(VirtualLinkContent content, IDfSession dfSession) throws IOException  {	
String cPath;
	
	System.out.println("Entering StampDoc....");
	cPath = content.getFilePath() + ".wmk.pdf";
	
	watermarkStampPDF(content.getFilePath());
	
	content.setFilePath(cPath);
	System.out.println("Document stamped: " + cPath);
		
	System.out.println("finished!");
		
	return;

}	
	public static void watermarkStampPDF(String thePDF) {
		System.out.println("Webtop Stamper -  Creates a PDF file, then stamps extra content on it:");
		// we create a PDF file
		// now we are going to inspect it
		try {
			// we create a PdfReader object
			PdfReader reader = new PdfReader(thePDF);
			PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(thePDF + ".wmk.pdf"));
			// we create an Image we'll use as a Watermark
//			Image img = Image.getInstance("resources/in_action/chapter02/watermark.jpg");
//			img.setAbsolutePosition(200, 400);
			// we create a Font for the text to add
			BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
			// these are the canvases we are going to use
			PdfContentByte under, over;
			int total = reader.getNumberOfPages() + 1;
			for (int i = 1; i < total; i++) {
				stamper.setRotateContents(false);
				under = stamper.getUnderContent(i);
//				under.addImage(img);
				// text over the existing page
				over = stamper.getOverContent(i);
				over.beginText();
				over.setFontAndSize(bf, 18);
				over.setTextMatrix(30, 30);
				over.showText("Approved Document - Do Not Modify" );
				over.endText();
				over.setRGBColorStroke(0xFF, 0x00, 0x00);
				over.setLineWidth(5f);
				over.ellipse(250, 450, 350, 550);
				over.stroke();
			}
			stamper.close();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		}
	}
 

}
