Example usage for com.lowagie.text.xml SAXmyHandler SAXmyHandler

List of usage examples for com.lowagie.text.xml SAXmyHandler SAXmyHandler

Introduction

In this page you can find the example usage for com.lowagie.text.xml SAXmyHandler SAXmyHandler.

Prototype


public SAXmyHandler(DocListener document, HashMap myTags) 

Source Link

Document

Constructs a new SAXiTextHandler that will translate all the events triggered by the parser to actions on the Document-object.

Usage

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private int createPasswordLetterContent(DocumentPrintContext dpc) throws ContentCreationException {
    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
    System.out.println("Default locale: "
            + getIWApplicationContext().getApplicationSettings().getDefaultLocale().toString());
    String sAddrString = "";
    PdfContentByte cb = dpc.getPdfWriter().getDirectContent();
    Document document = dpc.getDocument();
    Locale locale = dpc.getLocale();
    PrintMessage msg = dpc.getMessage();
    // String mail_zip = iwb.getProperty("commune.mail_zip");
    // String mail_name = iwb.getProperty("commune.mail_name");

    try {/*from ww  w . j  ava 2s.  c  om*/
        sAddrString = getAddressString(dpc.getMessage().getOwner());
    } catch (Exception nouser) {
        handleNoAddressUser();
        System.err.println(nouser.getMessage());
        // nouser.printStackTrace();
        return ADDRESS_ERROR;
    }
    try {
        if (addTemplateHeader()) {
            ColumnText ct = new ColumnText(cb);
            float margin = getPointsFromMM(14);
            float lly = getPointsFromMM(297 - 22);
            float ury = lly + 60f;
            float urx = 595f - margin - 60f - 5f;
            float llx = 110f + margin;
            Phrase Ph0 = new Phrase(sAddrString, new Font(Font.HELVETICA, 12, Font.BOLD));
            ct.setSimpleColumn(Ph0, llx, lly, urx, ury, 15, Element.ALIGN_LEFT);
            ct.go();

            document.add(new Paragraph("\n\n\n\n\n\n\n"));
        }

        {

            User owner = msg.getOwner();
            HashMap tagmap = new CommuneUserTagMap(getIWApplicationContext(), owner);
            tagmap.putAll(getMessageTagMap(msg, locale));

            XmlPeer date = new XmlPeer(ElementTags.CHUNK, "date");
            date.setContent(new IWTimestamp().getDateString("dd.MM.yyyy"));
            tagmap.put(date.getAlias(), date);
            System.out.println("Date tag: " + date.getTag());

            String letterUrl = getXMLLetterUrl(iwb, locale, "password_letter.xml");
            if (msg.getBody().indexOf("|") > 0) {
                StringTokenizer tokenizer = new StringTokenizer(msg.getBody(), "|");
                XmlPeer peer = new XmlPeer(ElementTags.ITEXT, "letter");
                tagmap.put(peer.getAlias(), peer);

                if (tokenizer.hasMoreTokens()) {
                    peer = new XmlPeer(ElementTags.CHUNK, "username");
                    peer.setContent(tokenizer.nextToken());
                    tagmap.put(peer.getAlias(), peer);
                }
                if (tokenizer.hasMoreTokens()) {
                    peer = new XmlPeer(ElementTags.CHUNK, "password");
                    peer.setContent(tokenizer.nextToken());
                    tagmap.put(peer.getAlias(), peer);
                }

            }
            javax.xml.parsers.SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            SAXmyHandler handler = new SAXmyHandler(document, tagmap);
            handler.setControlOpenClose(false);

            parser.parse(letterUrl, handler);
        }
    } catch (Exception e) {
        throw new ContentCreationException(e);
    }

    return 0;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private int createDefaultLetterContent(DocumentPrintContext dpc) throws ContentCreationException {
    try {/*from  w  w  w . j a va2  s.com*/
        IWBundle iwb = getIWApplicationContext().getIWMainApplication()
                .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
        PdfWriter writer = dpc.getPdfWriter();
        Document document = dpc.getDocument();
        Locale locale = dpc.getLocale();
        PrintMessage msg = dpc.getMessage();

        createLogoContent(document);
        String addressString = getAddressString(msg.getOwner());
        createAddressContent(addressString, writer);

        document.add(new Paragraph("\n\n\n\n\n\n\n\n"));

        {
            User owner = msg.getOwner();
            HashMap tagmap = new CommuneUserTagMap(getIWApplicationContext(), owner);
            tagmap.putAll(getMessageTagMap(msg, locale));

            String letterUrl = getXMLLetterUrl(iwb, locale, "default_letter.xml", true);

            SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            SAXmyHandler handler = new SAXmyHandler(document, tagmap);
            handler.setControlOpenClose(false);

            parser.parse(letterUrl, handler);

        }

        createCommuneFooter(writer);
    } catch (Exception e) {
        throw new ContentCreationException(e);
    }

    return 0;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public void createArchiveMessageContent(DocumentPrintContext dpc) throws ContentCreationException {
    try {//from  ww w. j  a v  a  2  s  . c  o  m
        IWBundle iwb = getIWApplicationContext().getIWMainApplication()
                .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
        // IWResourceBundle iwrb = iwb.getResourceBundle(locale);

        // DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT,locale);
        PrintMessage msg = dpc.getMessage();
        Locale locale = dpc.getLocale();
        User owner = msg.getOwner();
        HashMap tagmap = new CommuneUserTagMap(getIWApplicationContext(), owner);
        tagmap.putAll(getMessageTagMap(msg, locale));

        String letterUrl = getXMLLetterUrl(iwb, locale, "archive_letter.xml");

        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        SAXmyHandler handler = new SAXmyHandler(dpc.getDocument(), tagmap);
        handler.setControlOpenClose(false);

        parser.parse(letterUrl, handler);
    } catch (Exception e) {
        throw new ContentCreationException(e);
    }
}