1 4 5 9 10 14 15 package org.openlaszlo.compiler; 16 import org.openlaszlo.utils.StringUtils; 17 import org.openlaszlo.xml.internal.XMLUtils; 18 import org.openlaszlo.server.Configuration; 19 import org.openlaszlo.server.LPS; 20 import java.util.*; 21 import java.io.Serializable ; 22 import java.io.File ; 23 import org.jdom.Element; 24 import org.jdom.Namespace; 25 import org.apache.log4j.Logger; 26 27 public class Canvas implements java.io.Serializable { 28 29 32 private static Logger mLogger = Logger.getLogger(Canvas.class); 33 34 35 private static final int DEFAULT_WIDTH = 500; 36 37 38 private static final int DEFAULT_HEIGHT = 400; 39 40 41 private static final int DEFAULT_BGCOLOR = 0xFFFFFF; 42 43 44 private static final String DEFAULT_TITLE = "Laszlo Application"; 45 46 47 public static final String DEFAULT_VERSION = "1.1"; 49 50 public static final String DEFAULT_SWF6_FONT = "Verdana,Vera,sans-serif"; 52 53 public static final String DEFAULT_FONT = "default"; 54 public static final String DEFAULT_FONT_FILENAME = "verity" + File.separator + "verity11.ttf"; 55 public static final String DEFAULT_BOLD_FONT_FILENAME = "verity" + File.separator + "verity11bold.ttf"; 56 public static final String DEFAULT_ITALIC_FONT_FILENAME = "verity" + File.separator + "verity11italic.ttf"; 57 public static final String DEFAULT_BOLD_ITALIC_FONT_FILENAME = "verity" + File.separator + "verity11bolditalic.ttf"; 58 59 public String defaultFont () { 60 if (mSWFVersion.equals( "swf5" )) { 61 return DEFAULT_FONT; 62 } else { 63 return DEFAULT_SWF6_FONT; 64 } 65 } 66 67 public String defaultFontsize () { 68 if (mSWFVersion.equals( "swf5" )) { 69 return DEFAULT_FONTSIZE; 70 } else { 71 return DEFAULT_SWF6_FONTSIZE; 72 } 73 } 74 75 76 public static final String DEFAULT_FONTSIZE = "8"; 77 public static final String DEFAULT_SWF6_FONTSIZE = "11"; 78 public static final String DEFAULT_FONTSTYLE = ""; 79 80 81 private static final long DEFAULT_HEARTBEAT = 5000; private static final boolean DEFAULT_SENDUSERDISCONNECT = false; 83 84 public String defaultFont = DEFAULT_FONT; 85 public String defaultFontFilename = DEFAULT_FONT_FILENAME; 86 public String defaultBoldFontFilename = DEFAULT_BOLD_FONT_FILENAME; 87 public String defaultItalicFontFilename = DEFAULT_ITALIC_FONT_FILENAME; 88 public String defaultBoldItalicFontFilename = DEFAULT_BOLD_ITALIC_FONT_FILENAME; 89 90 91 private String mFilePath = null; 92 93 private int mWidth = DEFAULT_WIDTH; 94 95 private int mHeight = DEFAULT_HEIGHT; 96 97 private int mBGColor = DEFAULT_BGCOLOR; 98 99 private String mWidthString = null; 101 private String mHeightString = null; 102 103 private boolean mProxied = true; 105 106 108 private int mMaxTextWidth = 0; 109 110 112 private int mMaxTextHeight = 0; 113 114 115 private FontInfo mFontInfo = null; 116 117 118 private String mTitle = DEFAULT_TITLE; 119 120 121 private String mSWFVersion = LPS.getProperty("compiler.runtime.default", "swf6"); 122 123 124 private boolean mIsConnected = false; 125 private boolean mSendUserDisconnect = false; 126 private long mHeartbeat = 0; 127 private String mAuthenticator = null; 128 private String mGroup = null; 129 private Set mAgents = null; 130 131 private final Map mSecurityOptions = new Hashtable(); 132 133 private String mCompilationWarningText = null; 134 private String mCompilationWarningXML = null; 135 private Element mInfo = new org.jdom.Element("stats"); 136 137 public void setCompilationWarningText(String text) { 138 mCompilationWarningText = text; 139 } 140 141 public void setCompilationWarningXML(String xml) { 142 mCompilationWarningXML = xml; 143 } 144 145 public void setSWFVersion(String text) { 146 mSWFVersion = text; 147 } 148 149 public String getSWFVersion() { 150 return mSWFVersion; 151 } 152 153 public void addInfo(Element info) { 154 mInfo.addContent(info); 155 } 156 157 public String getCompilationWarningText() { 158 return mCompilationWarningText; 159 } 160 161 public void setFontInfo(FontInfo info) { 162 mFontInfo = info; 163 } 164 165 public String getInfoAsString() { 166 org.jdom.output.XMLOutputter outputter = 167 new org.jdom.output.XMLOutputter(); 168 outputter.setTextNormalize(true); 169 return outputter.outputString(mInfo); 170 } 171 172 173 public String getFilePath() { 174 return mFilePath; 175 } 176 177 178 public void setFilePath(String filePath) { 179 mFilePath = filePath; 180 } 181 182 183 public int getWidth() { 184 return mWidth; 185 } 186 187 188 public String getWidthXML() { 189 if (mWidthString == null) 190 return "" + mWidth; 191 else 192 return mWidthString; 193 } 194 195 196 public void setWidth(int w) { 197 mWidth = w; 198 } 199 200 201 public void setWidthString(String w) { 202 mWidthString = w; 203 } 204 205 206 207 public int getHeight() { 208 return mHeight; 209 } 210 211 212 public String getHeightXML() { 213 if (mHeightString == null) 214 return "" + mHeight; 215 else 216 return mHeightString; 217 } 218 219 220 public void setHeight(int h) { 221 mHeight = h; 222 } 223 224 225 public void setHeightString(String h) { 226 mHeightString = h; 227 } 228 229 230 231 public int getMaxTextWidth() { 232 return mMaxTextWidth; 233 } 234 235 236 public void setMaxTextWidth(int h) { 237 mMaxTextWidth = h; 238 } 239 240 241 public int getMaxTextHeight() { 242 return mMaxTextHeight; 243 } 244 245 246 public void setMaxTextHeight(int h) { 247 mMaxTextHeight = h; 248 } 249 250 251 252 public int getBGColor() { 253 return mBGColor; 254 } 255 256 257 public String getBGColorString() { 259 String red = Integer.toHexString((mBGColor >> 16) & 0xff); 260 String green = Integer.toHexString((mBGColor >> 8) & 0xff); 261 String blue = Integer.toHexString(mBGColor & 0xff); 262 if (red.length() == 1) 263 red = "0" + red; 264 if (green.length() == 1) 265 green = "0" + green; 266 if (blue.length() == 1) 267 blue = "0" + blue; 268 return "#" + red + green + blue; 269 } 270 271 272 public void setBGColor(int BGColor) { 273 mBGColor = BGColor; 274 } 275 276 277 public String getTitle() { 278 return mTitle; 279 280 } 281 282 public String getISBN() { 283 return "192975213X"; 284 } 285 286 287 public void setTitle(String t) { 288 mTitle = t; 289 } 290 291 292 public long getHeartbeat() { 293 return mHeartbeat; 294 295 } 296 297 298 public void setHeartbeat(long heartbeat) { 299 mHeartbeat = heartbeat; 300 } 301 302 303 public String getGroup() { 304 return mGroup; 305 306 } 307 308 309 public void setGroup(String g) { 310 mGroup = g; 311 } 312 313 314 public String getAuthenticator() { 315 return mAuthenticator; 316 317 } 318 319 320 public void setAuthenticator(String a) { 321 mAuthenticator = a; 322 } 323 324 325 public boolean doSendUserDisconnect() { 326 return mSendUserDisconnect; 327 } 328 329 330 public void setSendUserDisconnect(boolean sud) { 331 mSendUserDisconnect = sud; 332 } 333 334 335 public void setProxied(boolean val) { 336 mProxied = val; 337 } 338 339 340 public boolean isProxied() { 341 return mProxied; 342 } 343 344 345 public boolean isConnected() { 346 return mIsConnected; 347 } 348 349 350 public void setIsConnected(boolean isConnected) { 351 mIsConnected = isConnected; 352 } 353 354 355 public Set getAgents() { 356 return mAgents; 357 } 358 359 360 public void addAgent(String agent) { 361 if (mAgents == null) 362 mAgents = new HashSet(); 363 mAgents.add(agent); 364 } 365 366 367 368 public FontInfo getFontInfo() { 369 return mFontInfo; 370 } 371 372 373 public Map getSecurityOptions() { 374 return mSecurityOptions; 375 } 376 377 378 public void setSecurityOptions(Element element) { 379 Configuration.addOption(mSecurityOptions, element); 380 } 381 382 public String getXML(String content) { 383 StringBuffer buffer = new StringBuffer (); 384 buffer.append( 385 "<canvas " + 386 "title=\"" + XMLUtils.escapeXml(getTitle()) + "\" " + 387 "bgcolor=\"" + getBGColorString() + "\" " + 388 "width=\"" + getWidthXML() + "\" " + 389 "height=\"" + getHeightXML() + "\" " + 390 "runtime=\"" + getSWFVersion() +"\" " + 391 ">"); 392 buffer.append(content); 393 buffer.append(getInfoAsString()); 394 if (mCompilationWarningXML != null) 395 buffer.append("<warnings>" + mCompilationWarningXML + "</warnings>"); 396 buffer.append("</canvas>"); 397 return buffer.toString(); 398 } 399 400 403 protected void initializeConnection(Element elt) { 404 Element eltConnection = elt.getChild("connection", elt.getNamespace()); 407 if (eltConnection!=null) { 408 409 setIsConnected(true); 410 setSendUserDisconnect(DEFAULT_SENDUSERDISCONNECT); 411 setHeartbeat(DEFAULT_HEARTBEAT); 412 413 String heartbeat = eltConnection.getAttributeValue("heartbeat"); 414 if (heartbeat != null) { 415 try { 416 setHeartbeat(Long.parseLong(heartbeat)); 417 } catch (NumberFormatException e) { 418 throw new CompilationError(elt, "heartbeat", e); 419 } 420 } 421 422 String sendUserDisconnect = 423 eltConnection.getAttributeValue("receiveuserdisconnect"); 424 if (sendUserDisconnect != null) { 425 setSendUserDisconnect(Boolean.valueOf(sendUserDisconnect).booleanValue()); 426 } 427 428 String group = eltConnection.getAttributeValue("group"); 429 if (group != null) { 430 setGroup(group); 431 } 432 433 String authenticator = eltConnection.getAttributeValue("authenticator"); 437 if (authenticator != null) { 438 setAuthenticator(authenticator); 439 } 440 441 List agents = eltConnection.getChildren("agent", elt.getNamespace()); 442 for (int i=0; i < agents.size(); i++) { 443 Element eltAgent = (Element)agents.get(i); 444 String url = eltAgent.getAttributeValue("url"); 445 if (url != null || ! url.equals("")) 446 addAgent(url); 447 } 448 } 449 } 450 } 451 | Popular Tags |