From 8ce64979e91ff880d966501093222e7c2812c645 Mon Sep 17 00:00:00 2001 From: john Date: Thu, 12 Sep 2002 00:46:17 +0000 Subject: [PATCH] soon this will be a producers.xml pluggable node that will allow one to take content data and use java to do page layout/typography calculations so that one can actually make a useful pdf using mir. right now it is just a (working) skeleton that needs to be filled in with some math, and generalized a bit --- .../producer/PDFPreFormattingProducerNode.java | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 source/mircoders/producer/PDFPreFormattingProducerNode.java diff --git a/source/mircoders/producer/PDFPreFormattingProducerNode.java b/source/mircoders/producer/PDFPreFormattingProducerNode.java new file mode 100755 index 00000000..cac93457 --- /dev/null +++ b/source/mircoders/producer/PDFPreFormattingProducerNode.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.producer; + +import java.util.*; +import java.io.*; +import mir.util.*; +import mir.producer.*; +import mir.entity.*; +import mir.entity.adapter.*; +import mircoders.entity.*; + +//because images are returned as a template model! +import freemarker.template.*; + + +public class PDFPreFormattingProducerNode implements ProducerNode { + private String contentKey; + + public PDFPreFormattingProducerNode(String aContentKey) { + contentKey = aContentKey; + } + + public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure { + Object data; + Entity entity; + + try { + data = ParameterExpander.findValueForKey( aValueMap, contentKey ); + + if (! (data instanceof EntityAdapter)) { + throw new ProducerFailure("ContentMarkingProducerNode: value of '"+contentKey+"' is not an EntityAdapter, but an " + data.getClass().getName(), null); + } + + entity = ((EntityAdapter) data).getEntity(); + if (! (entity instanceof EntityContent)) { + throw new ProducerFailure("ContentMarkingProducerNode: value of '"+contentKey+"' is not a content EntityAdapter, but a " + entity.getClass().getName() + " adapter", null); + } + + int numLinesBetweenImages = 3; + float characterWidthCM = 0.17F; + float contentAreaWidthCM = 16; + float pixelWidthCM = .03F; + float lineHeightCM = .5F; + + int numCharsInAnImagelessRow = (new Float(numLinesBetweenImages * (contentAreaWidthCM/characterWidthCM))).intValue(); + + + //yikes! a templatemodel....why is freemarker in the backend? + TemplateModel images=entity.get("to_media_images"); + if (images != null){ + HashMap row = new HashMap(); + row.put("text",((EntityContent) entity).getValue("content_data").substring(0,numCharsInAnImagelessRow)); + } + + ArrayList brokenUpContent = new ArrayList(); + + + brokenUpContent.add("hello"); + brokenUpContent.add("goodbye"); + + ParameterExpander.setValueForKey( + aValueMap, + "data.formatted_content", + new CachingRewindableIterator(brokenUpContent.iterator()) + ); + // aValueMap.put("test_content",((EntityContent) entity).getValue("content_data")); + + } + catch (Throwable t) { + aLogger.println("Error while formatting content for PDF: " + t.getMessage()); + t.printStackTrace(aLogger); + + throw new ProducerFailure(t.getMessage(), t); + } + } + + public Set buildVerbSet() { + return new HashSet(); + } +} + + -- 2.11.0