
com.viaoa.web.util.OAJspUtil Maven / Gradle / Ivy
/* Copyright 1999 Vince Via [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.viaoa.web.util;
import com.viaoa.util.OAString;
/**
* Utility used to convert dynamic data for internal text, so that it is html and javascript safe.
*
* Data that is sent as code to the browser needs to be converted, so that the code that is created for it
* does not break, either within the javascript or html.
*
* The outer js code will wrap the text in single or double quotes, and can then have html inside of it.
* The html can also have js code in it, so there is various encoding/escaping that needs to be done
* to have well formed js and html that will not break the back from processing it.
*
*
* @author vvia
*/
public class OAJspUtil {
/**
* Helper method use to make sure that text is correctly escaped to be inside of javascript code.
* This will call createJsString(text, '"', false, false)
*/
/*
public static String createText(final String text) {
String s = createJsString(text, '"', false, true);
return s;
}
public static String createText(final String text, char quoteChar) {
String s = createJsString(text, quoteChar, false, true);
return s;
}
public static String createHtml(final String text) {
String s = createJsString(text, '"', false, true);
return s;
}
public static String createHtml(final String text, char quoteChar) {
String s = createJsString(text, quoteChar, false, true);
return s;
}
*/
/*
* This is only needed when putting html code/data inside of something that is quoted.
*
* where data = "John's" and would need to be convertedto "John's"
* example:
* @return
*/
public static String createEmbeddedHtmlString(final String text, final char htmlQuoteChar) {
String s;
if (htmlQuoteChar == '\'') s = OAString.convert(text, "\'", "'"); // ' not yet supported
else if (htmlQuoteChar == '\"') s = OAString.convert(text, "\"", """); // "
else s = text;
return s;
}
/*
* Javascript code that is inside of JS > Html
* example: $('#id').html(" ..
© 2015 - 2025 Weber Informatics LLC | Privacy Policy