import mir.entity.*;
import mir.entity.adapter.*;
import mircoders.entity.*;
+import mircoders.storage.*;
//because images are returned as a template model!
import freemarker.template.*;
int numCharsInAnImagelessRow = (new Float(numLinesBetweenImages * (contentAreaWidthCM/characterWidthCM))).intValue();
-
+
+ boolean outOfText = false;
+
ArrayList brokenUpContent = new ArrayList();
- //yikes! a templatemodel....why is freemarker in the backend?
- TemplateModel images=entity.get("to_media_images");
+
+ EntityList images=DatabaseContentToMedia.getInstance().getImages((EntityContent)entity);
if (images == null){
HashMap row = new HashMap();
row.put("text",((EntityContent) entity).getValue("content_data"));
brokenUpContent.add(row);
}
if (images != null){
+ //need to add checks for out of content!
HashMap row0 = new HashMap();
- row0.put("text",((EntityContent) entity).getValue("content_data").substring(0,numCharsInAnImagelessRow));
+ if (numCharsInAnImagelessRow>(((EntityContent) entity).getValue("content_data")).length()){
+ row0.put("text",((EntityContent) entity).getValue("content_data"));
+ outOfText = true;
+ }
+ else {
+ row0.put("text",((EntityContent) entity).getValue("content_data").substring(0,numCharsInAnImagelessRow));
+ }
+
brokenUpContent.add(row0);
currentPosition=numCharsInAnImagelessRow;
-
- while(((SimpleList)images).hasNext()){
+ aLogger.println("CP1 is "+ currentPosition);
+ while(images.hasNext()){
HashMap row1 = new HashMap();
HashMap row2 = new HashMap();
+ EntityImages currentImage=(EntityImages) images.next();
+ float img_width=(new Float(currentImage.getValue("img_width"))).floatValue();
+ float img_height=(new Float(currentImage.getValue("img_height"))).floatValue();
+
+ //oversize images must be shrunk
+ if (img_width>400){
+ img_height=(new Float((new Float(img_height*(400.0F/img_width))).intValue())).floatValue();
+ img_width=400.0F;
+ }
- float img_width=(new Float(((EntityImages)((SimpleList)images).next()).getValue("img_width"))).floatValue();
- float img_height=(new Float(((EntityImages)((SimpleList)images).next()).getValue("img_height"))).floatValue();
//calculate how much text goes in the column
- float text_widthCM = contentAreaWidthCM-(img_width*pixelWidthCM)/characterWidthCM;
+ float text_widthCM = contentAreaWidthCM-(img_width*pixelWidthCM);
float number_of_lines = img_height*pixelWidthCM/lineHeightCM; //don't worry we will make it an int
- int text_amount= (new Float(text_widthCM*number_of_lines)).intValue();
+ int text_amount= (new Float((text_widthCM/characterWidthCM)*number_of_lines)).intValue();
row1.put("text_widthCM",Float.toString(text_widthCM));
+
+
+
row1.put("img_width",Float.toString(img_width));
row1.put("img_height",Float.toString(img_height));
- row1.put("img_src",((EntityImages)((SimpleList)images).next()).getValue("source"));
-
- row1.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition,currentPosition+text_amount));
+ aLogger.println("img_width " +Float.toString(img_width));
+ aLogger.println("img_height "+Float.toString(img_height));
+
+ row1.put("img_src",currentImage.getValue("source"));
+
+ if (! outOfText){
+ try {
+ row1.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition,currentPosition+text_amount));
+ }
+ catch (IndexOutOfBoundsException e){
+ row1.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition));
+ outOfText = true;
+ }
+ }
currentPosition=currentPosition+text_amount;
+ aLogger.println("CP2 is "+ currentPosition);
brokenUpContent.add(row1);
- row2.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition,currentPosition+numCharsInAnImagelessRow));
+ if (! outOfText){
+ try {
+ row2.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition,currentPosition+numCharsInAnImagelessRow));
+ }
+ catch (IndexOutOfBoundsException e){
+ row2.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition));
+ outOfText = true;
+ }
+ }
brokenUpContent.add(row2);
currentPosition=currentPosition+numCharsInAnImagelessRow;
+ aLogger.println("CP3 is "+ currentPosition);
}
HashMap row3 = new HashMap();
- row3.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition));
- brokenUpContent.add(row3);
+ if (! outOfText){
+ row3.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition));
+ brokenUpContent.add(row3);
+ }
+
}
"data.formatted_content",
new CachingRewindableIterator(brokenUpContent.iterator())
);
- // aValueMap.put("test_content",((EntityContent) entity).getValue("content_data"));
+
}
catch (Throwable t) {