1 22 23 package org.infoglue.cms.applications.contenttool.actions; 24 25 import java.awt.Font ; 26 import java.awt.GraphicsEnvironment ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.apache.log4j.Logger; 33 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 34 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService; 35 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController; 37 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeTypeDefinitionController; 38 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController; 39 import org.infoglue.cms.entities.management.AvailableServiceBindingVO; 40 import org.infoglue.cms.entities.management.SiteNodeTypeDefinitionVO; 41 import org.infoglue.cms.entities.structure.SiteNodeVO; 42 import org.infoglue.cms.entities.structure.SiteNodeVersionVO; 43 import org.infoglue.cms.exception.SystemException; 44 import org.infoglue.deliver.applications.databeans.DatabaseWrapper; 45 import org.infoglue.deliver.controllers.kernel.impl.simple.BasicTemplateController; 46 import org.infoglue.deliver.controllers.kernel.impl.simple.IntegrationDeliveryController; 47 import org.infoglue.deliver.controllers.kernel.impl.simple.NodeDeliveryController; 48 import org.infoglue.deliver.util.BrowserBean; 49 50 56 public class TextToImageEditorAction extends InfoGlueAbstractAction 57 { 58 private final static Logger logger = Logger.getLogger(TextToImageEditorAction.class.getName()); 59 60 private static final long serialVersionUID = 1L; 61 62 private Integer languageId = null; 63 private Integer contentId = null; 64 private Integer siteNodeId = null; 65 private Integer repositoryId = null; 66 67 70 71 private String [] defaultSizes = 72 { "8", "9", 73 "10","11","12","13","14","15","16","18","20","22", 74 "24","26","28","30","36","42","48","72" 75 }; 76 77 private String text = "Sample"; 78 private String canvasWidth = "200"; 79 private String canvasHeight = "50"; 80 private String textStartPosX = "0"; 81 private String textStartPosY = "0"; 82 private String textWidth = "20"; 83 private String textHeight = "20"; 84 private String fontName = "Serif"; 85 private String fontStyle = "0"; 86 private String fontSize = "12"; 87 private String foregroundColor = "000000"; 88 private String backgroundColor = "FFFFFF"; 89 90 91 private String generatedImage = ""; 92 private String generatedCommand = ""; 93 private Collection fontNames = new ArrayList (); 94 private Collection fonts = new ArrayList (); 95 private SiteNodeVO siteNodeVO; 96 private SiteNodeVersionVO siteNodeVersionVO; 97 private SiteNodeTypeDefinitionVO siteNodeTypeDefinitionVO; 98 private List availableServiceBindings; 99 private List serviceBindings; 100 101 public int getBoldValue() 102 { 103 return Font.BOLD; 104 } 105 public int getItalicValue() 106 { 107 return Font.ITALIC; 108 } 109 public String [] getSizes() 110 { 111 return defaultSizes; 112 } 113 114 115 private String q(String t) 116 { 117 return "\"" + t + "\""; 118 } 119 private String qc(String t) 120 { 121 return "\"" + t + "\", "; 122 } 123 private String c(String t) 124 { 125 return "" + t + ", "; 126 } 127 128 protected void initialize(Integer siteNodeId) throws Exception 129 { 130 this.siteNodeVO = SiteNodeController.getSiteNodeVOWithId(siteNodeId); 131 this.siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId); 132 133 if(siteNodeVO.getSiteNodeTypeDefinitionId() != null) 134 { 135 this.siteNodeTypeDefinitionVO = SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionVOWithId(siteNodeVO.getSiteNodeTypeDefinitionId()); 136 this.availableServiceBindings = SiteNodeTypeDefinitionController.getController().getAvailableServiceBindingVOList(siteNodeVO.getSiteNodeTypeDefinitionId()); 137 this.serviceBindings = SiteNodeVersionController.getServiceBindningVOList(siteNodeVersionVO.getSiteNodeVersionId()); 138 } 139 } 140 141 protected String doExecute() throws Exception 142 { 143 DatabaseWrapper dbWrapper = new DatabaseWrapper(CastorDatabaseService.getDatabase()); 144 146 beginTransaction(dbWrapper.getDatabase()); 147 148 try 149 { 150 if(siteNodeId==null) 151 siteNodeId = SiteNodeController.getController().getRootSiteNodeVO(repositoryId).getId(); 152 153 if(languageId==null) 154 languageId = LanguageController.getController().getMasterLanguage(repositoryId).getId(); 155 156 if(contentId==null) 157 contentId = new Integer (-1); 158 159 initialize(siteNodeId); 160 161 165 166 169 170 Font allFonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); 171 for(int i = 0;i<allFonts.length;i++) 172 { 173 fonts.add(allFonts[i]); 174 } 175 176 String [] fontNamesList = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); 177 for(int i = 0;i<fontNamesList.length;i++) 178 fontNames.add(fontNamesList[i]); 179 180 181 StringBuffer t = new StringBuffer (); 182 t.append("$templateLogic.getStringAsImageUrl("); 183 t.append(qc(text)); 184 t.append(c(canvasWidth)); 185 t.append(c(canvasHeight)); 186 t.append(c(textStartPosX)); 187 t.append(c(textStartPosY)); 188 t.append(c(textWidth)); 189 t.append(c(textHeight)); 190 t.append(qc(fontName)); 191 t.append(c(fontStyle)); 192 t.append(c(fontSize)); 193 t.append(qc(foregroundColor)); 194 t.append(q(backgroundColor)); 195 t.append(")"); 196 197 198 BasicTemplateController templateController = getTemplateController(dbWrapper, siteNodeId, languageId, contentId); 199 generatedImage = templateController.renderString(t.toString()); 200 generatedCommand = t.toString(); 201 202 203 closeTransaction(dbWrapper.getDatabase()); 204 } 205 catch(Exception e) 206 { 207 logger.error("An error occurred so we should not complete the transaction:" + e, e); 208 rollbackTransaction(dbWrapper.getDatabase()); 209 throw new SystemException(e.getMessage()); 210 } 211 212 return "success"; 213 } 214 215 public BasicTemplateController getTemplateController(DatabaseWrapper databaseWrapper, Integer siteNodeId, Integer languageId, Integer contentId) throws SystemException, Exception 216 { 217 BasicTemplateController templateController = new BasicTemplateController(databaseWrapper, this.getInfoGluePrincipal()); 218 templateController.setStandardRequestParameters(siteNodeId, languageId, contentId); 219 templateController.setHttpRequest(getRequest()); 220 templateController.setBrowserBean(new BrowserBean()); 221 templateController.setDeliveryControllers(NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId), null, IntegrationDeliveryController.getIntegrationDeliveryController(siteNodeId,languageId, contentId)); 222 return templateController; 223 } 224 225 public List getSortedAvailableServiceBindings() 226 { 227 List sortedAvailableServiceBindings = new ArrayList (); 228 229 Iterator iterator = this.availableServiceBindings.iterator(); 230 while(iterator.hasNext()) 231 { 232 AvailableServiceBindingVO availableServiceBinding = (AvailableServiceBindingVO)iterator.next(); 233 int index = 0; 234 Iterator sortedListIterator = sortedAvailableServiceBindings.iterator(); 235 while(sortedListIterator.hasNext()) 236 { 237 AvailableServiceBindingVO sortedAvailableServiceBinding = (AvailableServiceBindingVO)sortedListIterator.next(); 238 239 String currentAttribute = availableServiceBinding.getName(); 240 String sortedAttribute = sortedAvailableServiceBinding.getName(); 241 242 if(currentAttribute != null && sortedAttribute != null && currentAttribute.compareTo(sortedAttribute) < 0) 243 { 244 break; 245 } 246 index++; 247 } 248 sortedAvailableServiceBindings.add(index, availableServiceBinding); 249 } 250 251 return sortedAvailableServiceBindings; 252 } 253 254 257 258 public List getSortedAvailableContentServiceBindings() 259 { 260 List sortedAvailableContentServiceBindings = new ArrayList (); 261 262 Iterator sortedListIterator = getSortedAvailableServiceBindings().iterator(); 263 while(sortedListIterator.hasNext()) 264 { 265 AvailableServiceBindingVO sortedAvailableServiceBinding = (AvailableServiceBindingVO)sortedListIterator.next(); 266 if(sortedAvailableServiceBinding.getVisualizationAction().indexOf("Structure") == -1) 267 sortedAvailableContentServiceBindings.add(sortedAvailableServiceBinding); 268 } 269 270 return sortedAvailableContentServiceBindings; 271 } 272 public List getSortedAvailableSingleContentServiceBindings() 273 { 274 List sortedAvailableContentServiceBindings = new ArrayList (); 275 276 Iterator sortedListIterator = getSortedAvailableServiceBindings().iterator(); 277 while(sortedListIterator.hasNext()) 278 { 279 AvailableServiceBindingVO sortedAvailableServiceBinding = (AvailableServiceBindingVO)sortedListIterator.next(); 280 if(sortedAvailableServiceBinding.getVisualizationAction().indexOf("Structure") == -1 && 281 sortedAvailableServiceBinding.getVisualizationAction().indexOf("Multi") == -1 ) 282 sortedAvailableContentServiceBindings.add(sortedAvailableServiceBinding); 283 } 284 285 return sortedAvailableContentServiceBindings; 286 } 287 288 public List getAvailableAttributes() 289 { 290 List sortedAvailableContentServiceBindings = new ArrayList (); 291 292 Iterator sortedListIterator = getSortedAvailableServiceBindings().iterator(); 293 while(sortedListIterator.hasNext()) 294 { 295 AvailableServiceBindingVO sortedAvailableServiceBinding = (AvailableServiceBindingVO)sortedListIterator.next(); 296 if(sortedAvailableServiceBinding.getVisualizationAction().indexOf("Structure") == -1 && 297 sortedAvailableServiceBinding.getVisualizationAction().indexOf("Multi") == -1 ) 298 { 299 sortedAvailableContentServiceBindings.add(sortedAvailableServiceBinding); 300 301 } 302 303 } 304 305 306 307 return sortedAvailableContentServiceBindings; 308 } 309 310 313 314 public List getSortedAvailableStructureServiceBindings() 315 { 316 List sortedAvailableStructureServiceBindings = new ArrayList (); 317 318 Iterator sortedListIterator = getSortedAvailableServiceBindings().iterator(); 319 while(sortedListIterator.hasNext()) 320 { 321 AvailableServiceBindingVO sortedAvailableServiceBinding = (AvailableServiceBindingVO)sortedListIterator.next(); 322 if(sortedAvailableServiceBinding.getVisualizationAction().indexOf("Structure") > -1) 323 sortedAvailableStructureServiceBindings.add(sortedAvailableServiceBinding); 324 } 325 326 return sortedAvailableStructureServiceBindings; 327 } 328 329 330 public List getServiceBindings() 331 { 332 return this.serviceBindings; 333 } 334 335 336 public String getGeneratedImage() 337 { 338 return generatedImage; 339 } 340 341 public Collection getFonts() 342 { 343 return fonts; 344 } 345 348 public String getBackgroundColor() 349 { 350 return backgroundColor; 351 } 352 355 public void setBackgroundColor(String backgroundColor) 356 { 357 this.backgroundColor = backgroundColor; 358 } 359 362 public String getCanvasHeight() 363 { 364 return canvasHeight; 365 } 366 369 public void setCanvasHeight(String canvasHeight) 370 { 371 this.canvasHeight = canvasHeight; 372 } 373 376 public String getCanvasWidth() 377 { 378 return canvasWidth; 379 } 380 383 public void setCanvasWidth(String canvasWidth) 384 { 385 this.canvasWidth = canvasWidth; 386 } 387 390 public String getFontName() 391 { 392 return fontName; 393 } 394 397 public void setFontName(String fontName) 398 { 399 this.fontName = fontName; 400 } 401 404 public String getFontSize() 405 { 406 return fontSize; 407 } 408 411 public void setFontSize(String fontSize) 412 { 413 this.fontSize = fontSize; 414 } 415 418 public String getFontStyle() 419 { 420 return fontStyle; 421 } 422 425 public void setFontStyle(String fontStyle) 426 { 427 this.fontStyle = fontStyle; 428 } 429 432 public String getForegroundColor() 433 { 434 return foregroundColor; 435 } 436 439 public void setForegroundColor(String foregroundColor) 440 { 441 this.foregroundColor = foregroundColor; 442 } 443 446 public String getText() 447 { 448 return text; 449 } 450 453 public void setText(String text) 454 { 455 this.text = text; 456 } 457 460 public String getTextHeight() 461 { 462 return textHeight; 463 } 464 467 public void setTextHeight(String textHeight) 468 { 469 this.textHeight = textHeight; 470 } 471 474 public String getTextStartPosX() 475 { 476 return textStartPosX; 477 } 478 481 public void setTextStartPosX(String textStartPosX) 482 { 483 this.textStartPosX = textStartPosX; 484 } 485 488 public String getTextStartPosY() 489 { 490 return textStartPosY; 491 } 492 495 public void setTextStartPosY(String textStartPosY) 496 { 497 this.textStartPosY = textStartPosY; 498 } 499 502 public String getTextWidth() 503 { 504 return textWidth; 505 } 506 509 public void setTextWidth(String textWidth) 510 { 511 this.textWidth = textWidth; 512 } 513 516 public Collection getFontNames() 517 { 518 return fontNames; 519 } 520 523 public Integer getContentId() 524 { 525 return contentId; 526 } 527 530 public void setContentId(Integer contentId) 531 { 532 this.contentId = contentId; 533 } 534 537 public Integer getLanguageId() 538 { 539 return languageId; 540 } 541 544 public void setLanguageId(Integer languageId) 545 { 546 this.languageId = languageId; 547 } 548 551 public Integer getRepositoryId() 552 { 553 return repositoryId; 554 } 555 558 public void setRepositoryId(Integer repositoryId) 559 { 560 this.repositoryId = repositoryId; 561 } 562 565 public Integer getSiteNodeId() 566 { 567 return siteNodeId; 568 } 569 572 public void setSiteNodeId(Integer siteNodeId) 573 { 574 this.siteNodeId = siteNodeId; 575 } 576 579 public String getGeneratedCommand() 580 { 581 return generatedCommand; 582 } 583 586 public void setGeneratedCommand(String generatedCommand) 587 { 588 this.generatedCommand = generatedCommand; 589 } 590 } 591 | Popular Tags |