All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viaoa.web.OAJspUtil Maven / Gradle / Ivy

There is a newer version: 3.7.10
Show newest version
package com.viaoa.web;

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