From: Marco Zanon Date: Fri, 13 Apr 2012 20:29:43 +0000 (+0000) Subject: Moved code from separate MWebString class (web.ui) into MText class (text). X-Git-Tag: SVN-to-Git~141 X-Git-Url: https://gitweb.marcozanon.com/?a=commitdiff_plain;h=7a7645fdce47dc0a6c9365f307846ddf442b521a;p=Macaco Moved code from separate MWebString class (web.ui) into MText class (text). --- diff --git a/src/java/com/marcozanon/macaco/text/MText.java b/src/java/com/marcozanon/macaco/text/MText.java index 2bed714..ae46b31 100644 --- a/src/java/com/marcozanon/macaco/text/MText.java +++ b/src/java/com/marcozanon/macaco/text/MText.java @@ -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("&", "&"); + text = text.replace("\"", """); + text = text.replace("'", "'"); + text = text.replace("<", "<"); + text = text.replace(">", ">"); + // + text = text.replace("\n", "
"); + // + return text; + } + + public static String getXhtmlNumericEntitiesString(String x) { // for compatibility with innerHTML + if (null == x) { + return null; + } + // + String text = x; + // + text = text.replace(" ", " "); + text = text.replace("¡", "¡"); + text = text.replace("¢", "¢"); + text = text.replace("£", "£"); + text = text.replace("¤", "¤"); + text = text.replace("¥", "¥"); + text = text.replace("¦", "¦"); + text = text.replace("§", "§"); + text = text.replace("¨", "¨"); + text = text.replace("©", "©"); + text = text.replace("ª", "ª"); + text = text.replace("«", "«"); + text = text.replace("¬", "¬"); + text = text.replace("­", "­"); + text = text.replace("®", "®"); + text = text.replace("¯", "¯"); + text = text.replace("°", "°"); + text = text.replace("±", "±"); + text = text.replace("²", "²"); + text = text.replace("³", "³"); + text = text.replace("´", "´"); + text = text.replace("µ", "µ"); + text = text.replace("¶", "¶"); + text = text.replace("·", "·"); + text = text.replace("¸", "¸"); + text = text.replace("¹", "¹"); + text = text.replace("º", "º"); + text = text.replace("»", "»"); + text = text.replace("¼", "¼"); + text = text.replace("½", "½"); + text = text.replace("¾", "¾"); + text = text.replace("¿", "¿"); + text = text.replace("À", "À"); + text = text.replace("Á", "Á"); + text = text.replace("Â", "Â"); + text = text.replace("Ã", "Ã"); + text = text.replace("Ä", "Ä"); + text = text.replace("Å", "Å"); + text = text.replace("Æ", "Æ"); + text = text.replace("Ç", "Ç"); + text = text.replace("È", "È"); + text = text.replace("É", "É"); + text = text.replace("Ê", "Ê"); + text = text.replace("Ë", "Ë"); + text = text.replace("Ì", "Ì"); + text = text.replace("Í", "Í"); + text = text.replace("Î", "Î"); + text = text.replace("Ï", "Ï"); + text = text.replace("Ð", "Ð"); + text = text.replace("Ñ", "Ñ"); + text = text.replace("Ò", "Ò"); + text = text.replace("Ó", "Ó"); + text = text.replace("Ô", "Ô"); + text = text.replace("Õ", "Õ"); + text = text.replace("Ö", "Ö"); + text = text.replace("×", "×"); + text = text.replace("Ø", "Ø"); + text = text.replace("Ù", "Ù"); + text = text.replace("Ú", "Ú"); + text = text.replace("Û", "Û"); + text = text.replace("Ü", "Ü"); + text = text.replace("Ý", "Ý"); + text = text.replace("Þ", "Þ"); + text = text.replace("ß", "ß"); + text = text.replace("à", "à"); + text = text.replace("á", "á"); + text = text.replace("â", "â"); + text = text.replace("ã", "ã"); + text = text.replace("ä", "ä"); + text = text.replace("å", "å"); + text = text.replace("æ", "æ"); + text = text.replace("ç", "ç"); + text = text.replace("è", "è"); + text = text.replace("é", "é"); + text = text.replace("ê", "ê"); + text = text.replace("ë", "ë"); + text = text.replace("ì", "ì"); + text = text.replace("í", "í"); + text = text.replace("î", "î"); + text = text.replace("ï", "ï"); + text = text.replace("ð", "ð"); + text = text.replace("ñ", "ñ"); + text = text.replace("ò", "ò"); + text = text.replace("ó", "ó"); + text = text.replace("ô", "ô"); + text = text.replace("õ", "õ"); + text = text.replace("ö", "ö"); + text = text.replace("÷", "÷"); + text = text.replace("ø", "ø"); + text = text.replace("ù", "ù"); + text = text.replace("ú", "ú"); + text = text.replace("û", "û"); + text = text.replace("ü", "ü"); + text = text.replace("ý", "ý"); + text = text.replace("þ", "þ"); + text = text.replace("ÿ", "ÿ"); + text = text.replace("Œ", "Œ"); + text = text.replace("œ", "œ"); + text = text.replace("Š", "Š"); + text = text.replace("š", "š"); + text = text.replace("Ÿ", "Ÿ"); + text = text.replace("ƒ", "ƒ"); + text = text.replace("ˆ", "ˆ"); + text = text.replace("˜", "˜"); + text = text.replace("Α", "Α"); + text = text.replace("Β", "Β"); + text = text.replace("Γ", "Γ"); + text = text.replace("Δ", "Δ"); + text = text.replace("Ε", "Ε"); + text = text.replace("Ζ", "Ζ"); + text = text.replace("Η", "Η"); + text = text.replace("Θ", "Θ"); + text = text.replace("Ι", "Ι"); + text = text.replace("Κ", "Κ"); + text = text.replace("Λ", "Λ"); + text = text.replace("Μ", "Μ"); + text = text.replace("Ν", "Ν"); + text = text.replace("Ξ", "Ξ"); + text = text.replace("Ο", "Ο"); + text = text.replace("Π", "Π"); + text = text.replace("Ρ", "Ρ"); + text = text.replace("Σ", "Σ"); + text = text.replace("Τ", "Τ"); + text = text.replace("Υ", "Υ"); + text = text.replace("Φ", "Φ"); + text = text.replace("Χ", "Χ"); + text = text.replace("Ψ", "Ψ"); + text = text.replace("Ω", "Ω"); + text = text.replace("α", "α"); + text = text.replace("β", "β"); + text = text.replace("γ", "γ"); + text = text.replace("δ", "δ"); + text = text.replace("ε", "ε"); + text = text.replace("ζ", "ζ"); + text = text.replace("η", "η"); + text = text.replace("θ", "θ"); + text = text.replace("ι", "ι"); + text = text.replace("κ", "κ"); + text = text.replace("λ", "λ"); + text = text.replace("μ", "μ"); + text = text.replace("ν", "ν"); + text = text.replace("ξ", "ξ"); + text = text.replace("ο", "ο"); + text = text.replace("π", "π"); + text = text.replace("ρ", "ρ"); + text = text.replace("ς", "ς"); + text = text.replace("σ", "σ"); + text = text.replace("τ", "τ"); + text = text.replace("υ", "υ"); + text = text.replace("φ", "φ"); + text = text.replace("χ", "χ"); + text = text.replace("ψ", "ψ"); + text = text.replace("ω", "ω"); + text = text.replace("ϑ", "ϑ"); + text = text.replace("ϒ", "ϒ"); + text = text.replace("ϖ", "ϖ"); + text = text.replace(" ", " "); + text = text.replace(" ", " "); + text = text.replace(" ", " "); + text = text.replace("‌", "‌"); + text = text.replace("‍", "‍"); + text = text.replace("‎", "‎"); + text = text.replace("‏", "‏"); + text = text.replace("–", "–"); + text = text.replace("—", "—"); + text = text.replace("‘", "‘"); + text = text.replace("’", "’"); + text = text.replace("‚", "‚"); + text = text.replace("“", "“"); + text = text.replace("”", "”"); + text = text.replace("„", "„"); + text = text.replace("†", "†"); + text = text.replace("‡", "‡"); + text = text.replace("•", "•"); + text = text.replace("…", "…"); + text = text.replace("‰", "‰"); + text = text.replace("′", "′"); + text = text.replace("″", "″"); + text = text.replace("‹", "‹"); + text = text.replace("›", "›"); + text = text.replace("‾", "‾"); + text = text.replace("⁄", "⁄"); + text = text.replace("€", "€"); + text = text.replace("ℑ", "ℑ"); + text = text.replace("℘", "℘"); + text = text.replace("ℜ", "ℜ"); + text = text.replace("™", "™"); + text = text.replace("ℵ", "ℵ"); + text = text.replace("←", "←"); + text = text.replace("↑", "↑"); + text = text.replace("→", "→"); + text = text.replace("↓", "↓"); + text = text.replace("↔", "↔"); + text = text.replace("↵", "↵"); + text = text.replace("⇐", "⇐"); + text = text.replace("⇑", "⇑"); + text = text.replace("⇒", "⇒"); + text = text.replace("⇓", "⇓"); + text = text.replace("⇔", "⇔"); + text = text.replace("∀", "∀"); + text = text.replace("∂", "∂"); + text = text.replace("∃", "∃"); + text = text.replace("∅", "∅"); + text = text.replace("∇", "∇"); + text = text.replace("∈", "∈"); + text = text.replace("∉", "∉"); + text = text.replace("∋", "∋"); + text = text.replace("∏", "∏"); + text = text.replace("∑", "∑"); + text = text.replace("−", "−"); + text = text.replace("∗", "∗"); + text = text.replace("√", "√"); + text = text.replace("∝", "∝"); + text = text.replace("∞", "∞"); + text = text.replace("∠", "∠"); + text = text.replace("∧", "∧"); + text = text.replace("∨", "∨"); + text = text.replace("∩", "∩"); + text = text.replace("∪", "∪"); + text = text.replace("∫", "∫"); + text = text.replace("∴", "∴"); + text = text.replace("∼", "∼"); + text = text.replace("≅", "≅"); + text = text.replace("≈", "≈"); + text = text.replace("≠", "≠"); + text = text.replace("≡", "≡"); + text = text.replace("≤", "≤"); + text = text.replace("≥", "≥"); + text = text.replace("⊂", "⊂"); + text = text.replace("⊃", "⊃"); + text = text.replace("⊄", "⊄"); + text = text.replace("⊆", "⊆"); + text = text.replace("⊇", "⊇"); + text = text.replace("⊕", "⊕"); + text = text.replace("⊗", "⊗"); + text = text.replace("⊥", "⊥"); + text = text.replace("⋅", "⋅"); + text = text.replace("⌈", "⌈"); + text = text.replace("⌉", "⌉"); + text = text.replace("⌊", "⌊"); + text = text.replace("⌋", "⌋"); + text = text.replace("⟨", "〈"); + text = text.replace("⟩", "〉"); + text = text.replace("◊", "◊"); + text = text.replace("♠", "♠"); + text = text.replace("♣", "♣"); + text = text.replace("♥", "♥"); + text = text.replace("♦", "♦"); + // + 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("", MInformation.TEXT_ENCODING)); + fakeXhtmlPageContent.append(""); + fakeXhtmlPageContent.append(""); + fakeXhtmlPageContent.append("</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 index 0000000..462c2da --- /dev/null +++ b/src/java/com/marcozanon/macaco/text/MXhtmlUnsafeStringTextException.java @@ -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); + } + +} diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebApplicationContext.java b/src/java/com/marcozanon/macaco/web/ui/MWebApplicationContext.java index 3737df1..7889949 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebApplicationContext.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebApplicationContext.java @@ -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)))); } } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebBreadcrumbs.java b/src/java/com/marcozanon/macaco/web/ui/MWebBreadcrumbs.java index 0763ecb..f00949f 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebBreadcrumbs.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebBreadcrumbs.java @@ -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 */ diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebBrowserPage.java b/src/java/com/marcozanon/macaco/web/ui/MWebBrowserPage.java index 14b35c5..59368e4 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebBrowserPage.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebBrowserPage.java @@ -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..." + 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 */ diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebCheckBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebCheckBox.java index 74d20b1..5a7f744 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebCheckBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebCheckBox.java @@ -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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onChangeFunction), this.getId())); + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onChangeFunction), this.getId())); // super.refresh(); // diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebComboBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebComboBox.java index e501ff8..92add70 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebComboBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebComboBox.java @@ -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 = ''; }", 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 = ''; }", 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))); } } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java index b9cfb14..a8a3454 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java @@ -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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId())); // super.refresh(); // diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java index 4ef73a3..7e5dd97 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java @@ -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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId())); // super.refresh(); // diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebGridLayout.java b/src/java/com/marcozanon/macaco/web/ui/MWebGridLayout.java index f7bc4a2..5b8bfee 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebGridLayout.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebGridLayout.java @@ -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(""); } content.append(""); - 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++) { diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebImage.java b/src/java/com/marcozanon/macaco/web/ui/MWebImage.java index 53d1004..6688ddf 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebImage.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebImage.java @@ -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 = '\"\"'; }", 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 = '\"\"'; }", 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 */ diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebImageButton.java b/src/java/com/marcozanon/macaco/web/ui/MWebImageButton.java index aef97c2..e01c168 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebImageButton.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebImageButton.java @@ -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(""); String onClickFunction = String.format("javascript: m_messageInterface.fireMessage('%s', 'onClick', {});", this.getId()); - this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", 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 = ''; }", 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) { diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebLabel.java b/src/java/com/marcozanon/macaco/web/ui/MWebLabel.java index e130aef..f589ce8 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebLabel.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebLabel.java @@ -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 = '
'; }", 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 = '
'; }", 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 { diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java index 958c6a4..8cdabc1 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java @@ -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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId())); // super.refresh(); // diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java index 28401b1..91a857c 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java @@ -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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", this.getId(), this.getId(), MText.getJavascriptEscapedString(customClasses), MText.getJavascriptEscapedString(onBlurFunction), this.getId())); // super.refresh(); // diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java index 630a07e..63eba85 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java @@ -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 = ''; }", this.getId(), this.getId(), MWebString.getJavascriptEscapedString(customClasses), MWebString.getJavascriptEscapedString(onBlurFunction), this.getId())); + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').parentNode.innerHTML = ''; }", 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 index cca589a..0000000 --- a/src/java/com/marcozanon/macaco/web/ui/MWebString.java +++ /dev/null @@ -1,402 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * 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("&", "&"); - text = text.replace("\"", """); - text = text.replace("'", "'"); - text = text.replace("<", "<"); - text = text.replace(">", ">"); - // - text = text.replace("\n", "
"); - // - return text; - } - - public static String getXhtmlNumericEntitiesString(String x) { // for compatibility with innerHTML - if (null == x) { - return null; - } - // - String text = x; - // - text = text.replace(" ", " "); - text = text.replace("¡", "¡"); - text = text.replace("¢", "¢"); - text = text.replace("£", "£"); - text = text.replace("¤", "¤"); - text = text.replace("¥", "¥"); - text = text.replace("¦", "¦"); - text = text.replace("§", "§"); - text = text.replace("¨", "¨"); - text = text.replace("©", "©"); - text = text.replace("ª", "ª"); - text = text.replace("«", "«"); - text = text.replace("¬", "¬"); - text = text.replace("­", "­"); - text = text.replace("®", "®"); - text = text.replace("¯", "¯"); - text = text.replace("°", "°"); - text = text.replace("±", "±"); - text = text.replace("²", "²"); - text = text.replace("³", "³"); - text = text.replace("´", "´"); - text = text.replace("µ", "µ"); - text = text.replace("¶", "¶"); - text = text.replace("·", "·"); - text = text.replace("¸", "¸"); - text = text.replace("¹", "¹"); - text = text.replace("º", "º"); - text = text.replace("»", "»"); - text = text.replace("¼", "¼"); - text = text.replace("½", "½"); - text = text.replace("¾", "¾"); - text = text.replace("¿", "¿"); - text = text.replace("À", "À"); - text = text.replace("Á", "Á"); - text = text.replace("Â", "Â"); - text = text.replace("Ã", "Ã"); - text = text.replace("Ä", "Ä"); - text = text.replace("Å", "Å"); - text = text.replace("Æ", "Æ"); - text = text.replace("Ç", "Ç"); - text = text.replace("È", "È"); - text = text.replace("É", "É"); - text = text.replace("Ê", "Ê"); - text = text.replace("Ë", "Ë"); - text = text.replace("Ì", "Ì"); - text = text.replace("Í", "Í"); - text = text.replace("Î", "Î"); - text = text.replace("Ï", "Ï"); - text = text.replace("Ð", "Ð"); - text = text.replace("Ñ", "Ñ"); - text = text.replace("Ò", "Ò"); - text = text.replace("Ó", "Ó"); - text = text.replace("Ô", "Ô"); - text = text.replace("Õ", "Õ"); - text = text.replace("Ö", "Ö"); - text = text.replace("×", "×"); - text = text.replace("Ø", "Ø"); - text = text.replace("Ù", "Ù"); - text = text.replace("Ú", "Ú"); - text = text.replace("Û", "Û"); - text = text.replace("Ü", "Ü"); - text = text.replace("Ý", "Ý"); - text = text.replace("Þ", "Þ"); - text = text.replace("ß", "ß"); - text = text.replace("à", "à"); - text = text.replace("á", "á"); - text = text.replace("â", "â"); - text = text.replace("ã", "ã"); - text = text.replace("ä", "ä"); - text = text.replace("å", "å"); - text = text.replace("æ", "æ"); - text = text.replace("ç", "ç"); - text = text.replace("è", "è"); - text = text.replace("é", "é"); - text = text.replace("ê", "ê"); - text = text.replace("ë", "ë"); - text = text.replace("ì", "ì"); - text = text.replace("í", "í"); - text = text.replace("î", "î"); - text = text.replace("ï", "ï"); - text = text.replace("ð", "ð"); - text = text.replace("ñ", "ñ"); - text = text.replace("ò", "ò"); - text = text.replace("ó", "ó"); - text = text.replace("ô", "ô"); - text = text.replace("õ", "õ"); - text = text.replace("ö", "ö"); - text = text.replace("÷", "÷"); - text = text.replace("ø", "ø"); - text = text.replace("ù", "ù"); - text = text.replace("ú", "ú"); - text = text.replace("û", "û"); - text = text.replace("ü", "ü"); - text = text.replace("ý", "ý"); - text = text.replace("þ", "þ"); - text = text.replace("ÿ", "ÿ"); - text = text.replace("Œ", "Œ"); - text = text.replace("œ", "œ"); - text = text.replace("Š", "Š"); - text = text.replace("š", "š"); - text = text.replace("Ÿ", "Ÿ"); - text = text.replace("ƒ", "ƒ"); - text = text.replace("ˆ", "ˆ"); - text = text.replace("˜", "˜"); - text = text.replace("Α", "Α"); - text = text.replace("Β", "Β"); - text = text.replace("Γ", "Γ"); - text = text.replace("Δ", "Δ"); - text = text.replace("Ε", "Ε"); - text = text.replace("Ζ", "Ζ"); - text = text.replace("Η", "Η"); - text = text.replace("Θ", "Θ"); - text = text.replace("Ι", "Ι"); - text = text.replace("Κ", "Κ"); - text = text.replace("Λ", "Λ"); - text = text.replace("Μ", "Μ"); - text = text.replace("Ν", "Ν"); - text = text.replace("Ξ", "Ξ"); - text = text.replace("Ο", "Ο"); - text = text.replace("Π", "Π"); - text = text.replace("Ρ", "Ρ"); - text = text.replace("Σ", "Σ"); - text = text.replace("Τ", "Τ"); - text = text.replace("Υ", "Υ"); - text = text.replace("Φ", "Φ"); - text = text.replace("Χ", "Χ"); - text = text.replace("Ψ", "Ψ"); - text = text.replace("Ω", "Ω"); - text = text.replace("α", "α"); - text = text.replace("β", "β"); - text = text.replace("γ", "γ"); - text = text.replace("δ", "δ"); - text = text.replace("ε", "ε"); - text = text.replace("ζ", "ζ"); - text = text.replace("η", "η"); - text = text.replace("θ", "θ"); - text = text.replace("ι", "ι"); - text = text.replace("κ", "κ"); - text = text.replace("λ", "λ"); - text = text.replace("μ", "μ"); - text = text.replace("ν", "ν"); - text = text.replace("ξ", "ξ"); - text = text.replace("ο", "ο"); - text = text.replace("π", "π"); - text = text.replace("ρ", "ρ"); - text = text.replace("ς", "ς"); - text = text.replace("σ", "σ"); - text = text.replace("τ", "τ"); - text = text.replace("υ", "υ"); - text = text.replace("φ", "φ"); - text = text.replace("χ", "χ"); - text = text.replace("ψ", "ψ"); - text = text.replace("ω", "ω"); - text = text.replace("ϑ", "ϑ"); - text = text.replace("ϒ", "ϒ"); - text = text.replace("ϖ", "ϖ"); - text = text.replace(" ", " "); - text = text.replace(" ", " "); - text = text.replace(" ", " "); - text = text.replace("‌", "‌"); - text = text.replace("‍", "‍"); - text = text.replace("‎", "‎"); - text = text.replace("‏", "‏"); - text = text.replace("–", "–"); - text = text.replace("—", "—"); - text = text.replace("‘", "‘"); - text = text.replace("’", "’"); - text = text.replace("‚", "‚"); - text = text.replace("“", "“"); - text = text.replace("”", "”"); - text = text.replace("„", "„"); - text = text.replace("†", "†"); - text = text.replace("‡", "‡"); - text = text.replace("•", "•"); - text = text.replace("…", "…"); - text = text.replace("‰", "‰"); - text = text.replace("′", "′"); - text = text.replace("″", "″"); - text = text.replace("‹", "‹"); - text = text.replace("›", "›"); - text = text.replace("‾", "‾"); - text = text.replace("⁄", "⁄"); - text = text.replace("€", "€"); - text = text.replace("ℑ", "ℑ"); - text = text.replace("℘", "℘"); - text = text.replace("ℜ", "ℜ"); - text = text.replace("™", "™"); - text = text.replace("ℵ", "ℵ"); - text = text.replace("←", "←"); - text = text.replace("↑", "↑"); - text = text.replace("→", "→"); - text = text.replace("↓", "↓"); - text = text.replace("↔", "↔"); - text = text.replace("↵", "↵"); - text = text.replace("⇐", "⇐"); - text = text.replace("⇑", "⇑"); - text = text.replace("⇒", "⇒"); - text = text.replace("⇓", "⇓"); - text = text.replace("⇔", "⇔"); - text = text.replace("∀", "∀"); - text = text.replace("∂", "∂"); - text = text.replace("∃", "∃"); - text = text.replace("∅", "∅"); - text = text.replace("∇", "∇"); - text = text.replace("∈", "∈"); - text = text.replace("∉", "∉"); - text = text.replace("∋", "∋"); - text = text.replace("∏", "∏"); - text = text.replace("∑", "∑"); - text = text.replace("−", "−"); - text = text.replace("∗", "∗"); - text = text.replace("√", "√"); - text = text.replace("∝", "∝"); - text = text.replace("∞", "∞"); - text = text.replace("∠", "∠"); - text = text.replace("∧", "∧"); - text = text.replace("∨", "∨"); - text = text.replace("∩", "∩"); - text = text.replace("∪", "∪"); - text = text.replace("∫", "∫"); - text = text.replace("∴", "∴"); - text = text.replace("∼", "∼"); - text = text.replace("≅", "≅"); - text = text.replace("≈", "≈"); - text = text.replace("≠", "≠"); - text = text.replace("≡", "≡"); - text = text.replace("≤", "≤"); - text = text.replace("≥", "≥"); - text = text.replace("⊂", "⊂"); - text = text.replace("⊃", "⊃"); - text = text.replace("⊄", "⊄"); - text = text.replace("⊆", "⊆"); - text = text.replace("⊇", "⊇"); - text = text.replace("⊕", "⊕"); - text = text.replace("⊗", "⊗"); - text = text.replace("⊥", "⊥"); - text = text.replace("⋅", "⋅"); - text = text.replace("⌈", "⌈"); - text = text.replace("⌉", "⌉"); - text = text.replace("⌊", "⌊"); - text = text.replace("⌋", "⌋"); - text = text.replace("⟨", "〈"); - text = text.replace("⟩", "〉"); - text = text.replace("◊", "◊"); - text = text.replace("♠", "♠"); - text = text.replace("♣", "♣"); - text = text.replace("♥", "♥"); - text = text.replace("♦", "♦"); - // - 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("", MInformation.TEXT_ENCODING)); - fakeXhtmlPageContent.append(""); - fakeXhtmlPageContent.append(""); - fakeXhtmlPageContent.append("</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); - } - -} diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebTable.java b/src/java/com/marcozanon/macaco/web/ui/MWebTable.java index fe93e57..97cc74a 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebTable.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebTable.java @@ -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()) { diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebTableCell.java b/src/java/com/marcozanon/macaco/web/ui/MWebTableCell.java index ab42c86..32263ca 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebTableCell.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebTableCell.java @@ -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 */ diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java index 9bbf431..6b7de1f 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java @@ -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 { diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebUploader.java b/src/java/com/marcozanon/macaco/web/ui/MWebUploader.java index 00a7e80..cf48316 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebUploader.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebUploader.java @@ -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(); // diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebVerticalMenu.java b/src/java/com/marcozanon/macaco/web/ui/MWebVerticalMenu.java index 6af6c31..6ae1f4f 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebVerticalMenu.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebVerticalMenu.java @@ -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(); } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebView.java b/src/java/com/marcozanon/macaco/web/ui/MWebView.java index 9453b78..d5321e3 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebView.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebView.java @@ -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 */ diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebWysiwygBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebWysiwygBox.java index de05a9d..e026693 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebWysiwygBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebWysiwygBox.java @@ -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); diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebXhtmlLabel.java b/src/java/com/marcozanon/macaco/web/ui/MWebXhtmlLabel.java index 2505630..b22c35a 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebXhtmlLabel.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebXhtmlLabel.java @@ -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 index 8b892f4..0000000 --- a/src/java/com/marcozanon/macaco/web/ui/MXhtmlUnsafeStringWebException.java +++ /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); - } - -}