You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/09/18 13:51:59 UTC
svn commit: r289916 - in
/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html:
HtmlRendererUtils.java HtmlResponseWriterImpl.java util/JavascriptUtils.java
Author: mmarinschek
Date: Sun Sep 18 04:51:53 2005
New Revision: 289916
URL: http://svn.apache.org/viewcvs?rev=289916&view=rev
Log:
even better script support
Modified:
myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java
myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java
myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/util/JavascriptUtils.java
Modified: myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java?rev=289916&r1=289915&r2=289916&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java Sun Sep 18 04:51:53 2005
@@ -834,7 +834,7 @@
// Using writeComment instead of write with <!-- tag
StringBuffer script = new StringBuffer();
- script.append("\nfunction ");
+ script.append("function ");
script.append(functionName);
script.append("() {");
if (dummyFormParams != null) {
@@ -868,8 +868,7 @@
script.append(functionName);
script.append("();");
- script.append("\n");
- writer.writeComment(script.toString());
+ writer.writeText(script.toString(),null);
writer.endElement(HTML.SCRIPT_ELEM);
}
Modified: myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java?rev=289916&r1=289915&r2=289916&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java Sun Sep 18 04:51:53 2005
@@ -56,6 +56,9 @@
private String _contentType;
private String _characterEncoding;
private String _startElementName;
+ private Boolean _isScript;
+ private Boolean _isStyle;
+ private Boolean _isTextArea;
private UIComponent _startElementUIComponent;
private boolean _startTagOpen;
@@ -96,7 +99,7 @@
}
else
{
- // validates the encoding, it will throw an UnsupportedEncodingException if it the encoding is invalid
+ // validates the encoding, it will throw an UnsupportedEncodingException if the encoding is invalid
try
{
new String("myfaces".getBytes(), characterEncoding);
@@ -155,11 +158,9 @@
startElement(HTML.SCRIPT_ELEM,null);
writeAttribute(HTML.SCRIPT_TYPE_ATTR,HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT,null);
StringBuffer script = new StringBuffer();
- script.append("\n");
script.append("document.location.replace('").
append(facesContext.getApplication().getViewHandler().getResourceURL(facesContext, "/_javascriptDetector_")).append("?goto=").append(facesContext.getApplication().getViewHandler().getActionURL(facesContext, facesContext.getViewRoot().getViewId())).append("');");
- script.append("\n//");
- writeComment(script.toString());
+ writeText(script.toString(),null);
endElement(HTML.SCRIPT_ELEM);
}
}
@@ -193,19 +194,33 @@
{
if (s_emptyHtmlElements.contains(_startElementName.toLowerCase()))
{
- _writer.write("/>");
+ _writer.write(" />");
// make null, this will cause NullPointer in some invalid element nestings
// (better than doing nothing)
- _startElementName = null;
+ resetStartedElement();
}
else
{
_writer.write('>');
+
+ if(isScriptOrStyle())
+ {
+ _writer.write("<!--\n");
+ }
}
_startTagOpen = false;
}
}
+ private void resetStartedElement()
+ {
+ _startElementName = null;
+ _startElementUIComponent = null;
+ _isScript = null;
+ _isStyle = null;
+ _isTextArea = null;
+ }
+
public void endElement(String name) throws IOException
{
if (name == null)
@@ -227,18 +242,17 @@
if(_startTagOpen)
{
+
// we will get here only if no text or attribute was written after the start element was opened
- if (s_emptyHtmlElements.contains(name.toLowerCase()))
+ // now we close out the started tag - if it is an empty tag, this is then fully closed
+ closeStartTagIfNecessary();
+
+ //tag was no empty tag - it has no accompanying end tag now.
+ if(_startElementName!=null)
{
- _writer.write("/>");
+ //write closing tag
+ writeEndTag(name);
}
- else
- {
- _writer.write("></");
- _writer.write(name);
- _writer.write('>');
- }
- _startTagOpen = false;
}
else
{
@@ -249,14 +263,24 @@
}
else
{
- _writer.write("</");
- _writer.write(name);
- _writer.write('>');
+ writeEndTag(name);
}
}
- _startElementName = null;
- _startElementUIComponent = null;
+ resetStartedElement();
+ }
+
+ private void writeEndTag(String name)
+ throws IOException
+ {
+ if(isScriptOrStyle())
+ {
+ _writer.write("\n//-->");
+ }
+
+ _writer.write("</");
+ _writer.write(name);
+ _writer.write('>');
}
public void writeAttribute(String name, Object value, String componentPropertyName) throws IOException
@@ -315,14 +339,17 @@
else
{
/*
- if (_startElementName.equalsIgnoreCase(HTML.ANCHOR_ELEM) && //TODO: Also support image and button urls ?
+ Todo: what is this section about? still needed?
+ client side state saving is now done via javascript...
+
+ if (_startElementName.equalsIgnoreCase(HTML.ANCHOR_ELEM) && //Also support image and button urls?
name.equalsIgnoreCase(HTML.HREF_ATTR) &&
!strValue.startsWith("#"))
{
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext))
{
- //TODO/HACK: saving state in url depends on the work together
+ // saving state in url depends on the work together
// of 3 (theoretically) pluggable components:
// ViewHandler, ResponseWriter and ViewTag
// We should try to make this HtmlResponseWriterImpl able
@@ -415,17 +442,62 @@
private boolean isScriptOrStyle()
{
- return _startElementName != null &&
- (_startElementName.equalsIgnoreCase(HTML.SCRIPT_ELEM) ||
- _startElementName.equalsIgnoreCase(HTML.STYLE_ELEM));
+ initializeStartedTagInfo();
+
+ return (_isStyle != null && _isStyle.booleanValue()) ||
+ (_isScript != null && _isScript.booleanValue());
}
private boolean isTextarea()
{
- return _startElementName != null &&
- (_startElementName.equalsIgnoreCase(HTML.TEXTAREA_ELEM));
+ initializeStartedTagInfo();
+
+ return _isTextArea != null && _isTextArea.booleanValue();
}
+ private void initializeStartedTagInfo()
+ {
+ if(_startElementName != null)
+ {
+ if(_isScript==null)
+ {
+ if(_startElementName.equalsIgnoreCase(HTML.SCRIPT_ELEM))
+ {
+ _isScript = Boolean.TRUE;
+ _isStyle = Boolean.FALSE;
+ _isTextArea = Boolean.FALSE;
+ }
+ else
+ {
+ _isScript = Boolean.FALSE;
+ }
+ }
+ if(_isStyle == null)
+ {
+ if(_startElementName.equalsIgnoreCase(HTML.STYLE_ELEM))
+ {
+ _isStyle = Boolean.TRUE;
+ _isTextArea = Boolean.FALSE;
+ }
+ else
+ {
+ _isStyle = Boolean.FALSE;
+ }
+ }
+
+ if(_isTextArea == null)
+ {
+ if(_startElementName.equalsIgnoreCase(HTML.TEXTAREA_ELEM))
+ {
+ _isStyle = Boolean.TRUE;
+ }
+ else
+ {
+ _isStyle = Boolean.FALSE;
+ }
+ }
+ }
+ }
public ResponseWriter cloneWithWriter(Writer writer)
{
@@ -441,11 +513,7 @@
public void close() throws IOException
{
- if (_startTagOpen)
- {
- // we will get here only if no text was written after the start element was opened
- _writer.write(" />");
- }
+ closeStartTagIfNecessary();
_writer.close();
}
Modified: myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/util/JavascriptUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/util/JavascriptUtils.java?rev=289916&r1=289915&r2=289916&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/util/JavascriptUtils.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/util/JavascriptUtils.java Sun Sep 18 04:51:53 2005
@@ -297,12 +297,11 @@
StringBuffer script = new StringBuffer();
- script.append("\n");
-
-
- script.append("function " + AUTO_SCROLL_FUNCTION + " {\n" +
- " var x = 0; var y = 0;\n" +
- " if (self.pageXOffset) {\n" +
+ script.append("function ");
+ script.append(AUTO_SCROLL_FUNCTION);
+ script.append(" {\n");
+ script.append(" var x = 0; var y = 0;\n");
+ script.append( " if (self.pageXOffset) {\n"+
" x = self.pageXOffset;\n" +
" y = self.pageYOffset;\n" +
" } else if (document.documentElement && document.documentElement.scrollLeft) {\n" +
@@ -339,9 +338,8 @@
script.append("window.scrollTo(").append(x).append(",").append(y).append(");\n");
}
}
- script.append("\n//");
- writer.writeComment(script.toString());
+ writer.writeText(script.toString(),null);
writer.endElement(HTML.SCRIPT_ELEM);
}