com.nurelm.util
Class WebUtil

java.lang.Object
  extended bycom.nurelm.util.WebUtil

public class WebUtil
extends java.lang.Object

Class providing basic Web utility functions.


Constructor Summary
WebUtil()
           
 
Method Summary
static java.lang.String addTextToHtmlHead(java.lang.String html, java.lang.String textToAdd)
          Puts specified text into area of HTML.
static java.lang.String cleanHtml(java.lang.String text, java.lang.String allowedTags, java.lang.String allowedAttributes, boolean dropParas)
          Cleans up and formats HTML with JTidy library.
static java.lang.String convertQuotesToHtml(java.lang.String inputString)
          Replaces ALL quotes (") in a string with the HTML code " Q: Where do we need to use this? A: When displaying a text string in a TEXT type input field, and you want to display the quotes properly and have them stored properly.
static java.lang.String convertServerNameToDomain(java.lang.String serverName)
          This method typically accepts a String that is obtained via request.getServerName().
static java.lang.String convertToHexSpaces(java.lang.String inputString)
          Replaces ALL spaces in a string with hex value of '%20'.
static java.lang.String createPopupJS(java.lang.String url, java.lang.String features)
           
static java.lang.String encodeWithNumericCharRefs(java.lang.String input)
          Replaces characters in a string that have character values of 160 or above with their equivalent HTML numeric character references.
static void forwardRequest(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String path)
          Forwards to the requested address.
static Browser getBrowserObject(java.lang.String userAgent)
          This method typically accepts a String and gives Browser Object.
static java.lang.String getEditButton(javax.servlet.http.HttpServletRequest request, java.lang.String actionName, java.lang.String altText, java.lang.String linkFile, java.util.Map linkParams, boolean enabled, boolean openInNewWindow, java.lang.String anchorName)
          Constructs a NuRelm edit button.
static java.lang.String getIconImgTag(java.lang.String iconName, java.lang.String altText, boolean enabled, java.lang.String webFilePath)
          Constructs an image tag to the correct NuContent icon based on the parameters provided.
static java.lang.String getInputImgTag(java.lang.String iconName, java.lang.String altText, boolean enabled, java.lang.String webFilePath)
          Constructs an input image tag to the correct NuContent icon based on the parameters provided.
static java.lang.String getNucontentWebFilePath(javax.servlet.http.HttpServletRequest request)
          Returns absolute path to NuContent's Files directory, including context path at beginning.
static java.lang.String getNucontentWebFilePathNoContext()
           
static java.lang.String getNucontentWebPath(javax.servlet.http.HttpServletRequest request)
          Returns absolute path to NuContent's Web assets directory, including context path at beginning.
static java.lang.String getNucontentWebPathNoContext()
           
static java.lang.String getParamValueFromURL(java.lang.String param, java.lang.String URL)
          Gets the specified parameter's value from the given URL.
static java.lang.String getRefererURINoContextPath(javax.servlet.http.HttpServletRequest request)
          Returns the URI of the refering page with no context path.
static java.lang.String getUndecodedParameter(javax.servlet.http.HttpServletRequest request, java.lang.String parameterName)
          Gets given parameter value passed into through the URL without decoding the value.
static java.lang.String getURINoContextPath(javax.servlet.http.HttpServletRequest request)
          Returns the URI with no context path.
static java.lang.String htmlToIFrameFormat(java.lang.String text)
          The WYSIWYG editor in /home/app/client/cms/web/editContentRich.jsp uses JavaScript that breaks if you include quotes, \r or \n chars.
static java.lang.String htmlToTextAreaFormat(java.lang.String text)
          Basically the opposite of textToHtml().
static boolean isWYSIWYGBrowser(javax.servlet.http.HttpServletRequest request)
          Returns true if the client's Web browser supports the WYSIWYG text editor; false otherwise.
static float javaScriptParseFloat(java.lang.String inputs)
           
static void printNode(org.w3c.dom.Node node, java.io.PrintWriter out, java.lang.String allowedTags, java.lang.String allowedAttributes)
          Prints the specified JTidy DOM node recursively.
static void redirectResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String path)
          Redirects to the requested URI.
static java.lang.String replaceStringNull(java.lang.String str)
          Returns "" if the string is null, otherwise it returns the passed-in string unchanged.
static java.lang.String setParamValueInURL(java.lang.String param, java.lang.String value, java.lang.String URL)
          Sets the specified parameter's value in the given URL.
static java.lang.String textToHtml(java.lang.String text)
          Takes regular text and makes it "webby" by changing newlines to "
".
 void WebUtil()
          Constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebUtil

public WebUtil()
Method Detail

WebUtil

public void WebUtil()
Constructor.


forwardRequest

public static void forwardRequest(javax.servlet.ServletRequest request,
                                  javax.servlet.ServletResponse response,
                                  java.lang.String path)
Forwards to the requested address.

Parameters:
request - The current request to be forwarded.
response - The current response to be forwarded.
path - The path to which we'll forward.

redirectResponse

public static void redirectResponse(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    java.lang.String path)
Redirects to the requested URI. Prepends the current context path.

Parameters:
request - The current request, used to determine context path.
response - The current response to be redirected.
path - The path to which we'll forward.

getParamValueFromURL

public static java.lang.String getParamValueFromURL(java.lang.String param,
                                                    java.lang.String URL)
Gets the specified parameter's value from the given URL.

Parameters:
param - The parameter whose value should be retrieved from the URL.
URL - The URL from which to retrieve a param value.
Returns:
The value of the specified parameter.

setParamValueInURL

public static java.lang.String setParamValueInURL(java.lang.String param,
                                                  java.lang.String value,
                                                  java.lang.String URL)
Sets the specified parameter's value in the given URL.

Parameters:
param - The parameter whose value should be set in the URL.
value - The value to set the parameter to.
URL - The URL in which to set a param value.
Returns:
The updated URL (unchanged if parameter is not specified).

getNucontentWebPath

public static java.lang.String getNucontentWebPath(javax.servlet.http.HttpServletRequest request)
Returns absolute path to NuContent's Web assets directory, including context path at beginning.

Parameters:
request - Current HttpServletRequest for which path will be built.
Returns:
Absolute path to NuContent's Web assets directory.

getNucontentWebPathNoContext

public static java.lang.String getNucontentWebPathNoContext()

getNucontentWebFilePath

public static java.lang.String getNucontentWebFilePath(javax.servlet.http.HttpServletRequest request)
Returns absolute path to NuContent's Files directory, including context path at beginning.

Parameters:
request - Current HttpServletRequest for which path will be built.
Returns:
Absolute path to NuContent's Files assets directory.

getNucontentWebFilePathNoContext

public static java.lang.String getNucontentWebFilePathNoContext()

getURINoContextPath

public static java.lang.String getURINoContextPath(javax.servlet.http.HttpServletRequest request)
Returns the URI with no context path.

Parameters:
request - The request from which to extract URI and context path.
Returns:
URI without context path

getRefererURINoContextPath

public static java.lang.String getRefererURINoContextPath(javax.servlet.http.HttpServletRequest request)
Returns the URI of the refering page with no context path.

Parameters:
request - The request from which to extract referer's URI and current context path.
Returns:
Referer's URI with no context path.

addTextToHtmlHead

public static java.lang.String addTextToHtmlHead(java.lang.String html,
                                                 java.lang.String textToAdd)
Puts specified text into area of HTML. If no exists, then just put it at the top of the file.


getUndecodedParameter

public static java.lang.String getUndecodedParameter(javax.servlet.http.HttpServletRequest request,
                                                     java.lang.String parameterName)
Gets given parameter value passed into through the URL without decoding the value. Normally, we use request.getParameter(), but when params are passed in through the URL, this method decodes them. Usually, this is fine, but when we are parsing restrictvalues in a repeat block, it causes problems: "real" commas cannot be distinguished from commas separating restrictvalues, making it impossible to figure out where to break values out.

A parameter passed in through the URL will always override one passed in through a form.

Parameters:
request - The current request object.
parameterName - The name of the param to get.
Returns:
The undecoded value of the param.

getIconImgTag

public static java.lang.String getIconImgTag(java.lang.String iconName,
                                             java.lang.String altText,
                                             boolean enabled,
                                             java.lang.String webFilePath)
Constructs an image tag to the correct NuContent icon based on the parameters provided.

Parameters:
iconName - The name of the icon to present.
altText - The icon's alt text.
enabled - Whether icon should be enabled or disabled.
webFilePath - The HTTP path to this context's web files.
Returns:
Propertly constructed NuContent icon image tag.

getInputImgTag

public static java.lang.String getInputImgTag(java.lang.String iconName,
                                              java.lang.String altText,
                                              boolean enabled,
                                              java.lang.String webFilePath)
Constructs an input image tag to the correct NuContent icon based on the parameters provided.

Parameters:
iconName - The name of the icon to present.
altText - The icon's alt text.
enabled - Whether icon should be enabled or disabled.
webFilePath - The HTTP path to this context's web files.
Returns:
Propertly constructed NuContent input image tag.

createPopupJS

public static java.lang.String createPopupJS(java.lang.String url,
                                             java.lang.String features)

getEditButton

public static java.lang.String getEditButton(javax.servlet.http.HttpServletRequest request,
                                             java.lang.String actionName,
                                             java.lang.String altText,
                                             java.lang.String linkFile,
                                             java.util.Map linkParams,
                                             boolean enabled,
                                             boolean openInNewWindow,
                                             java.lang.String anchorName)
Constructs a NuRelm edit button. It is useful to have one function that does this for any edit buttons on the whole site since many factors affect all edit buttons on a page at the same time. For example, if a page is locked to someone else, the page's edit buttons will be greyed out, but there will be a link to a page explaining that the page is locked. A similar situation occurs when a page is being reviewed by someone else.

Parameters:
request - The current ServletRequest, which is used to get information about the current page that is required for building the link, like the context path, and info about the current page locking status.
actionName - The name of the action the button represents. This corresponds to icon to present, and will be used to retrieve the icon image with the same name.
altText - The icon's alt text.
linkFile - The file path part of the link (no parameters).
linkParams - The link parameters, with parameter name/values corresponding to Map key/values.
openInNewWindow - true if link should open in a new window.
Returns:
The full button link and image tags, ready to place on the page.

cleanHtml

public static java.lang.String cleanHtml(java.lang.String text,
                                         java.lang.String allowedTags,
                                         java.lang.String allowedAttributes,
                                         boolean dropParas)
Cleans up and formats HTML with JTidy library. Cleans up bad HTML, Word HTML, unclosed tags, etc.

Parameters:
text - The incoming HTML text to be processed.
allowedTags - Comma separated list of tags to be included in resulting HTML.
Returns:
Returns cleaned up HTML.

printNode

public static void printNode(org.w3c.dom.Node node,
                             java.io.PrintWriter out,
                             java.lang.String allowedTags,
                             java.lang.String allowedAttributes)
Prints the specified JTidy DOM node recursively.

Parameters:
node - The JTidy Node to be printed.
out - The Writer to stream output to.
allowedTags - A comma separated list of lowercase tags to include. All other tags will be removed (but their contents will remain).
allowedAttributes - A comma separated list of lowercase tag attributes to include in tags. All other attributes will be removed. Note: The list of tags and attributes must start and end with a comma in order to keep searching simple in this function.

encodeWithNumericCharRefs

public static java.lang.String encodeWithNumericCharRefs(java.lang.String input)
Replaces characters in a string that have character values of 160 or above with their equivalent HTML numeric character references. For example, the copyright symbol (c with a circle around it) is replaced by © - this allows users to paste just about anything into NuRelm's wysiwyg editor.

Parameters:
input - String to make replacements on.
Returns:
New string with replacements made

textToHtml

public static java.lang.String textToHtml(java.lang.String text)
Takes regular text and makes it "webby" by changing newlines to "
". Changes multiple spaces to "  ". That is, one space followed by "  " for each following space. Single spaces are left alone. Updated 8/28/2002: Changed conversion from \n ->
\n to \r\n -> \r\n
, and made it case insensitive. Textareas add \r\n when you hit return (it's in the HTML rules, or at least one of the HTML books we reviewed).

Parameters:
text - The input text to be "webified"
Returns:
The resulting HTML.

htmlToTextAreaFormat

public static java.lang.String htmlToTextAreaFormat(java.lang.String text)
Basically the opposite of textToHtml(). This is used to prepare content that will be displayed in an HTML textarea for editing. In the NuContent scheme, we add
s and extra spaces to content that is edited in a textarea. This helps preserve whitespace for folks that don't know HTML. As of the WYSIWYG NuContent version, we will begin saving content in HTML format (w/ the
s added in). So, we need a way to take the extra HTML out before the editer views the content in a textarea to edit it. This method is called to convert the content just before it is presented in a textarea. Initially used by CMSController, in the EDIT_CONTENT block.

Parameters:
text - The input text to be "textarea"ified
Returns:
The resulting content, minus some
s &  s

htmlToIFrameFormat

public static java.lang.String htmlToIFrameFormat(java.lang.String text)
The WYSIWYG editor in /home/app/client/cms/web/editContentRich.jsp uses JavaScript that breaks if you include quotes, \r or \n chars. This method removes all \r and \n's, and escapes the quotes. The cleaned text is returned.

Parameters:
text - The input text to be "IFrame"ified
Returns:
The resulting content, minus \r\n's, and quotes escaped

replaceStringNull

public static java.lang.String replaceStringNull(java.lang.String str)
Returns "" if the string is null, otherwise it returns the passed-in string unchanged. This is usefull when printing data to a Web view. If the data is null, then "null" will appear in the web view. We don't want that, so I wrote this method.

Parameters:
str - DOCUMENT ME!
Returns:
DOCUMENT ME!

convertToHexSpaces

public static java.lang.String convertToHexSpaces(java.lang.String inputString)
Replaces ALL spaces in a string with hex value of '%20'. Q: Where do we need to use this? A: When you add form fields directly to a query string, you need to use this. For example, we grab an "imageId" field in the CES app that can contain spaces. For example, imageId="My Picture". We add this directly to the query string in a "Modify Image" link. Unless we deal with the space, it breaks.

Parameters:
inputString - string that needs spaces converted to hex values
Returns:
DOCUMENT ME!

convertQuotesToHtml

public static java.lang.String convertQuotesToHtml(java.lang.String inputString)
Replaces ALL quotes (") in a string with the HTML code " Q: Where do we need to use this? A: When displaying a text string in a TEXT type input field, and you want to display the quotes properly and have them stored properly.

Parameters:
inputString - string that needs quotes converted
Returns:
DOCUMENT ME!

convertServerNameToDomain

public static java.lang.String convertServerNameToDomain(java.lang.String serverName)
                                                  throws NuPlatformException
This method typically accepts a String that is obtained via request.getServerName(). Any subdomain data is stripped off, leaving the registered domain name. If you pass in "localhost", "localhost" is returned. If you pass in "nurelm.com", "nurelm.com" is returned. If you pass in "www.nurelm.com", "nurelm.com" is returned. If you pass in "sub.domain.nurelm.com", "nurelm.com" is returned. If you pass in trash, a NuPlatformException is thrown. If you pass in null, a NullPointerException is thrown. Originally created to support NuPlatformUtil.getEmailDomain().

Parameters:
serverName - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
NuPlatformException - DOCUMENT ME!

isWYSIWYGBrowser

public static boolean isWYSIWYGBrowser(javax.servlet.http.HttpServletRequest request)
Returns true if the client's Web browser supports the WYSIWYG text editor; false otherwise. Currently supported browsers:

Microsoft Internet Explorer 5 and up (any browser with "... MSIE 5(or higher). ... in the user-agent header)
Netscape 7.0 and up (any browser with "Mozilla ... Netscape/7(or more). ..." or "Mozilla ... MultiZilla ..." in the user-agent header
Firefox, any version (any browser with "Mozilla ... Firefox ..." in the user-agent header)

A little header info: http://www.zytrax.com/tech/web/browser_ids.htm
A lot of header info: http://www.pgts.com.au/pgtsj/pgtsj0208j.html

Parameters:
request - The current HttpServletRequest from which to get user agent
Returns:
true if the current user agent is either MSIE 5+, Mozilla 1.4+, or Firefox

getBrowserObject

public static Browser getBrowserObject(java.lang.String userAgent)
This method typically accepts a String and gives Browser Object.

Parameters:
userAgent - Browser detail string UserAgent!
Returns:
Browser Object!
Throws:
NuPlatformException - DOCUMENT ME!

javaScriptParseFloat

public static float javaScriptParseFloat(java.lang.String inputs)