Moved code from separate MWebString class (web.ui) into MText class (text).
authorMarco Zanon <info@marcozanon.com>
Fri, 13 Apr 2012 20:29:43 +0000 (20:29 +0000)
committerMarco Zanon <info@marcozanon.com>
Fri, 13 Apr 2012 20:29:43 +0000 (20:29 +0000)
26 files changed:
src/java/com/marcozanon/macaco/text/MText.java
src/java/com/marcozanon/macaco/text/MXhtmlUnsafeStringTextException.java [new file with mode: 0644]
src/java/com/marcozanon/macaco/web/ui/MWebApplicationContext.java
src/java/com/marcozanon/macaco/web/ui/MWebBreadcrumbs.java
src/java/com/marcozanon/macaco/web/ui/MWebBrowserPage.java
src/java/com/marcozanon/macaco/web/ui/MWebCheckBox.java
src/java/com/marcozanon/macaco/web/ui/MWebComboBox.java
src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java
src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java
src/java/com/marcozanon/macaco/web/ui/MWebGridLayout.java
src/java/com/marcozanon/macaco/web/ui/MWebImage.java
src/java/com/marcozanon/macaco/web/ui/MWebImageButton.java
src/java/com/marcozanon/macaco/web/ui/MWebLabel.java
src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java
src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java
src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java
src/java/com/marcozanon/macaco/web/ui/MWebString.java [deleted file]
src/java/com/marcozanon/macaco/web/ui/MWebTable.java
src/java/com/marcozanon/macaco/web/ui/MWebTableCell.java
src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java
src/java/com/marcozanon/macaco/web/ui/MWebUploader.java
src/java/com/marcozanon/macaco/web/ui/MWebVerticalMenu.java
src/java/com/marcozanon/macaco/web/ui/MWebView.java
src/java/com/marcozanon/macaco/web/ui/MWebWysiwygBox.java
src/java/com/marcozanon/macaco/web/ui/MWebXhtmlLabel.java
src/java/com/marcozanon/macaco/web/ui/MXhtmlUnsafeStringWebException.java [deleted file]

index 2bed7140663b41b65a8a9c3d958267513405ba33..ae46b319acf420774acaa0a7a36dbdabc57f176e 100644 (file)
@@ -6,7 +6,23 @@
 
 package com.marcozanon.macaco.text;
 
+import com.marcozanon.macaco.MInformation;
 import com.marcozanon.macaco.MObject;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
 
 public class MText extends MObject {
 
@@ -33,4 +49,371 @@ public class MText extends MObject {
         return y.toString();
     }
 
+    /* Javascript escape */
+
+    public static String getJavascriptEscapedString(String x) {
+        if (null == x) {
+            return null;
+        }
+        //
+        String text = x;
+        //
+        text = text.replace("\\", "\\\\");
+        text = text.replace("'", "\\\'");
+        //
+        return text;
+    }
+
+    /* Xhtml escape and safety */
+
+    public static String getXhtmlEscapedString(String x) { // similar to PHP's htmlspecialchars()
+        if (null == x) {
+            return null;
+        }
+        //
+        String text = x;
+        //
+        text = text.replace("&", "&amp;");
+        text = text.replace("\"", "&quot;");
+        text = text.replace("'", "&apos;");
+        text = text.replace("<", "&lt;");
+        text = text.replace(">", "&gt;");
+        //
+        text = text.replace("\n", "<br />");
+        //
+        return text;
+    }
+
+    public static String getXhtmlNumericEntitiesString(String x) { // for compatibility with innerHTML
+        if (null == x) {
+            return null;
+        }
+        //
+        String text = x;
+        //
+        text = text.replace("&nbsp;", "&#160;");
+        text = text.replace("&iexcl;", "&#161;");
+        text = text.replace("&cent;", "&#162;");
+        text = text.replace("&pound;", "&#163;");
+        text = text.replace("&curren;", "&#164;");
+        text = text.replace("&yen;", "&#165;");
+        text = text.replace("&brvbar;", "&#166;");
+        text = text.replace("&sect;", "&#167;");
+        text = text.replace("&uml;", "&#168;");
+        text = text.replace("&copy;", "&#169;");
+        text = text.replace("&ordf;", "&#170;");
+        text = text.replace("&laquo;", "&#171;");
+        text = text.replace("&not;", "&#172;");
+        text = text.replace("&shy;", "&#173;");
+        text = text.replace("&reg;", "&#174;");
+        text = text.replace("&macr;", "&#175;");
+        text = text.replace("&deg;", "&#176;");
+        text = text.replace("&plusmn;", "&#177;");
+        text = text.replace("&sup2;", "&#178;");
+        text = text.replace("&sup3;", "&#179;");
+        text = text.replace("&acute;", "&#180;");
+        text = text.replace("&micro;", "&#181;");
+        text = text.replace("&para;", "&#182;");
+        text = text.replace("&middot;", "&#183;");
+        text = text.replace("&cedil;", "&#184;");
+        text = text.replace("&sup1;", "&#185;");
+        text = text.replace("&ordm;", "&#186;");
+        text = text.replace("&raquo;", "&#187;");
+        text = text.replace("&frac14;", "&#188;");
+        text = text.replace("&frac12;", "&#189;");
+        text = text.replace("&frac34;", "&#190;");
+        text = text.replace("&iquest;", "&#191;");
+        text = text.replace("&Agrave;", "&#192;");
+        text = text.replace("&Aacute;", "&#193;");
+        text = text.replace("&Acirc;", "&#194;");
+        text = text.replace("&Atilde;", "&#195;");
+        text = text.replace("&Auml;", "&#196;");
+        text = text.replace("&Aring;", "&#197;");
+        text = text.replace("&AElig;", "&#198;");
+        text = text.replace("&Ccedil;", "&#199;");
+        text = text.replace("&Egrave;", "&#200;");
+        text = text.replace("&Eacute;", "&#201;");
+        text = text.replace("&Ecirc;", "&#202;");
+        text = text.replace("&Euml;", "&#203;");
+        text = text.replace("&Igrave;", "&#204;");
+        text = text.replace("&Iacute;", "&#205;");
+        text = text.replace("&Icirc;", "&#206;");
+        text = text.replace("&Iuml;", "&#207;");
+        text = text.replace("&ETH;", "&#208;");
+        text = text.replace("&Ntilde;", "&#209;");
+        text = text.replace("&Ograve;", "&#210;");
+        text = text.replace("&Oacute;", "&#211;");
+        text = text.replace("&Ocirc;", "&#212;");
+        text = text.replace("&Otilde;", "&#213;");
+        text = text.replace("&Ouml;", "&#214;");
+        text = text.replace("&times;", "&#215;");
+        text = text.replace("&Oslash;", "&#216;");
+        text = text.replace("&Ugrave;", "&#217;");
+        text = text.replace("&Uacute;", "&#218;");
+        text = text.replace("&Ucirc;", "&#219;");
+        text = text.replace("&Uuml;", "&#220;");
+        text = text.replace("&Yacute;", "&#221;");
+        text = text.replace("&THORN;", "&#222;");
+        text = text.replace("&szlig;", "&#223;");
+        text = text.replace("&agrave;", "&#224;");
+        text = text.replace("&aacute;", "&#225;");
+        text = text.replace("&acirc;", "&#226;");
+        text = text.replace("&atilde;", "&#227;");
+        text = text.replace("&auml;", "&#228;");
+        text = text.replace("&aring;", "&#229;");
+        text = text.replace("&aelig;", "&#230;");
+        text = text.replace("&ccedil;", "&#231;");
+        text = text.replace("&egrave;", "&#232;");
+        text = text.replace("&eacute;", "&#233;");
+        text = text.replace("&ecirc;", "&#234;");
+        text = text.replace("&euml;", "&#235;");
+        text = text.replace("&igrave;", "&#236;");
+        text = text.replace("&iacute;", "&#237;");
+        text = text.replace("&icirc;", "&#238;");
+        text = text.replace("&iuml;", "&#239;");
+        text = text.replace("&eth;", "&#240;");
+        text = text.replace("&ntilde;", "&#241;");
+        text = text.replace("&ograve;", "&#242;");
+        text = text.replace("&oacute;", "&#243;");
+        text = text.replace("&ocirc;", "&#244;");
+        text = text.replace("&otilde;", "&#245;");
+        text = text.replace("&ouml;", "&#246;");
+        text = text.replace("&divide;", "&#247;");
+        text = text.replace("&oslash;", "&#248;");
+        text = text.replace("&ugrave;", "&#249;");
+        text = text.replace("&uacute;", "&#250;");
+        text = text.replace("&ucirc;", "&#251;");
+        text = text.replace("&uuml;", "&#252;");
+        text = text.replace("&yacute;", "&#253;");
+        text = text.replace("&thorn;", "&#254;");
+        text = text.replace("&yuml;", "&#255;");
+        text = text.replace("&OElig;", "&#338;");
+        text = text.replace("&oelig;", "&#339;");
+        text = text.replace("&Scaron;", "&#352;");
+        text = text.replace("&scaron;", "&#353;");
+        text = text.replace("&Yuml;", "&#376;");
+        text = text.replace("&fnof;", "&#402;");
+        text = text.replace("&circ;", "&#710;");
+        text = text.replace("&tilde;", "&#732;");
+        text = text.replace("&Alpha;", "&#913;");
+        text = text.replace("&Beta;", "&#914;");
+        text = text.replace("&Gamma;", "&#915;");
+        text = text.replace("&Delta;", "&#916;");
+        text = text.replace("&Epsilon;", "&#917;");
+        text = text.replace("&Zeta;", "&#918;");
+        text = text.replace("&Eta;", "&#919;");
+        text = text.replace("&Theta;", "&#920;");
+        text = text.replace("&Iota;", "&#921;");
+        text = text.replace("&Kappa;", "&#922;");
+        text = text.replace("&Lambda;", "&#923;");
+        text = text.replace("&Mu;", "&#924;");
+        text = text.replace("&Nu;", "&#925;");
+        text = text.replace("&Xi;", "&#926;");
+        text = text.replace("&Omicron;", "&#927;");
+        text = text.replace("&Pi;", "&#928;");
+        text = text.replace("&Rho;", "&#929;");
+        text = text.replace("&Sigma;", "&#931;");
+        text = text.replace("&Tau;", "&#932;");
+        text = text.replace("&Upsilon;", "&#933;");
+        text = text.replace("&Phi;", "&#934;");
+        text = text.replace("&Chi;", "&#935;");
+        text = text.replace("&Psi;", "&#936;");
+        text = text.replace("&Omega;", "&#937;");
+        text = text.replace("&alpha;", "&#945;");
+        text = text.replace("&beta;", "&#946;");
+        text = text.replace("&gamma;", "&#947;");
+        text = text.replace("&delta;", "&#948;");
+        text = text.replace("&epsilon;", "&#949;");
+        text = text.replace("&zeta;", "&#950;");
+        text = text.replace("&eta;", "&#951;");
+        text = text.replace("&theta;", "&#952;");
+        text = text.replace("&iota;", "&#953;");
+        text = text.replace("&kappa;", "&#954;");
+        text = text.replace("&lambda;", "&#955;");
+        text = text.replace("&mu;", "&#956;");
+        text = text.replace("&nu;", "&#957;");
+        text = text.replace("&xi;", "&#958;");
+        text = text.replace("&omicron;", "&#959;");
+        text = text.replace("&pi;", "&#960;");
+        text = text.replace("&rho;", "&#961;");
+        text = text.replace("&sigmaf;", "&#962;");
+        text = text.replace("&sigma;", "&#963;");
+        text = text.replace("&tau;", "&#964;");
+        text = text.replace("&upsilon;", "&#965;");
+        text = text.replace("&phi;", "&#966;");
+        text = text.replace("&chi;", "&#967;");
+        text = text.replace("&psi;", "&#968;");
+        text = text.replace("&omega;", "&#969;");
+        text = text.replace("&thetasym;", "&#977;");
+        text = text.replace("&upsih;", "&#978;");
+        text = text.replace("&piv;", "&#982;");
+        text = text.replace("&ensp;", "&#8194;");
+        text = text.replace("&emsp;", "&#8195;");
+        text = text.replace("&thinsp;", "&#8201;");
+        text = text.replace("&zwnj;", "&#8204;");
+        text = text.replace("&zwj;", "&#8205;");
+        text = text.replace("&lrm;", "&#8206;");
+        text = text.replace("&rlm;", "&#8207;");
+        text = text.replace("&ndash;", "&#8211;");
+        text = text.replace("&mdash;", "&#8212;");
+        text = text.replace("&lsquo;", "&#8216;");
+        text = text.replace("&rsquo;", "&#8217;");
+        text = text.replace("&sbquo;", "&#8218;");
+        text = text.replace("&ldquo;", "&#8220;");
+        text = text.replace("&rdquo;", "&#8221;");
+        text = text.replace("&bdquo;", "&#8222;");
+        text = text.replace("&dagger;", "&#8224;");
+        text = text.replace("&Dagger;", "&#8225;");
+        text = text.replace("&bull;", "&#8226;");
+        text = text.replace("&hellip;", "&#8230;");
+        text = text.replace("&permil;", "&#8240;");
+        text = text.replace("&prime;", "&#8242;");
+        text = text.replace("&Prime;", "&#8243;");
+        text = text.replace("&lsaquo;", "&#8249;");
+        text = text.replace("&rsaquo;", "&#8250;");
+        text = text.replace("&oline;", "&#8254;");
+        text = text.replace("&frasl;", "&#8260;");
+        text = text.replace("&euro;", "&#8364;");
+        text = text.replace("&image;", "&#8465;");
+        text = text.replace("&weierp;", "&#8472;");
+        text = text.replace("&real;", "&#8476;");
+        text = text.replace("&trade;", "&#8482;");
+        text = text.replace("&alefsym;", "&#8501;");
+        text = text.replace("&larr;", "&#8592;");
+        text = text.replace("&uarr;", "&#8593;");
+        text = text.replace("&rarr;", "&#8594;");
+        text = text.replace("&darr;", "&#8595;");
+        text = text.replace("&harr;", "&#8596;");
+        text = text.replace("&crarr;", "&#8629;");
+        text = text.replace("&lArr;", "&#8656;");
+        text = text.replace("&uArr;", "&#8657;");
+        text = text.replace("&rArr;", "&#8658;");
+        text = text.replace("&dArr;", "&#8659;");
+        text = text.replace("&hArr;", "&#8660;");
+        text = text.replace("&forall;", "&#8704;");
+        text = text.replace("&part;", "&#8706;");
+        text = text.replace("&exist;", "&#8707;");
+        text = text.replace("&empty;", "&#8709;");
+        text = text.replace("&nabla;", "&#8711;");
+        text = text.replace("&isin;", "&#8712;");
+        text = text.replace("&notin;", "&#8713;");
+        text = text.replace("&ni;", "&#8715;");
+        text = text.replace("&prod;", "&#8719;");
+        text = text.replace("&sum;", "&#8721;");
+        text = text.replace("&minus;", "&#8722;");
+        text = text.replace("&lowast;", "&#8727;");
+        text = text.replace("&radic;", "&#8730;");
+        text = text.replace("&prop;", "&#8733;");
+        text = text.replace("&infin;", "&#8734;");
+        text = text.replace("&ang;", "&#8736;");
+        text = text.replace("&and;", "&#8743;");
+        text = text.replace("&or;", "&#8744;");
+        text = text.replace("&cap;", "&#8745;");
+        text = text.replace("&cup;", "&#8746;");
+        text = text.replace("&int;", "&#8747;");
+        text = text.replace("&there4;", "&#8756;");
+        text = text.replace("&sim;", "&#8764;");
+        text = text.replace("&cong;", "&#8773;");
+        text = text.replace("&asymp;", "&#8776;");
+        text = text.replace("&ne;", "&#8800;");
+        text = text.replace("&equiv;", "&#8801;");
+        text = text.replace("&le;", "&#8804;");
+        text = text.replace("&ge;", "&#8805;");
+        text = text.replace("&sub;", "&#8834;");
+        text = text.replace("&sup;", "&#8835;");
+        text = text.replace("&nsub;", "&#8836;");
+        text = text.replace("&sube;", "&#8838;");
+        text = text.replace("&supe;", "&#8839;");
+        text = text.replace("&oplus;", "&#8853;");
+        text = text.replace("&otimes;", "&#8855;");
+        text = text.replace("&perp;", "&#8869;");
+        text = text.replace("&sdot;", "&#8901;");
+        text = text.replace("&lceil;", "&#8968;");
+        text = text.replace("&rceil;", "&#8969;");
+        text = text.replace("&lfloor;", "&#8970;");
+        text = text.replace("&rfloor;", "&#8971;");
+        text = text.replace("&lang;", "&#9001;");
+        text = text.replace("&rang;", "&#9002;");
+        text = text.replace("&loz;", "&#9674;");
+        text = text.replace("&spades;", "&#9824;");
+        text = text.replace("&clubs;", "&#9827;");
+        text = text.replace("&hearts;", "&#9829;");
+        text = text.replace("&diams;", "&#9830;");
+        //
+        return text;
+    }
+
+    public static String getXhtmlSafeString(String x) throws MXhtmlUnsafeStringTextException {
+        if (null == x) {
+            return null;
+        }
+        //
+        String text = x;
+        //
+        StringBuilder fakeXhtmlPageContent = new StringBuilder("");
+        fakeXhtmlPageContent.append(String.format("<?xml version=\"1.0\" encoding=\"%s\" ?>", MInformation.TEXT_ENCODING));
+        fakeXhtmlPageContent.append("<!DOCTYPE html SYSTEM \"fake-dtd\" >");
+        fakeXhtmlPageContent.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
+        fakeXhtmlPageContent.append("<head><title /></head>");
+        fakeXhtmlPageContent.append(String.format("<body>%s</body>", text));
+        fakeXhtmlPageContent.append("</html>");
+        // validate Xhtml (without dangerous tags and event attributes)
+        try {
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setValidating(true);
+            factory.setNamespaceAware(true);
+            SAXParser parser = factory.newSAXParser();
+            XMLReader reader = parser.getXMLReader();
+            reader.setEntityResolver(new EntityResolver() {
+
+                public InputSource resolveEntity(String publicId, String systemId) {
+                    return new InputSource(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("dtd/xhtml1-transitional-macaco-edit.dtd")));
+                }
+
+            });
+            reader.setContentHandler(new DefaultHandler() {
+
+                public void startElement(String namespaceUri, String strippedName, String tagName, Attributes attributes) throws SAXException {
+                    if ("script".equalsIgnoreCase(tagName)) {
+                        throw new SAXException(String.format("Tag not allowed: %s.", tagName));
+                    }
+                    for (int a = 0; a < attributes.getLength(); a++) {
+                        if (attributes.getLocalName(a).toLowerCase().startsWith("on")) {
+                            throw new SAXException(String.format("Attribute not allowed: %s.", attributes.getLocalName(a)));
+                        }
+                    }
+                }
+
+            });
+            reader.setErrorHandler(new ErrorHandler() {
+
+                public void error(SAXParseException exception) throws SAXException {
+                    throw new SAXException(exception);
+                }
+
+                public void fatalError(SAXParseException exception) throws SAXException {
+                    throw new SAXException(exception);
+                }
+
+                public void warning(SAXParseException exception) throws SAXException {
+                    throw new SAXException(exception);
+                }
+
+            });
+            //
+            reader.parse(new InputSource(new ByteArrayInputStream(fakeXhtmlPageContent.toString().getBytes(MInformation.TEXT_ENCODING))));
+        }
+        catch (ParserConfigurationException exception) { // cannot happen
+        }
+        catch (SAXException exception) {
+            throw new MXhtmlUnsafeStringTextException("Invalid 'x': unsafe tags or attributes inside.", exception);
+        }
+        catch (UnsupportedEncodingException exception) { // cannot happen
+        }
+        catch (IOException exception) { // cannot happen, put here not to bypass UnsupportedEncodingException
+        }
+        // also convert named entities to numeric entities
+        return MText.getXhtmlNumericEntitiesString(text);
+    }
+
 }
diff --git a/src/java/com/marcozanon/macaco/text/MXhtmlUnsafeStringTextException.java b/src/java/com/marcozanon/macaco/text/MXhtmlUnsafeStringTextException.java
new file mode 100644 (file)
index 0000000..462c2da
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Macaco
+ * Copyright (c) 2009-2012 Marco Zanon <info@marcozanon.com>.
+ * Released under MIT license (see LICENSE for details).
+ */
+
+package com.marcozanon.macaco.text;
+
+public class MXhtmlUnsafeStringTextException extends MTextException {
+
+    private static final long serialVersionUID = 0L;
+
+    /* */
+
+    public MXhtmlUnsafeStringTextException() {
+        super();
+    }
+
+    public MXhtmlUnsafeStringTextException(String message) {
+        super(message);
+    }
+
+    public MXhtmlUnsafeStringTextException(Throwable error) {
+        super(error);
+    }
+
+    public MXhtmlUnsafeStringTextException(String message, Throwable error) {
+        super(message, error);
+    }
+
+}
index 3737df1f6c927dcad5bccffc83a868a91cef5e38..7889949018c089bebb5344a126de2c989ac2707e 100644 (file)
@@ -8,6 +8,7 @@ package com.marcozanon.macaco.web.ui;
 
 import com.marcozanon.macaco.MInformation;
 import com.marcozanon.macaco.MObject;
+import com.marcozanon.macaco.text.MText;
 import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -196,7 +197,7 @@ public abstract class MWebApplicationContext extends MObject {
             content.append("    <body>" + NL);
             content.append("        <script type=\"text/javascript\">" + NL);
             content.append("        // <![CDATA[" + NL);
-            content.append(String.format("            parent.m_notificationArea.addMessage(%s, '%s');", error, MWebString.getJavascriptEscapedString(MWebString.getXhtmlEscapedString(message))));
+            content.append(String.format("            parent.m_notificationArea.addMessage(%s, '%s');", error, MText.getJavascriptEscapedString(MText.getXhtmlEscapedString(message))));
             content.append("        // ]]>" + NL);
             content.append("        </script>" + NL);
             content.append("    </body>" + NL);
@@ -217,7 +218,7 @@ public abstract class MWebApplicationContext extends MObject {
             }
         }
         else {
-            this.addPlainTextResponseContent(String.format("m_notificationArea.addMessage(%s, '%s');", error, MWebString.getJavascriptEscapedString(MWebString.getXhtmlEscapedString(message))));
+            this.addPlainTextResponseContent(String.format("m_notificationArea.addMessage(%s, '%s');", error, MText.getJavascriptEscapedString(MText.getXhtmlEscapedString(message))));
         }
     }
 
index 0763ecbfb6fbf2ca2357a87e9da002f28466a8c1..f00949f96a675fa2439fa5bdae3cee4dcb28967d 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 
@@ -60,16 +61,16 @@ public class MWebBreadcrumbs extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<div class=\"MWebBreadcrumbs %s\" style=\"display: inline-block;\" id=\"%s\"></div>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<div class=\"MWebBreadcrumbs %s\" style=\"display: inline-block;\" id=\"%s\"></div>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), this.getId()));
         //
         super.refresh();
         //
         StringBuilder content = new StringBuilder("");
-        content.append(String.format("<span class=\"MWebBreadcrumbPrefix %s\">%s</span>", customClasses, MWebString.getXhtmlEscapedString(this.getPrefix())));
+        content.append(String.format("<span class=\"MWebBreadcrumbPrefix %s\">%s</span>", customClasses, MText.getXhtmlEscapedString(this.getPrefix())));
         LinkedList<String> viewBreadcrumbs = this.getViewReference().getBrowserPageReference().getViewBreadcrumbs();
         for (int t = 0; t < viewBreadcrumbs.size(); t++) {
             content.append(" ");
@@ -78,13 +79,13 @@ public class MWebBreadcrumbs extends MWebDirectWidget {
             }
             if (t < (viewBreadcrumbs.size() - 1))  {
                 String onItemSelectionFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onItemSelection', {'viewCount': '%s'});", this.getId(), viewBreadcrumbs.size() - 1 - t);
-                content.append(String.format("<span class=\"MWebBreadcrumbItem %s\" onclick=\"%s\">%s</span>", customClasses, onItemSelectionFunction, MWebString.getXhtmlEscapedString(viewBreadcrumbs.get(t))));
+                content.append(String.format("<span class=\"MWebBreadcrumbItem %s\" onclick=\"%s\">%s</span>", customClasses, onItemSelectionFunction, MText.getXhtmlEscapedString(viewBreadcrumbs.get(t))));
             }
             else {
-                content.append(String.format("<span class=\"MWebBreadcrumbLastItem %s\">%s</span>", customClasses, MWebString.getXhtmlEscapedString(viewBreadcrumbs.get(t))));
+                content.append(String.format("<span class=\"MWebBreadcrumbLastItem %s\">%s</span>", customClasses, MText.getXhtmlEscapedString(viewBreadcrumbs.get(t))));
             }
         }
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(content.toString())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(content.toString())));
     }
 
     /* Messages */
index 14b35c58b7f74308614d33b3734d807a1c17f173..59368e4863fa56cae8ba2d11d73b9c4e619c42e0 100644 (file)
@@ -8,6 +8,7 @@ package com.marcozanon.macaco.web.ui;
 
 import com.marcozanon.macaco.MInformation;
 import com.marcozanon.macaco.MObject;
+import com.marcozanon.macaco.text.MText;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.Random;
@@ -282,7 +283,7 @@ public abstract class MWebBrowserPage extends MObject {
             throw new IllegalArgumentException("Invalid 'url': null or empty.");
         }
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("window.location = '%s';", MWebString.getJavascriptEscapedString(url)));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("window.location = '%s';", MText.getJavascriptEscapedString(url)));
     }
 
     /* Refresh */
@@ -290,7 +291,7 @@ public abstract class MWebBrowserPage extends MObject {
     protected void refresh() throws MResponseWebException {
         this.resetSecurityId();
         //
-        String cssSource = MWebString.getXhtmlEscapedString(this.getCssSource());
+        String cssSource = MText.getXhtmlEscapedString(this.getCssSource());
         if (null == cssSource) {
             cssSource = String.format("%s/coreResources/css/default.css", this.getApplicationContextReference().getRequestReference().getRequestURL());
         }
@@ -302,8 +303,8 @@ public abstract class MWebBrowserPage extends MObject {
         content.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">" + NL);
         content.append(NL);
         content.append("    <head>" + NL);
-        content.append(String.format("        <meta name=\"author\" content=\"%s\" />", MWebString.getXhtmlEscapedString(this.getAuthor())) + NL);
-        content.append(String.format("        <meta name=\"generator\" content=\"%s\" />", MWebString.getXhtmlEscapedString(MInformation.getMacacoFullName())) + NL);
+        content.append(String.format("        <meta name=\"author\" content=\"%s\" />", MText.getXhtmlEscapedString(this.getAuthor())) + NL);
+        content.append(String.format("        <meta name=\"generator\" content=\"%s\" />", MText.getXhtmlEscapedString(MInformation.getMacacoFullName())) + NL);
         content.append(String.format("        <meta http-equiv=\"Content-type\" content=\"%s\" />", MInformation.HttpContentType.XHTML.toString()) + NL);
         content.append(String.format("        <link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />", cssSource) + NL);
         content.append("        <title>Loading...</title>" + NL);
@@ -355,7 +356,7 @@ public abstract class MWebBrowserPage extends MObject {
                         + "        metaTags[m].setAttribute('content', '%s');"
                         + "    }"
                         + "}";
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format(commands, MWebString.getJavascriptEscapedString(this.getAuthor())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format(commands, MText.getJavascriptEscapedString(this.getAuthor())));
     }
 
     protected void refreshCssSource() throws MResponseWebException { // inspired by http://www.thesitewizard.com/javascripts/change-style-sheets.shtml
@@ -370,7 +371,7 @@ public abstract class MWebBrowserPage extends MObject {
                         + "        linkTags[l].href = '%s';"
                         + "    }"
                         + "}";
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format(commands, MWebString.getJavascriptEscapedString(cssSource)));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format(commands, MText.getJavascriptEscapedString(cssSource)));
     }
 
     /* Requests */
index 74d20b1b8164263f64e254cc99e91cca5abfa1e0..5a7f7446c84278adca13355211626ba15b317e24 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebCheckBox extends MWebDirectWidget {
@@ -113,12 +114,12 @@ public class MWebCheckBox extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onChangeFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onChange', {'checkedMode': (this.checked ? '1' : '0')});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"checkbox\" class=\"MWebCheckBox %s\" style=\"display: inline-block;\" onchange=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onChangeFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"checkbox\" class=\"MWebCheckBox %s\" style=\"display: inline-block;\" onchange=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onChangeFunction), this.getId()));
         //
         super.refresh();
         //
index e501ff8b0fa8aa3447783b81594e0a131bdede97..92add707be958e0434389db1edaefc1e25807173 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 
@@ -240,13 +241,13 @@ public class MWebComboBox extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'selectedItemKey': this.value});", this.getId());
         String onChangeFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onChange', {'selectedItemKey': this.value});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<select class=\"MWebComboBox %s\" style=\"display: inline-block;\" onblur=\"%s\" onchange=\"%s\" id=\"%s\"><option value=\"\"></option></select>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), MWebString.getJavascriptEscapedString(onChangeFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<select class=\"MWebComboBox %s\" style=\"display: inline-block;\" onblur=\"%s\" onchange=\"%s\" id=\"%s\"><option value=\"\"></option></select>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), MText.getJavascriptEscapedString(onChangeFunction), this.getId()));
         //
         super.refresh();
         //
@@ -262,7 +263,7 @@ public class MWebComboBox extends MWebDirectWidget {
         this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').options.length = 0; }", this.getId(), this.getId()));
         this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').options[$('%s').options.length] = new Option('', ''); }", this.getId(), this.getId(), this.getId()));
         for (String itemKey: this.getItemsReference().keySet()) {
-            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').options[$('%s').options.length] = new Option('%s', '%s'); }", this.getId(), this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getItemsReference().get(itemKey)), MWebString.getJavascriptEscapedString(itemKey)));
+            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').options[$('%s').options.length] = new Option('%s', '%s'); }", this.getId(), this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getItemsReference().get(itemKey)), MText.getJavascriptEscapedString(itemKey)));
         }
     }
 
index b9cfb14cfb557f571ba0cce722c91d1198105b16..a8a34547026e5db0483f9618970536bdc8e44359 100644 (file)
@@ -8,6 +8,7 @@ package com.marcozanon.macaco.web.ui;
 
 import com.marcozanon.macaco.conversion.MDateConverter;
 import com.marcozanon.macaco.conversion.MFormatConversionException;
+import com.marcozanon.macaco.text.MText;
 import java.util.Date;
 
 public class MWebDateBox extends MWebTextBox {
@@ -92,12 +93,12 @@ public class MWebDateBox extends MWebTextBox {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebDateBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebDateBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId()));
         //
         super.refresh();
         //
index 4ef73a363fc2d34c326307dce958c157a07113ff..7e5dd97c28d6020540ef4ad0615966fd1d2c3642 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebExtendedTextBox extends MWebTextBox {
@@ -27,12 +28,12 @@ public class MWebExtendedTextBox extends MWebTextBox {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<textarea class=\"MWebExtendedTextBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" cols=\"1\" rows=\"1\"></textarea>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<textarea class=\"MWebExtendedTextBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" cols=\"1\" rows=\"1\"></textarea>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId()));
         //
         super.refresh();
         //
index f7bc4a2b7a70b59e5c8210fa34712151c379aa7f..5b8bfee708c93e6e8ab06d74ddf9d7a84a987f28 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebGridLayout extends MWebDirectWidget {
@@ -138,7 +139,7 @@ public class MWebGridLayout extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
@@ -157,7 +158,7 @@ public class MWebGridLayout extends MWebDirectWidget {
             content.append("</tr>");
         }
         content.append("</table>");
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(content.toString())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(content.toString())));
         //
         for (int r = 0; r < this.getRowCount(); r++) {
             for (int c = 0; c < this.getColumnCount(); c++) {
index 53d1004ef7ac94a6be25b618b436cb27a110c69f..6688ddffbc60cd7ae88a48783c7bbfc80404f5dd 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebImage extends MWebDirectWidget {
@@ -91,13 +92,13 @@ public class MWebImage extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onClick', {});", this.getId());
         String onDoubleClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onDoubleClick', {});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<img class=\"MWebImage %s\" style=\"display: inline-block;\" onclick=\"%s\" ondblclick=\"%s\" id=\"%s\" src=\"%s/null\" alt=\"\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onClickFunction), MWebString.getJavascriptEscapedString(onDoubleClickFunction), this.getId(), this.getApplicationContextReference().getRequestReference().getRequestURL()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<img class=\"MWebImage %s\" style=\"display: inline-block;\" onclick=\"%s\" ondblclick=\"%s\" id=\"%s\" src=\"%s/null\" alt=\"\" />'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onClickFunction), MText.getJavascriptEscapedString(onDoubleClickFunction), this.getId(), this.getApplicationContextReference().getRequestReference().getRequestURL()));
         //
         super.refresh();
         //
@@ -112,14 +113,14 @@ public class MWebImage extends MWebDirectWidget {
             this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').src = '%s/null'; }", this.getId(), this.getId(), this.getApplicationContextReference().getRequestReference().getRequestURL()));
         }
         else {
-            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').src = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getImageSource())));
+            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').src = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getImageSource())));
         }
     }
 
     protected void refreshAlternativeText() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
         this.checkPresence();
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').alt = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getAlternativeText())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').alt = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getAlternativeText())));
     }
 
     /* Messages */
index aef97c2782c19459b8c35aa80f66085b8ebf5bfa..e01c168b57ea347f190ace36727c43dce2e947da 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebImageButton extends MWebDirectWidget {
@@ -201,7 +202,7 @@ public class MWebImageButton extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
@@ -245,7 +246,7 @@ public class MWebImageButton extends MWebDirectWidget {
         }
         content.append("</table>");
         String onClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onClick', {});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<button class=\"MWebImageButton %s\" style=\"display: inline-block;\" onclick=\"%s\" id=\"%s\">%s</button>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onClickFunction), this.getId(), MWebString.getJavascriptEscapedString(content.toString())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<button class=\"MWebImageButton %s\" style=\"display: inline-block;\" onclick=\"%s\" id=\"%s\">%s</button>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onClickFunction), this.getId(), MText.getJavascriptEscapedString(content.toString())));
         //
         super.refresh();
         //
@@ -257,7 +258,7 @@ public class MWebImageButton extends MWebDirectWidget {
     protected void refreshText() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
         this.checkPresence();
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s_textCell').innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getText())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s_textCell').innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getText())));
     }
 
     protected void refreshImageSource() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
@@ -269,7 +270,7 @@ public class MWebImageButton extends MWebDirectWidget {
                 this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s_image').src = '%s/null'; }", this.getId(), this.getId(), this.getApplicationContextReference().getRequestReference().getRequestURL()));
             }
             else {
-                this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s_image').src = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getImageSource())));
+                this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s_image').src = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getImageSource())));
             }
         }
         catch (MNullPropertyWebException exception) {
index e130aeffb41ad4dcfc1d6dcbe8428d995bb78752..f589ce8b7d314007d71a906df5e2b4c2c74a5485 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebLabel extends MWebDirectWidget {
@@ -111,13 +112,13 @@ public class MWebLabel extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onClick', {});", this.getId());
         String onDoubleClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onDoubleClick', {});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<div class=\"MWebLabel %s\" style=\"display: inline-block;\" onclick=\"%s\" ondblclick=\"%s\" id=\"%s\"></div>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onClickFunction), MWebString.getJavascriptEscapedString(onDoubleClickFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<div class=\"MWebLabel %s\" style=\"display: inline-block;\" onclick=\"%s\" ondblclick=\"%s\" id=\"%s\"></div>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onClickFunction), MText.getJavascriptEscapedString(onDoubleClickFunction), this.getId()));
         //
         super.refresh();
         //
@@ -128,7 +129,7 @@ public class MWebLabel extends MWebDirectWidget {
     protected void refreshText() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
         this.checkPresence();
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(MWebString.getXhtmlEscapedString(this.getText()))));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(MText.getXhtmlEscapedString(this.getText()))));
     }
 
     protected void refreshTextAlignment(boolean directRefreshMode) throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
index 958c6a4f1eb3ed0a0a3fb4a3b6f8ed9c4dbe6c55..8cdabc1a5304a4747269d4733a26d03dbcf1cc34 100644 (file)
@@ -8,6 +8,7 @@ package com.marcozanon.macaco.web.ui;
 
 import com.marcozanon.macaco.conversion.MFormatConversionException;
 import com.marcozanon.macaco.conversion.MNumberConverter;
+import com.marcozanon.macaco.text.MText;
 import java.math.BigDecimal;
 
 public class MWebNumberBox extends MWebTextBox {
@@ -92,12 +93,12 @@ public class MWebNumberBox extends MWebTextBox {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebNumberBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebNumberBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId()));
         //
         super.refresh();
         //
index 28401b17186ca071b3033c2bc3a8fb8151a06108..91a857c0d02dee5433984717ad94609eba95edd8 100644 (file)
@@ -6,6 +6,8 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
+
 public class MWebPasswordBox extends MWebTextBox {
 
     /* */
@@ -25,12 +27,12 @@ public class MWebPasswordBox extends MWebTextBox {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"password\" class=\"MWebPasswordBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"password\" class=\"MWebPasswordBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId()));
         //
         super.refresh();
         //
index 630a07e5180f58a67eadfdbb25f40b46a571a20f..63eba858375cde1fb3586f7121df1c01816a9b4f 100644 (file)
@@ -6,6 +6,8 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
+
 public class MWebSimpleTextBox extends MWebTextBox {
 
     /* */
@@ -25,12 +27,12 @@ public class MWebSimpleTextBox extends MWebTextBox {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onBlurFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onBlur', {'text': this.value});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebSimpleTextBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<input type=\"text\" class=\"MWebSimpleTextBox %s\" style=\"display: inline-block;\" onblur=\"%s\" id=\"%s\" />'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId()));
         //
         super.refresh();
         //
diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebString.java b/src/java/com/marcozanon/macaco/web/ui/MWebString.java
deleted file mode 100644 (file)
index cca589a..0000000
+++ /dev/null
@@ -1,402 +0,0 @@
-/**
- * Macaco
- * Copyright (c) 2009-2012 Marco Zanon <info@marcozanon.com>.
- * Released under MIT license (see LICENSE for details).
- */
-
-package com.marcozanon.macaco.web.ui;
-
-import com.marcozanon.macaco.MInformation;
-import com.marcozanon.macaco.MObject;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
-
-public class MWebString extends MObject {
-
-    /* */
-
-    public MWebString() {
-        super();
-    }
-
-    /* Javascript escape */
-
-    public static String getJavascriptEscapedString(String x) {
-        if (null == x) {
-            return null;
-        }
-        //
-        String text = x;
-        //
-        text = text.replace("\\", "\\\\");
-        text = text.replace("'", "\\\'");
-        //
-        return text;
-    }
-
-    /* Xhtml escape and safety */
-
-    public static String getXhtmlEscapedString(String x) { // similar to PHP's htmlspecialchars()
-        if (null == x) {
-            return null;
-        }
-        //
-        String text = x;
-        //
-        text = text.replace("&", "&amp;");
-        text = text.replace("\"", "&quot;");
-        text = text.replace("'", "&apos;");
-        text = text.replace("<", "&lt;");
-        text = text.replace(">", "&gt;");
-        //
-        text = text.replace("\n", "<br />");
-        //
-        return text;
-    }
-
-    public static String getXhtmlNumericEntitiesString(String x) { // for compatibility with innerHTML
-        if (null == x) {
-            return null;
-        }
-        //
-        String text = x;
-        //
-        text = text.replace("&nbsp;", "&#160;");
-        text = text.replace("&iexcl;", "&#161;");
-        text = text.replace("&cent;", "&#162;");
-        text = text.replace("&pound;", "&#163;");
-        text = text.replace("&curren;", "&#164;");
-        text = text.replace("&yen;", "&#165;");
-        text = text.replace("&brvbar;", "&#166;");
-        text = text.replace("&sect;", "&#167;");
-        text = text.replace("&uml;", "&#168;");
-        text = text.replace("&copy;", "&#169;");
-        text = text.replace("&ordf;", "&#170;");
-        text = text.replace("&laquo;", "&#171;");
-        text = text.replace("&not;", "&#172;");
-        text = text.replace("&shy;", "&#173;");
-        text = text.replace("&reg;", "&#174;");
-        text = text.replace("&macr;", "&#175;");
-        text = text.replace("&deg;", "&#176;");
-        text = text.replace("&plusmn;", "&#177;");
-        text = text.replace("&sup2;", "&#178;");
-        text = text.replace("&sup3;", "&#179;");
-        text = text.replace("&acute;", "&#180;");
-        text = text.replace("&micro;", "&#181;");
-        text = text.replace("&para;", "&#182;");
-        text = text.replace("&middot;", "&#183;");
-        text = text.replace("&cedil;", "&#184;");
-        text = text.replace("&sup1;", "&#185;");
-        text = text.replace("&ordm;", "&#186;");
-        text = text.replace("&raquo;", "&#187;");
-        text = text.replace("&frac14;", "&#188;");
-        text = text.replace("&frac12;", "&#189;");
-        text = text.replace("&frac34;", "&#190;");
-        text = text.replace("&iquest;", "&#191;");
-        text = text.replace("&Agrave;", "&#192;");
-        text = text.replace("&Aacute;", "&#193;");
-        text = text.replace("&Acirc;", "&#194;");
-        text = text.replace("&Atilde;", "&#195;");
-        text = text.replace("&Auml;", "&#196;");
-        text = text.replace("&Aring;", "&#197;");
-        text = text.replace("&AElig;", "&#198;");
-        text = text.replace("&Ccedil;", "&#199;");
-        text = text.replace("&Egrave;", "&#200;");
-        text = text.replace("&Eacute;", "&#201;");
-        text = text.replace("&Ecirc;", "&#202;");
-        text = text.replace("&Euml;", "&#203;");
-        text = text.replace("&Igrave;", "&#204;");
-        text = text.replace("&Iacute;", "&#205;");
-        text = text.replace("&Icirc;", "&#206;");
-        text = text.replace("&Iuml;", "&#207;");
-        text = text.replace("&ETH;", "&#208;");
-        text = text.replace("&Ntilde;", "&#209;");
-        text = text.replace("&Ograve;", "&#210;");
-        text = text.replace("&Oacute;", "&#211;");
-        text = text.replace("&Ocirc;", "&#212;");
-        text = text.replace("&Otilde;", "&#213;");
-        text = text.replace("&Ouml;", "&#214;");
-        text = text.replace("&times;", "&#215;");
-        text = text.replace("&Oslash;", "&#216;");
-        text = text.replace("&Ugrave;", "&#217;");
-        text = text.replace("&Uacute;", "&#218;");
-        text = text.replace("&Ucirc;", "&#219;");
-        text = text.replace("&Uuml;", "&#220;");
-        text = text.replace("&Yacute;", "&#221;");
-        text = text.replace("&THORN;", "&#222;");
-        text = text.replace("&szlig;", "&#223;");
-        text = text.replace("&agrave;", "&#224;");
-        text = text.replace("&aacute;", "&#225;");
-        text = text.replace("&acirc;", "&#226;");
-        text = text.replace("&atilde;", "&#227;");
-        text = text.replace("&auml;", "&#228;");
-        text = text.replace("&aring;", "&#229;");
-        text = text.replace("&aelig;", "&#230;");
-        text = text.replace("&ccedil;", "&#231;");
-        text = text.replace("&egrave;", "&#232;");
-        text = text.replace("&eacute;", "&#233;");
-        text = text.replace("&ecirc;", "&#234;");
-        text = text.replace("&euml;", "&#235;");
-        text = text.replace("&igrave;", "&#236;");
-        text = text.replace("&iacute;", "&#237;");
-        text = text.replace("&icirc;", "&#238;");
-        text = text.replace("&iuml;", "&#239;");
-        text = text.replace("&eth;", "&#240;");
-        text = text.replace("&ntilde;", "&#241;");
-        text = text.replace("&ograve;", "&#242;");
-        text = text.replace("&oacute;", "&#243;");
-        text = text.replace("&ocirc;", "&#244;");
-        text = text.replace("&otilde;", "&#245;");
-        text = text.replace("&ouml;", "&#246;");
-        text = text.replace("&divide;", "&#247;");
-        text = text.replace("&oslash;", "&#248;");
-        text = text.replace("&ugrave;", "&#249;");
-        text = text.replace("&uacute;", "&#250;");
-        text = text.replace("&ucirc;", "&#251;");
-        text = text.replace("&uuml;", "&#252;");
-        text = text.replace("&yacute;", "&#253;");
-        text = text.replace("&thorn;", "&#254;");
-        text = text.replace("&yuml;", "&#255;");
-        text = text.replace("&OElig;", "&#338;");
-        text = text.replace("&oelig;", "&#339;");
-        text = text.replace("&Scaron;", "&#352;");
-        text = text.replace("&scaron;", "&#353;");
-        text = text.replace("&Yuml;", "&#376;");
-        text = text.replace("&fnof;", "&#402;");
-        text = text.replace("&circ;", "&#710;");
-        text = text.replace("&tilde;", "&#732;");
-        text = text.replace("&Alpha;", "&#913;");
-        text = text.replace("&Beta;", "&#914;");
-        text = text.replace("&Gamma;", "&#915;");
-        text = text.replace("&Delta;", "&#916;");
-        text = text.replace("&Epsilon;", "&#917;");
-        text = text.replace("&Zeta;", "&#918;");
-        text = text.replace("&Eta;", "&#919;");
-        text = text.replace("&Theta;", "&#920;");
-        text = text.replace("&Iota;", "&#921;");
-        text = text.replace("&Kappa;", "&#922;");
-        text = text.replace("&Lambda;", "&#923;");
-        text = text.replace("&Mu;", "&#924;");
-        text = text.replace("&Nu;", "&#925;");
-        text = text.replace("&Xi;", "&#926;");
-        text = text.replace("&Omicron;", "&#927;");
-        text = text.replace("&Pi;", "&#928;");
-        text = text.replace("&Rho;", "&#929;");
-        text = text.replace("&Sigma;", "&#931;");
-        text = text.replace("&Tau;", "&#932;");
-        text = text.replace("&Upsilon;", "&#933;");
-        text = text.replace("&Phi;", "&#934;");
-        text = text.replace("&Chi;", "&#935;");
-        text = text.replace("&Psi;", "&#936;");
-        text = text.replace("&Omega;", "&#937;");
-        text = text.replace("&alpha;", "&#945;");
-        text = text.replace("&beta;", "&#946;");
-        text = text.replace("&gamma;", "&#947;");
-        text = text.replace("&delta;", "&#948;");
-        text = text.replace("&epsilon;", "&#949;");
-        text = text.replace("&zeta;", "&#950;");
-        text = text.replace("&eta;", "&#951;");
-        text = text.replace("&theta;", "&#952;");
-        text = text.replace("&iota;", "&#953;");
-        text = text.replace("&kappa;", "&#954;");
-        text = text.replace("&lambda;", "&#955;");
-        text = text.replace("&mu;", "&#956;");
-        text = text.replace("&nu;", "&#957;");
-        text = text.replace("&xi;", "&#958;");
-        text = text.replace("&omicron;", "&#959;");
-        text = text.replace("&pi;", "&#960;");
-        text = text.replace("&rho;", "&#961;");
-        text = text.replace("&sigmaf;", "&#962;");
-        text = text.replace("&sigma;", "&#963;");
-        text = text.replace("&tau;", "&#964;");
-        text = text.replace("&upsilon;", "&#965;");
-        text = text.replace("&phi;", "&#966;");
-        text = text.replace("&chi;", "&#967;");
-        text = text.replace("&psi;", "&#968;");
-        text = text.replace("&omega;", "&#969;");
-        text = text.replace("&thetasym;", "&#977;");
-        text = text.replace("&upsih;", "&#978;");
-        text = text.replace("&piv;", "&#982;");
-        text = text.replace("&ensp;", "&#8194;");
-        text = text.replace("&emsp;", "&#8195;");
-        text = text.replace("&thinsp;", "&#8201;");
-        text = text.replace("&zwnj;", "&#8204;");
-        text = text.replace("&zwj;", "&#8205;");
-        text = text.replace("&lrm;", "&#8206;");
-        text = text.replace("&rlm;", "&#8207;");
-        text = text.replace("&ndash;", "&#8211;");
-        text = text.replace("&mdash;", "&#8212;");
-        text = text.replace("&lsquo;", "&#8216;");
-        text = text.replace("&rsquo;", "&#8217;");
-        text = text.replace("&sbquo;", "&#8218;");
-        text = text.replace("&ldquo;", "&#8220;");
-        text = text.replace("&rdquo;", "&#8221;");
-        text = text.replace("&bdquo;", "&#8222;");
-        text = text.replace("&dagger;", "&#8224;");
-        text = text.replace("&Dagger;", "&#8225;");
-        text = text.replace("&bull;", "&#8226;");
-        text = text.replace("&hellip;", "&#8230;");
-        text = text.replace("&permil;", "&#8240;");
-        text = text.replace("&prime;", "&#8242;");
-        text = text.replace("&Prime;", "&#8243;");
-        text = text.replace("&lsaquo;", "&#8249;");
-        text = text.replace("&rsaquo;", "&#8250;");
-        text = text.replace("&oline;", "&#8254;");
-        text = text.replace("&frasl;", "&#8260;");
-        text = text.replace("&euro;", "&#8364;");
-        text = text.replace("&image;", "&#8465;");
-        text = text.replace("&weierp;", "&#8472;");
-        text = text.replace("&real;", "&#8476;");
-        text = text.replace("&trade;", "&#8482;");
-        text = text.replace("&alefsym;", "&#8501;");
-        text = text.replace("&larr;", "&#8592;");
-        text = text.replace("&uarr;", "&#8593;");
-        text = text.replace("&rarr;", "&#8594;");
-        text = text.replace("&darr;", "&#8595;");
-        text = text.replace("&harr;", "&#8596;");
-        text = text.replace("&crarr;", "&#8629;");
-        text = text.replace("&lArr;", "&#8656;");
-        text = text.replace("&uArr;", "&#8657;");
-        text = text.replace("&rArr;", "&#8658;");
-        text = text.replace("&dArr;", "&#8659;");
-        text = text.replace("&hArr;", "&#8660;");
-        text = text.replace("&forall;", "&#8704;");
-        text = text.replace("&part;", "&#8706;");
-        text = text.replace("&exist;", "&#8707;");
-        text = text.replace("&empty;", "&#8709;");
-        text = text.replace("&nabla;", "&#8711;");
-        text = text.replace("&isin;", "&#8712;");
-        text = text.replace("&notin;", "&#8713;");
-        text = text.replace("&ni;", "&#8715;");
-        text = text.replace("&prod;", "&#8719;");
-        text = text.replace("&sum;", "&#8721;");
-        text = text.replace("&minus;", "&#8722;");
-        text = text.replace("&lowast;", "&#8727;");
-        text = text.replace("&radic;", "&#8730;");
-        text = text.replace("&prop;", "&#8733;");
-        text = text.replace("&infin;", "&#8734;");
-        text = text.replace("&ang;", "&#8736;");
-        text = text.replace("&and;", "&#8743;");
-        text = text.replace("&or;", "&#8744;");
-        text = text.replace("&cap;", "&#8745;");
-        text = text.replace("&cup;", "&#8746;");
-        text = text.replace("&int;", "&#8747;");
-        text = text.replace("&there4;", "&#8756;");
-        text = text.replace("&sim;", "&#8764;");
-        text = text.replace("&cong;", "&#8773;");
-        text = text.replace("&asymp;", "&#8776;");
-        text = text.replace("&ne;", "&#8800;");
-        text = text.replace("&equiv;", "&#8801;");
-        text = text.replace("&le;", "&#8804;");
-        text = text.replace("&ge;", "&#8805;");
-        text = text.replace("&sub;", "&#8834;");
-        text = text.replace("&sup;", "&#8835;");
-        text = text.replace("&nsub;", "&#8836;");
-        text = text.replace("&sube;", "&#8838;");
-        text = text.replace("&supe;", "&#8839;");
-        text = text.replace("&oplus;", "&#8853;");
-        text = text.replace("&otimes;", "&#8855;");
-        text = text.replace("&perp;", "&#8869;");
-        text = text.replace("&sdot;", "&#8901;");
-        text = text.replace("&lceil;", "&#8968;");
-        text = text.replace("&rceil;", "&#8969;");
-        text = text.replace("&lfloor;", "&#8970;");
-        text = text.replace("&rfloor;", "&#8971;");
-        text = text.replace("&lang;", "&#9001;");
-        text = text.replace("&rang;", "&#9002;");
-        text = text.replace("&loz;", "&#9674;");
-        text = text.replace("&spades;", "&#9824;");
-        text = text.replace("&clubs;", "&#9827;");
-        text = text.replace("&hearts;", "&#9829;");
-        text = text.replace("&diams;", "&#9830;");
-        //
-        return text;
-    }
-
-    public static String getXhtmlSafeString(String x) throws MXhtmlUnsafeStringWebException {
-        if (null == x) {
-            return null;
-        }
-        //
-        String text = x;
-        //
-        StringBuilder fakeXhtmlPageContent = new StringBuilder("");
-        fakeXhtmlPageContent.append(String.format("<?xml version=\"1.0\" encoding=\"%s\" ?>", MInformation.TEXT_ENCODING));
-        fakeXhtmlPageContent.append("<!DOCTYPE html SYSTEM \"fake-dtd\" >");
-        fakeXhtmlPageContent.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
-        fakeXhtmlPageContent.append("<head><title /></head>");
-        fakeXhtmlPageContent.append(String.format("<body>%s</body>", text));
-        fakeXhtmlPageContent.append("</html>");
-        // validate Xhtml (without dangerous tags and event attributes)
-        try {
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setValidating(true);
-            factory.setNamespaceAware(true);
-            SAXParser parser = factory.newSAXParser();
-            XMLReader reader = parser.getXMLReader();
-            reader.setEntityResolver(new EntityResolver() {
-
-                public InputSource resolveEntity(String publicId, String systemId) {
-                    return new InputSource(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("dtd/xhtml1-transitional-macaco-edit.dtd")));
-                }
-
-            });
-            reader.setContentHandler(new DefaultHandler() {
-
-                public void startElement(String namespaceUri, String strippedName, String tagName, Attributes attributes) throws SAXException {
-                    if ("script".equalsIgnoreCase(tagName)) {
-                        throw new SAXException(String.format("Tag not allowed: %s.", tagName));
-                    }
-                    for (int a = 0; a < attributes.getLength(); a++) {
-                        if (attributes.getLocalName(a).toLowerCase().startsWith("on")) {
-                            throw new SAXException(String.format("Attribute not allowed: %s.", attributes.getLocalName(a)));
-                        }
-                    }
-                }
-
-            });
-            reader.setErrorHandler(new ErrorHandler() {
-
-                public void error(SAXParseException exception) throws SAXException {
-                    throw new SAXException(exception);
-                }
-
-                public void fatalError(SAXParseException exception) throws SAXException {
-                    throw new SAXException(exception);
-                }
-
-                public void warning(SAXParseException exception) throws SAXException {
-                    throw new SAXException(exception);
-                }
-
-            });
-            //
-            reader.parse(new InputSource(new ByteArrayInputStream(fakeXhtmlPageContent.toString().getBytes(MInformation.TEXT_ENCODING))));
-        }
-        catch (ParserConfigurationException exception) { // cannot happen
-        }
-        catch (SAXException exception) {
-            throw new MXhtmlUnsafeStringWebException("Invalid 'x': unsafe tags or attributes inside.", exception);
-        }
-        catch (UnsupportedEncodingException exception) { // cannot happen
-        }
-        catch (IOException exception) { // cannot happen, put here not to bypass UnsupportedEncodingException
-        }
-        // also convert named entities to numeric entities
-        return MWebString.getXhtmlNumericEntitiesString(text);
-    }
-
-}
index fe93e57dc5213978843141da7a4454be91a80f23..97cc74a63834e05041253301ff0372613125adc1 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -519,7 +520,7 @@ public abstract class MWebTable extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
@@ -537,25 +538,25 @@ public abstract class MWebTable extends MWebDirectWidget {
         for (String columnKey: columnHeaders.keySet()) {
             String onSortFunction = "";
             if (!"".equals(columnHeaders.get(columnKey).getText())) {
-                onSortFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onSort', {'sortKey': '%s'});", this.getId(), MWebString.getJavascriptEscapedString(columnKey));
+                onSortFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onSort', {'sortKey': '%s'});", this.getId(), MText.getJavascriptEscapedString(columnKey));
             }
-            content.append(String.format("<th class=\"MWebTableColumnHeaderCell %s\" onclick=\"%s\" id=\"%s\"></th>", customClasses, MWebString.getXhtmlEscapedString(onSortFunction), columnHeaders.get(columnKey).getId()));
+            content.append(String.format("<th class=\"MWebTableColumnHeaderCell %s\" onclick=\"%s\" id=\"%s\"></th>", customClasses, MText.getXhtmlEscapedString(onSortFunction), columnHeaders.get(columnKey).getId()));
         }
         content.append("</tr>");
         //
         for (String primaryKeyValue: rowSubset.keySet()) {
             content.append(String.format("<tr class=\"MWebTableRow %s\">", customClasses));
             if (this.getSelectableRowMode()) {
-                String onRowSelectedModeToggleFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onRowSelectedModeToggle', {'primaryKeyValue': '%s'});", this.getId(), MWebString.getJavascriptEscapedString(primaryKeyValue));
+                String onRowSelectedModeToggleFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onRowSelectedModeToggle', {'primaryKeyValue': '%s'});", this.getId(), MText.getJavascriptEscapedString(primaryKeyValue));
                 String checkedMode = "";
                 if (this.getRowSelectedMode(primaryKeyValue)) {
                     checkedMode = "checked=\"checked\"";
                 }
-                content.append(String.format("<th class=\"MWebTableRowSelectionCell %s\"><input type=\"checkbox\" class=\"MWebTableRowSelector %s\" onclick=\"%s\" %s /></th>", customClasses, customClasses, MWebString.getXhtmlEscapedString(onRowSelectedModeToggleFunction), checkedMode));
+                content.append(String.format("<th class=\"MWebTableRowSelectionCell %s\"><input type=\"checkbox\" class=\"MWebTableRowSelector %s\" onclick=\"%s\" %s /></th>", customClasses, customClasses, MText.getXhtmlEscapedString(onRowSelectedModeToggleFunction), checkedMode));
             }
             for (String columnKey: rowSubset.get(primaryKeyValue).keySet()) {
-                String onCellClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onCellClick', {'primaryKeyValue': '%s', 'columnKey': '%s'});", this.getId(), MWebString.getJavascriptEscapedString(primaryKeyValue), MWebString.getJavascriptEscapedString(columnKey));
-                content.append(String.format("<td class=\"MWebTableCell %s\" onclick=\"%s\" id=\"%s\"></td>", customClasses, MWebString.getXhtmlEscapedString(onCellClickFunction), rowSubset.get(primaryKeyValue).get(columnKey).getId()));
+                String onCellClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onCellClick', {'primaryKeyValue': '%s', 'columnKey': '%s'});", this.getId(), MText.getJavascriptEscapedString(primaryKeyValue), MText.getJavascriptEscapedString(columnKey));
+                content.append(String.format("<td class=\"MWebTableCell %s\" onclick=\"%s\" id=\"%s\"></td>", customClasses, MText.getXhtmlEscapedString(onCellClickFunction), rowSubset.get(primaryKeyValue).get(columnKey).getId()));
             }
             content.append("</tr>");
         }
@@ -594,7 +595,7 @@ public abstract class MWebTable extends MWebDirectWidget {
         content.append("</tr>");
         //
         content.append("</table>");
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(content.toString())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(content.toString())));
         //
         String sortKey = this.getSortKey();
         for (String columnKey: columnHeaders.keySet()) {
index ab42c8671e5c67efee8439c3ac129f6ef5b2c389..32263ca0d8d064f079168b9b44bc59bb9a943774 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public class MWebTableCell extends MWebCellWidget {
@@ -144,15 +145,15 @@ public class MWebTableCell extends MWebCellWidget {
         String imageSource = this.getImageSource();
         String externalLinkPrefix = this.getExternalLinkPrefix();
         if (null == imageSource) {
-            content = MWebString.getXhtmlEscapedString(text);
+            content = MText.getXhtmlEscapedString(text);
         }
         else {
-            content = String.format("<img src=\"%s\" alt=\"%s\" />", MWebString.getXhtmlEscapedString(imageSource), MWebString.getXhtmlEscapedString(text));
+            content = String.format("<img src=\"%s\" alt=\"%s\" />", MText.getXhtmlEscapedString(imageSource), MText.getXhtmlEscapedString(text));
         }
         if (null != externalLinkPrefix) {
-            content = String.format("<a href=\"%s\">%s</a>", MWebString.getXhtmlEscapedString(externalLinkPrefix + text), content);
+            content = String.format("<a href=\"%s\">%s</a>", MText.getXhtmlEscapedString(externalLinkPrefix + text), content);
         }
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(content)));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(content)));
     }
 
     /* Messages */
index 9bbf4313f78f217f0ea870fbc5868600a6455f6a..6b7de1f54344790ce57dce65921c29b93bbcdc06 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 
 public abstract class MWebTextBox extends MWebDirectWidget {
@@ -196,7 +197,7 @@ public abstract class MWebTextBox extends MWebDirectWidget {
     protected void refreshText() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
         this.checkPresence();
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').value = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getText())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').value = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getText())));
     }
 
     protected void refreshTextAlignment(boolean directRefreshMode) throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
index 00a7e802d05c7d65efd23643b857d342d8abc5be..cf48316c78770615e230647831074008a4354067 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.LinkedHashMap;
@@ -93,12 +94,12 @@ public class MWebUploader extends MWebDirectWidget {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onUploadFunction = String.format("javascript: m_messageInterface.fireUploadFakeMessage('%s');", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<form class=\"MWebUploader %s\" id=\"%s\" action=\"#\" enctype=\"multipart/form-data\" method=\"post\" target=\"m_uploader\"><input type=\"file\" class=\"MWebUploaderFile %s\" style=\"display: inline-block;\" onchange=\"%s\" id=\"%s_file\" name=\"%s_file\" /></form>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onUploadFunction), this.getId(), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<form class=\"MWebUploader %s\" id=\"%s\" action=\"#\" enctype=\"multipart/form-data\" method=\"post\" target=\"m_uploader\"><input type=\"file\" class=\"MWebUploaderFile %s\" style=\"display: inline-block;\" onchange=\"%s\" id=\"%s_file\" name=\"%s_file\" /></form>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onUploadFunction), this.getId(), this.getId()));
         //
         super.refresh();
         //
index 6af6c317d499a3ec6cf0343b7fd63abd1dfd6de5..6ae1f4fc26a192b7cedd2741b9f17b91779933ab 100644 (file)
@@ -6,6 +6,7 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 
@@ -176,7 +177,7 @@ public class MWebVerticalMenu extends MWebDirectWidget {
             parentItemKey = ""; // rewritten for better readability
         }
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
@@ -184,7 +185,7 @@ public class MWebVerticalMenu extends MWebDirectWidget {
         StringBuilder itemContent = new StringBuilder("");
         if ((0 == parentItemLevel) && (null != this.getTitle())) {
             itemContent.append(String.format("<tr class=\"MWebVerticalMenuTitleRow %s\">", customClasses));
-            itemContent.append(String.format("<td class=\"MWebVerticalMenuTitleCell %s\" colspan=\"2\">%s</td>", customClasses, MWebString.getXhtmlEscapedString(this.getTitle())));
+            itemContent.append(String.format("<td class=\"MWebVerticalMenuTitleCell %s\" colspan=\"2\">%s</td>", customClasses, MText.getXhtmlEscapedString(this.getTitle())));
             itemContent.append("</tr>");
         }
         String lastItemKey = "";
@@ -209,12 +210,12 @@ public class MWebVerticalMenu extends MWebDirectWidget {
                     imageClass = "MWebVerticalMenuSelectedImageCell";
                     textClass = "MWebVerticalMenuSelectedTextCell";
                 }
-                String onItemSelectionFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onItemSelection', {'selectedItemKey': '%s'});", this.getId(), MWebString.getJavascriptEscapedString(itemKey));
-                itemContent.append(String.format("<td class=\"%s %s\" onclick=\"%s\" id=\"%s\"><img class=\"MWebVerticalMenuImage %s\" src=\"%s\" alt=\"\" /></td>", imageClass, customClasses, MWebString.getXhtmlEscapedString(onItemSelectionFunction), this.getId() + MWebString.getXhtmlEscapedString(itemKey) + "-imageCell", customClasses, MWebString.getXhtmlEscapedString(imageSource)));
-                itemContent.append(String.format("<td class=\"%s %s\" onclick=\"%s\" id=\"%s\">%s</td>", textClass, customClasses, MWebString.getXhtmlEscapedString(onItemSelectionFunction), this.getId() + MWebString.getXhtmlEscapedString(itemKey) + "-textCell", MWebString.getXhtmlEscapedString(text)));
+                String onItemSelectionFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onItemSelection', {'selectedItemKey': '%s'});", this.getId(), MText.getJavascriptEscapedString(itemKey));
+                itemContent.append(String.format("<td class=\"%s %s\" onclick=\"%s\" id=\"%s\"><img class=\"MWebVerticalMenuImage %s\" src=\"%s\" alt=\"\" /></td>", imageClass, customClasses, MText.getXhtmlEscapedString(onItemSelectionFunction), this.getId() + MText.getXhtmlEscapedString(itemKey) + "-imageCell", customClasses, MText.getXhtmlEscapedString(imageSource)));
+                itemContent.append(String.format("<td class=\"%s %s\" onclick=\"%s\" id=\"%s\">%s</td>", textClass, customClasses, MText.getXhtmlEscapedString(onItemSelectionFunction), this.getId() + MText.getXhtmlEscapedString(itemKey) + "-textCell", MText.getXhtmlEscapedString(text)));
             }
             else {
-                itemContent.append(String.format("<td class=\"MWebVerticalMenuSeparatorCell %s\" id=\"%s\" colspan=\"2\"></td>", customClasses, this.getId() + MWebString.getXhtmlEscapedString(itemKey) + "-separatorCell"));
+                itemContent.append(String.format("<td class=\"MWebVerticalMenuSeparatorCell %s\" id=\"%s\" colspan=\"2\"></td>", customClasses, this.getId() + MText.getXhtmlEscapedString(itemKey) + "-separatorCell"));
             }
             itemContent.append("</tr>");
             //
@@ -223,7 +224,7 @@ public class MWebVerticalMenu extends MWebDirectWidget {
                 if (!"".equals(childItemContent.toString())) {
                     itemContent.append(String.format("<tr class=\"MWebVerticalMenuRow %s\">", customClasses));
                     itemContent.append(String.format("<td class=\"MWebVerticalMenuImageCell\" />", customClasses));
-                    itemContent.append(String.format("<td class=\"MWebVerticalMenuChildTableCell %s\" id=\"%s\">%s</td>", customClasses, this.getId() + MWebString.getXhtmlEscapedString(itemKey) + "-childCell", childItemContent));
+                    itemContent.append(String.format("<td class=\"MWebVerticalMenuChildTableCell %s\" id=\"%s\">%s</td>", customClasses, this.getId() + MText.getXhtmlEscapedString(itemKey) + "-childCell", childItemContent));
                     itemContent.append("</tr>");
                 }
             }
@@ -235,7 +236,7 @@ public class MWebVerticalMenu extends MWebDirectWidget {
                 content.append(String.format("<table class=\"MWebVerticalMenuTable %s\" style=\"display: inline-table;\" id=\"%s\">", customClasses, this.getId()));
             }
             else {
-                content.append(String.format("<table class=\"MWebVerticalMenuChildTable %s\" style=\"display: inline-table; width: 100%%;\" id=\"%s\">", customClasses, this.getId() + MWebString.getXhtmlEscapedString(lastItemKey) + "-childTable"));
+                content.append(String.format("<table class=\"MWebVerticalMenuChildTable %s\" style=\"display: inline-table; width: 100%%;\" id=\"%s\">", customClasses, this.getId() + MText.getXhtmlEscapedString(lastItemKey) + "-childTable"));
             }
             content.append(itemContent);
             content.append("</table>");
@@ -250,7 +251,7 @@ public class MWebVerticalMenu extends MWebDirectWidget {
         if ("".equals(content)) {
             content = String.format("<div id=\"%s\"></div>", this.getId());
         }
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(content)));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(content)));
         //
         super.refresh();
     }
index 9453b78b91c144a02f94384d2b919edb5fa008d2..d5321e351ea5178a3cf012148d46d25721350004 100644 (file)
@@ -7,6 +7,7 @@
 package com.marcozanon.macaco.web.ui;
 
 import com.marcozanon.macaco.MObject;
+import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -362,7 +363,7 @@ public class MWebView extends MObject implements Runnable {
     protected void refreshTitle() throws MNoBrowserPageWebException, MResponseWebException {
         this.checkPresence();
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("document.title = '%s';", MWebString.getJavascriptEscapedString(this.getTitle())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("document.title = '%s';", MText.getJavascriptEscapedString(this.getTitle())));
     }
 
     /* Messages */
index de05a9de8cf6723a531d5787a93aa4299be20371..e026693fb1983598ff94afc315b527d58f3bdfd7 100644 (file)
@@ -6,6 +6,8 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
+import com.marcozanon.macaco.text.MXhtmlUnsafeStringTextException;
 import java.util.LinkedHashMap;
 
 public class MWebWysiwygBox extends MWebDirectWidget {
@@ -55,9 +57,9 @@ public class MWebWysiwygBox extends MWebDirectWidget {
         }
         //
         try {
-            this.text = MWebString.getXhtmlSafeString(text);
+            this.text = MText.getXhtmlSafeString(text);
         }
-        catch (MXhtmlUnsafeStringWebException exception) {
+        catch (MXhtmlUnsafeStringTextException exception) {
             throw new IllegalArgumentException(String.format("Invalid 'text': %s: unsafe Xhtml tags or attributes inside.", text)); // no need to propagate exception
         }
         //
@@ -123,14 +125,14 @@ public class MWebWysiwygBox extends MWebDirectWidget {
         //
         this.displayedMode = false;
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         customClasses = customClasses + " " + this.getId();
         StringBuilder content = new StringBuilder("");
         content.append(String.format("<div class=\"MWebWysiwygBox %s\" style=\"display: inline-block;\" id=\"%s\" cols=\"1\" rows=\"1\"></div>", customClasses, this.getId()));
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(content.toString())));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(content.toString())));
         //
         super.refresh();
         //
@@ -142,7 +144,7 @@ public class MWebWysiwygBox extends MWebDirectWidget {
         this.checkPresence();
         //
         if (this.getEnabledMode()) {
-            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $enableWysiwygBoxEditor('%s', '%s'); }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getText())));
+            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $enableWysiwygBoxEditor('%s', '%s'); }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getText())));
             this.displayedMode = true;
         }
         else {
@@ -155,10 +157,10 @@ public class MWebWysiwygBox extends MWebDirectWidget {
         this.checkPresence();
         //
         if (this.getEnabledMode() && this.displayedMode) {
-            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $fillWysiwygBoxEditor('%s', '%s'); }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getText())));
+            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $fillWysiwygBoxEditor('%s', '%s'); }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getText())));
         }
         else {
-            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(this.getText())));
+            this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(this.getText())));
         }
     }
 
@@ -176,9 +178,9 @@ public class MWebWysiwygBox extends MWebDirectWidget {
                 throw new MUnexpectedMessageWebException("Invalid message: text parameter not available.");
             }
             try {
-                String y = MWebString.getXhtmlSafeString(text);
+                String y = MText.getXhtmlSafeString(text);
             }
-            catch (MXhtmlUnsafeStringWebException exception) {
+            catch (MXhtmlUnsafeStringTextException exception) {
                 throw new MUnexpectedMessageWebException(String.format("Invalid message: %s: unsafe Xhtml tags or attributes inside.", text)); // no need to propagate exception
             }
             this.onBlur(text);
index 25056303a09164c39ea041ba317589ba931bf1b6..b22c35ad25cb389ddd4461ccc390241e562a3e48 100644 (file)
@@ -6,6 +6,8 @@
 
 package com.marcozanon.macaco.web.ui;
 
+import com.marcozanon.macaco.text.MText;
+
 public class MWebXhtmlLabel extends MWebLabel {
 
     /* */
@@ -25,13 +27,13 @@ public class MWebXhtmlLabel extends MWebLabel {
     protected void refresh() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException, MUniqueWidgetIdNotAvailableWebException {
         this.checkPresence();
         //
-        String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+        String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
         if (null == customClasses) {
             customClasses = "";
         }
         String onClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onClick', {});", this.getId());
         String onDoubleClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onDoubleClick', {});", this.getId());
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<div class=\"MWebXhtmlLabel %s\" style=\"display: inline-block;\" onclick=\"%s\" ondblclick=\"%s\" id=\"%s\"></div>'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onClickFunction), MWebString.getJavascriptEscapedString(onDoubleClickFunction), this.getId()));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = '<div class=\"MWebXhtmlLabel %s\" style=\"display: inline-block;\" onclick=\"%s\" ondblclick=\"%s\" id=\"%s\"></div>'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onClickFunction), MText.getJavascriptEscapedString(onDoubleClickFunction), this.getId()));
         //
         super.refresh();
         //
@@ -41,7 +43,7 @@ public class MWebXhtmlLabel extends MWebLabel {
     protected void refreshText() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException {
         this.checkPresence();
         //
-        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(MWebString.getXhtmlNumericEntitiesString(this.getText()))));
+        this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').innerHTML = '%s'; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(MText.getXhtmlNumericEntitiesString(this.getText()))));
     }
 
 }
diff --git a/src/java/com/marcozanon/macaco/web/ui/MXhtmlUnsafeStringWebException.java b/src/java/com/marcozanon/macaco/web/ui/MXhtmlUnsafeStringWebException.java
deleted file mode 100644 (file)
index 8b892f4..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Macaco
- * Copyright (c) 2009-2012 Marco Zanon <info@marcozanon.com>.
- * Released under MIT license (see LICENSE for details).
- */
-
-package com.marcozanon.macaco.web.ui;
-
-public class MXhtmlUnsafeStringWebException extends MSecurityWebException {
-
-    private static final long serialVersionUID = 0L;
-
-    /* */
-
-    public MXhtmlUnsafeStringWebException() {
-        super();
-    }
-
-    public MXhtmlUnsafeStringWebException(String message) {
-        super(message);
-    }
-
-    public MXhtmlUnsafeStringWebException(Throwable error) {
-        super(error);
-    }
-
-    public MXhtmlUnsafeStringWebException(String message, Throwable error) {
-        super(message, error);
-    }
-
-}