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 {
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", "<br />");
+ //
+ 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("<?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);
+ }
+
}
--- /dev/null
+/**
+ * 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);
+ }
+
+}
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;
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);
}
}
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))));
}
}
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
import java.util.LinkedList;
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(" ");
}
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 */
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;
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 */
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());
}
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);
+ " 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
+ " linkTags[l].href = '%s';"
+ " }"
+ "}";
- this.getApplicationContextReference().addPlainTextResponseContent(String.format(commands, MWebString.getJavascriptEscapedString(cssSource)));
+ this.getApplicationContextReference().addPlainTextResponseContent(String.format(commands, MText.getJavascriptEscapedString(cssSource)));
}
/* Requests */
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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();
//
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
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();
//
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)));
}
}
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 {
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();
//
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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();
//
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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 = "";
}
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++) {
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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();
//
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 */
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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 = "";
}
}
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();
//
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 {
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) {
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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();
//
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 {
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 {
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();
//
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
+
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();
//
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
+
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();
//
+++ /dev/null
-/**
- * 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("&", "&");
- text = text.replace("\"", """);
- text = text.replace("'", "'");
- text = text.replace("<", "<");
- text = text.replace(">", ">");
- //
- 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(" ", " ");
- text = text.replace("¡", "¡");
- text = text.replace("¢", "¢");
- text = text.replace("£", "£");
- text = text.replace("¤", "¤");
- text = text.replace("¥", "¥");
- text = text.replace("¦", "¦");
- text = text.replace("§", "§");
- text = text.replace("¨", "¨");
- text = text.replace("©", "©");
- text = text.replace("ª", "ª");
- text = text.replace("«", "«");
- text = text.replace("¬", "¬");
- text = text.replace("­", "­");
- text = text.replace("®", "®");
- text = text.replace("¯", "¯");
- text = text.replace("°", "°");
- text = text.replace("±", "±");
- text = text.replace("²", "²");
- text = text.replace("³", "³");
- text = text.replace("´", "´");
- text = text.replace("µ", "µ");
- text = text.replace("¶", "¶");
- text = text.replace("·", "·");
- text = text.replace("¸", "¸");
- text = text.replace("¹", "¹");
- text = text.replace("º", "º");
- text = text.replace("»", "»");
- text = text.replace("¼", "¼");
- text = text.replace("½", "½");
- text = text.replace("¾", "¾");
- text = text.replace("¿", "¿");
- text = text.replace("À", "À");
- text = text.replace("Á", "Á");
- text = text.replace("Â", "Â");
- text = text.replace("Ã", "Ã");
- text = text.replace("Ä", "Ä");
- text = text.replace("Å", "Å");
- text = text.replace("Æ", "Æ");
- text = text.replace("Ç", "Ç");
- text = text.replace("È", "È");
- text = text.replace("É", "É");
- text = text.replace("Ê", "Ê");
- text = text.replace("Ë", "Ë");
- text = text.replace("Ì", "Ì");
- text = text.replace("Í", "Í");
- text = text.replace("Î", "Î");
- text = text.replace("Ï", "Ï");
- text = text.replace("Ð", "Ð");
- text = text.replace("Ñ", "Ñ");
- text = text.replace("Ò", "Ò");
- text = text.replace("Ó", "Ó");
- text = text.replace("Ô", "Ô");
- text = text.replace("Õ", "Õ");
- text = text.replace("Ö", "Ö");
- text = text.replace("×", "×");
- text = text.replace("Ø", "Ø");
- text = text.replace("Ù", "Ù");
- text = text.replace("Ú", "Ú");
- text = text.replace("Û", "Û");
- text = text.replace("Ü", "Ü");
- text = text.replace("Ý", "Ý");
- text = text.replace("Þ", "Þ");
- text = text.replace("ß", "ß");
- text = text.replace("à", "à");
- text = text.replace("á", "á");
- text = text.replace("â", "â");
- text = text.replace("ã", "ã");
- text = text.replace("ä", "ä");
- text = text.replace("å", "å");
- text = text.replace("æ", "æ");
- text = text.replace("ç", "ç");
- text = text.replace("è", "è");
- text = text.replace("é", "é");
- text = text.replace("ê", "ê");
- text = text.replace("ë", "ë");
- text = text.replace("ì", "ì");
- text = text.replace("í", "í");
- text = text.replace("î", "î");
- text = text.replace("ï", "ï");
- text = text.replace("ð", "ð");
- text = text.replace("ñ", "ñ");
- text = text.replace("ò", "ò");
- text = text.replace("ó", "ó");
- text = text.replace("ô", "ô");
- text = text.replace("õ", "õ");
- text = text.replace("ö", "ö");
- text = text.replace("÷", "÷");
- text = text.replace("ø", "ø");
- text = text.replace("ù", "ù");
- text = text.replace("ú", "ú");
- text = text.replace("û", "û");
- text = text.replace("ü", "ü");
- text = text.replace("ý", "ý");
- text = text.replace("þ", "þ");
- text = text.replace("ÿ", "ÿ");
- text = text.replace("Œ", "Œ");
- text = text.replace("œ", "œ");
- text = text.replace("Š", "Š");
- text = text.replace("š", "š");
- text = text.replace("Ÿ", "Ÿ");
- text = text.replace("ƒ", "ƒ");
- text = text.replace("ˆ", "ˆ");
- text = text.replace("˜", "˜");
- text = text.replace("Α", "Α");
- text = text.replace("Β", "Β");
- text = text.replace("Γ", "Γ");
- text = text.replace("Δ", "Δ");
- text = text.replace("Ε", "Ε");
- text = text.replace("Ζ", "Ζ");
- text = text.replace("Η", "Η");
- text = text.replace("Θ", "Θ");
- text = text.replace("Ι", "Ι");
- text = text.replace("Κ", "Κ");
- text = text.replace("Λ", "Λ");
- text = text.replace("Μ", "Μ");
- text = text.replace("Ν", "Ν");
- text = text.replace("Ξ", "Ξ");
- text = text.replace("Ο", "Ο");
- text = text.replace("Π", "Π");
- text = text.replace("Ρ", "Ρ");
- text = text.replace("Σ", "Σ");
- text = text.replace("Τ", "Τ");
- text = text.replace("Υ", "Υ");
- text = text.replace("Φ", "Φ");
- text = text.replace("Χ", "Χ");
- text = text.replace("Ψ", "Ψ");
- text = text.replace("Ω", "Ω");
- text = text.replace("α", "α");
- text = text.replace("β", "β");
- text = text.replace("γ", "γ");
- text = text.replace("δ", "δ");
- text = text.replace("ε", "ε");
- text = text.replace("ζ", "ζ");
- text = text.replace("η", "η");
- text = text.replace("θ", "θ");
- text = text.replace("ι", "ι");
- text = text.replace("κ", "κ");
- text = text.replace("λ", "λ");
- text = text.replace("μ", "μ");
- text = text.replace("ν", "ν");
- text = text.replace("ξ", "ξ");
- text = text.replace("ο", "ο");
- text = text.replace("π", "π");
- text = text.replace("ρ", "ρ");
- text = text.replace("ς", "ς");
- text = text.replace("σ", "σ");
- text = text.replace("τ", "τ");
- text = text.replace("υ", "υ");
- text = text.replace("φ", "φ");
- text = text.replace("χ", "χ");
- text = text.replace("ψ", "ψ");
- text = text.replace("ω", "ω");
- text = text.replace("ϑ", "ϑ");
- text = text.replace("ϒ", "ϒ");
- text = text.replace("ϖ", "ϖ");
- text = text.replace(" ", " ");
- text = text.replace(" ", " ");
- text = text.replace(" ", " ");
- text = text.replace("‌", "‌");
- text = text.replace("‍", "‍");
- text = text.replace("‎", "‎");
- text = text.replace("‏", "‏");
- text = text.replace("–", "–");
- text = text.replace("—", "—");
- text = text.replace("‘", "‘");
- text = text.replace("’", "’");
- text = text.replace("‚", "‚");
- text = text.replace("“", "“");
- text = text.replace("”", "”");
- text = text.replace("„", "„");
- text = text.replace("†", "†");
- text = text.replace("‡", "‡");
- text = text.replace("•", "•");
- text = text.replace("…", "…");
- text = text.replace("‰", "‰");
- text = text.replace("′", "′");
- text = text.replace("″", "″");
- text = text.replace("‹", "‹");
- text = text.replace("›", "›");
- text = text.replace("‾", "‾");
- text = text.replace("⁄", "⁄");
- text = text.replace("€", "€");
- text = text.replace("ℑ", "ℑ");
- text = text.replace("℘", "℘");
- text = text.replace("ℜ", "ℜ");
- text = text.replace("™", "™");
- text = text.replace("ℵ", "ℵ");
- text = text.replace("←", "←");
- text = text.replace("↑", "↑");
- text = text.replace("→", "→");
- text = text.replace("↓", "↓");
- text = text.replace("↔", "↔");
- text = text.replace("↵", "↵");
- text = text.replace("⇐", "⇐");
- text = text.replace("⇑", "⇑");
- text = text.replace("⇒", "⇒");
- text = text.replace("⇓", "⇓");
- text = text.replace("⇔", "⇔");
- text = text.replace("∀", "∀");
- text = text.replace("∂", "∂");
- text = text.replace("∃", "∃");
- text = text.replace("∅", "∅");
- text = text.replace("∇", "∇");
- text = text.replace("∈", "∈");
- text = text.replace("∉", "∉");
- text = text.replace("∋", "∋");
- text = text.replace("∏", "∏");
- text = text.replace("∑", "∑");
- text = text.replace("−", "−");
- text = text.replace("∗", "∗");
- text = text.replace("√", "√");
- text = text.replace("∝", "∝");
- text = text.replace("∞", "∞");
- text = text.replace("∠", "∠");
- text = text.replace("∧", "∧");
- text = text.replace("∨", "∨");
- text = text.replace("∩", "∩");
- text = text.replace("∪", "∪");
- text = text.replace("∫", "∫");
- text = text.replace("∴", "∴");
- text = text.replace("∼", "∼");
- text = text.replace("≅", "≅");
- text = text.replace("≈", "≈");
- text = text.replace("≠", "≠");
- text = text.replace("≡", "≡");
- text = text.replace("≤", "≤");
- text = text.replace("≥", "≥");
- text = text.replace("⊂", "⊂");
- text = text.replace("⊃", "⊃");
- text = text.replace("⊄", "⊄");
- text = text.replace("⊆", "⊆");
- text = text.replace("⊇", "⊇");
- text = text.replace("⊕", "⊕");
- text = text.replace("⊗", "⊗");
- text = text.replace("⊥", "⊥");
- text = text.replace("⋅", "⋅");
- text = text.replace("⌈", "⌈");
- text = text.replace("⌉", "⌉");
- text = text.replace("⌊", "⌊");
- 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("<?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);
- }
-
-}
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
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 = "";
}
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>");
}
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()) {
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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 */
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
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 {
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap;
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();
//
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
parentItemKey = ""; // rewritten for better readability
}
//
- String customClasses = MWebString.getXhtmlEscapedString(this.getCustomClasses());
+ String customClasses = MText.getXhtmlEscapedString(this.getCustomClasses());
if (null == customClasses) {
customClasses = "";
}
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 = "";
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>");
//
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>");
}
}
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>");
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();
}
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;
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 */
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 {
}
//
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
}
//
//
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();
//
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 {
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())));
}
}
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);
package com.marcozanon.macaco.web.ui;
+import com.marcozanon.macaco.text.MText;
+
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();
//
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()))));
}
}
+++ /dev/null
-/**
- * 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);
- }
-
-}