Friday, July 27, 2012

Send a responseText to JavaScript from Struts 1.3 Action Class Method


Struts 1.3 Action class method

public ActionForward deleteIfesSystem(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws IOException {
        Integer ifesSystemKey = Integer.parseInt(request.getParameter("ifesSystemKey"));
        // Set IFES System properties
        IFESystem ifeSystem = IFESystemManager.getIFESystem(ifesSystemKey);
        String error = "OK";      
        try {
            IFESystemManager.deleteIFESSystem(ifeSystem);
        }
        catch (HibernateException e) {
            error = "IFES System cannot be deleted.";
        }      
        response.getWriter().write(error);
        response.getWriter().close();
        return null;
    }

JavaScript ajax function


function deleteOnClick() {
    if (confirm("Do you want to delete the selected IFES System?")) {
        var params = new Array();
        params.push("action=deleteIfesSystem");
        params.push("ifesSystemKey=" + ifesSystemGrid.getSelectedId());
        var request = new ServerRequest( url + params.join("&"), null, false);
        var xmlhttp = request.send();
        debugger
        if (xmlhttp.responseText == "OK") {
            ifesSystemGrid.deleteRow(ifesSystemGrid.getSelectedId());
            alert("IFES System deleted.");
        }
        else {
            alert(xmlhttp.responseText);
        }
    }
}

Labels: ,

Monday, July 16, 2012

Mount Windows Shared folder into Linux Box

mount.cifs //smfs01/DR/swmonitor /mnt/swmonitor/ -ousername=xxx,password=xxx,domain=PROxy

Reference
http://www.stevens.edu/itwiki/w/index.php/Linux_Map_a_Network_Drive

Labels:

Thursday, July 12, 2012

iText

Set Zoom Size

PdfReader pdf = new PdfReader("abc.pdf");
PdfStamper stp = new PdfStamper(pdf, new
FileOutputStream("abcout.pdf"));
PdfWriter writer = stp.getWriter();
PdfAction ac = PdfAction.gotoLocalPage(1, new
PdfDestination(PdfDestination.XYZ, -1, -1, 0.1f), writer);
writer.setOpenAction(ac);
stp.close(); 
Set PDF on the Fly

public ActionForward showGraphic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IOException, DocumentException {
        String[] imgPaths = (request.getParameter("imgPath") != null)
                ? request.getParameter("imgPath").split(",") : null;
        String imgarea = request.getParameter("imgarea");
        Float height = Float.valueOf(request.getParameter("height"));
        Float width = Float.valueOf(request.getParameter("width"));
        Rectangle rectangle;
        rectangle = new Rectangle(Float.valueOf(width), Float.valueOf(height));
        ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
        Document document = new Document(rectangle);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, baosPDF);
        pdfWriter.setViewerPreferences(pdfWriter.PageModeUseOutlines);
        document.open();
        for (String imgPath : imgPaths) {
            File file = new File(request.getSession().getServletContext().getRealPath("").replace("editor", "webdav")
                    + imgPath.split("webdav")[1]);
            if(file.exists()) {
                Image image = Image.getInstance(file.getPath());
                image.scaleToFit(("BP".equals(imgarea)) ? width - 100f : width - 80f, height);
                document.add(image);
            }
            else {
                logger.error("Editor -> Graphic Preview -> File not found : " + file.getPath());
                Paragraph paragraph = new Paragraph();
                Chunk chunk = new Chunk("Image not found!");
                paragraph.add(chunk);
                document.add(paragraph);
            }
        }
        float zoom = 0f;
        if ("AP".equals(imgarea)) {
            zoom = 0.53f;
        }
        else if ("BP".equals(imgarea)) {
            zoom = 0.51f;
        }
        else {
            zoom = 0.52f;
        }
        PdfAction ac = PdfAction.gotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, -1, zoom), pdfWriter);
        pdfWriter.setOpenAction(ac);
        document.close();
        response.setContentType("application/pdf");
        response.addHeader("Content-Disposition", "inline; filename=preview.pdf");
        OutputStream out = response.getOutputStream();
        out.write(baosPDF.toByteArray());
        out.flush();
        out.close();
        return null;
    }

References
http://www.coderanch.com/t/494982/open-source/iText-PDF-export
http://www.opensubscriber.com/message/itext-questions@lists.sourceforge.net/3903218.html
http://itextpdf.com/examples/iia.php?id=17

Labels: