001/* Attribute for inserting HTML text into the page exported by Export to Web. 002 003 Copyright (c) 2011-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028 029package ptolemy.vergil.basic.export.web; 030 031import ptolemy.kernel.util.IllegalActionException; 032import ptolemy.kernel.util.NameDuplicationException; 033import ptolemy.kernel.util.NamedObj; 034 035/////////////////////////////////////////////////////////////////// 036//// HTMLText 037/** 038 * Attribute for inserting HTML text into the page exported by Export to Web. 039 * Drag its icon onto the background of a model, and specify the HTML text to 040 * export (double click on the attribute to set the text). 041 * By default, this text will be placed before the image for the model, 042 * after the title, but you can change the position by setting the 043 * <i>textPosition</i> parameter. You can also separately control what 044 * text is displayed in the model, or make the attribute disappear altogether 045 * in the model (for this, just set <i>displayText</i> to an empty string). 046 * 047 * @author Edward A. Lee 048 * @version $Id$ 049 * @since Ptolemy II 10.0 050 * @Pt.ProposedRating Red (cxh) 051 * @Pt.AcceptedRating Red (cxh) 052 */ 053public class HTMLText extends WebContent { 054 055 /** Create an instance of this parameter. 056 * @param container The container. 057 * @param name The name. 058 * @exception IllegalActionException If the superclass throws it. 059 * @exception NameDuplicationException If the superclass throws it. 060 */ 061 public HTMLText(NamedObj container, String name) 062 throws IllegalActionException, NameDuplicationException { 063 super(container, name); 064 textPosition = new HTMLTextPosition(this, "textPosition"); 065 } 066 067 /////////////////////////////////////////////////////////////////// 068 //// parameters //// 069 070 /** Parameter specifying the position into which to export HTML text. 071 * The parameter offers the following possibilities: 072 * <ul> 073 * <li><b>end</b>: Put the text at the end of the HTML file. 074 * <li><b>header</b>: Put the text in the header section. 075 * <li><b>start</b>: Put the text at the start of the body section. 076 * <li><i>anything_else</i>: Put the text in a div of this name. 077 * </ul> 078 * The default is "start". 079 */ 080 public HTMLTextPosition textPosition; 081 082 /////////////////////////////////////////////////////////////////// 083 //// public methods //// 084 085 /** HTMLText is of type text/html. 086 * 087 * @return The string text/html 088 */ 089 @Override 090 public String getMimeType() { 091 return "text/html"; 092 } 093 094 /** Return true, since new content should overwrite old. 095 * 096 * @return true, since new content should overwrite old 097 */ 098 @Override 099 public boolean isOverwriteable() { 100 return true; 101 } 102 103 /** Generate a <div> element holding the text content. 104 * 105 * @param exporter The WebExporter to add content to 106 * @exception IllegalActionException If something is wrong generating the 107 * web content 108 */ 109 @Override 110 protected void _provideElements(WebExporter exporter) 111 throws IllegalActionException { 112 WebElement webElement = WebElement.createWebElement(getContainer(), 113 getName() + "WebElement", getName() + "WebElement"); 114 webElement.setExpression("<div>" + stringValue() + "</div>"); 115 webElement.setParent(textPosition.stringValue()); 116 117 // Add text content. Text should only be added once (onceOnly -> true). 118 exporter.defineElement(webElement, true); 119 120 } 121}