Search in sources :

Example 1 with HtmlResponseWriterImpl

use of org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl in project myfaces by apache.

the class HtmlResponseWriterImplTest method testEmptyTagNotRenderEndOnXhtmlUppercase.

/**
 * In xhtml, it is valid to have an html empty tag with content.
 *
 * @throws IOException
 */
public void testEmptyTagNotRenderEndOnXhtmlUppercase() throws IOException {
    _writer = new HtmlResponseWriterImpl(_stringWriter, "application/xml", "UTF-8", false);
    _writer.startDocument();
    _writer.startElement("body", null);
    _writer.startElement("BR", null);
    _writer.writeText("hello", null);
    _writer.endElement("BR");
    _writer.endElement("body");
    _writer.endDocument();
    // the following should render <br>hello</br>
    String output = _stringWriter.toString();
    Assert.assertNotNull(output);
    Assert.assertTrue(output.contains("<BR>"));
    Assert.assertTrue(output.contains("</BR>"));
}
Also used : HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)

Example 2 with HtmlResponseWriterImpl

use of org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl in project myfaces by apache.

the class HtmlResponseWriterImplTest method testEmptyTagNotRenderEndOnXml.

/**
 * In xhtml, it is valid to have an html empty tag with content.
 *
 * @throws IOException
 */
public void testEmptyTagNotRenderEndOnXml() throws IOException {
    _writer = new HtmlResponseWriterImpl(_stringWriter, "application/xml", "UTF-8", false);
    _writer.startDocument();
    _writer.startElement("body", null);
    _writer.startElement("br", null);
    _writer.writeText("hello", null);
    _writer.endElement("br");
    _writer.endElement("body");
    _writer.endDocument();
    // the following should render <br>hello</br>
    String output = _stringWriter.toString();
    Assert.assertNotNull(output);
    Assert.assertTrue(output.contains("<br>"));
    Assert.assertTrue(output.contains("</br>"));
}
Also used : HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)

Example 3 with HtmlResponseWriterImpl

use of org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl in project myfaces by apache.

the class HtmlResponseWriterImplTest method testScriptOnHtmlIsoEncodingAndScriptXhmlComments.

public void testScriptOnHtmlIsoEncodingAndScriptXhmlComments() throws IOException {
    _writer = new HtmlResponseWriterImpl(_stringWriter, "text/html", "ISO-8859-1", true);
    String innerScript = "document.write('HELLO');";
    _writer.startDocument();
    _writer.startElement(HTML.SCRIPT_ELEM, null);
    _writer.write(innerScript);
    _writer.endElement(HTML.SCRIPT_ELEM);
    _writer.endDocument();
    String output = _stringWriter.toString();
    Assert.assertNotNull(output);
    Assert.assertTrue("script does not contain body:" + innerScript, output.contains(innerScript));
    Assert.assertTrue("script does not have start comment <!-- ", output.contains(CommentUtils.COMMENT_SIMPLE_START));
    Assert.assertTrue("script does not have end comment --> ", output.contains("//" + CommentUtils.COMMENT_SIMPLE_END));
}
Also used : HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)

Example 4 with HtmlResponseWriterImpl

use of org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl in project myfaces by apache.

the class HtmlResponseWriterImplTest method testScriptOnXhtmlUTF8Encoding.

public void testScriptOnXhtmlUTF8Encoding() throws IOException {
    _writer = new HtmlResponseWriterImpl(_stringWriter, "application/xhtml+xml", "UTF-8", false);
    String innerScript = "document.write('HELLO');";
    _writer.startDocument();
    _writer.startElement(HTML.SCRIPT_ELEM, null);
    _writer.write(innerScript);
    _writer.endElement(HTML.SCRIPT_ELEM);
    _writer.endDocument();
    String output = _stringWriter.toString();
    Assert.assertNotNull(output);
    Assert.assertTrue("script does not contain body:" + innerScript, output.contains(innerScript));
    Assert.assertTrue("script does not have start <![CDATA[ ", output.contains(CommentUtils.INLINE_SCRIPT_COMMENT + CommentUtils.CDATA_SIMPLE_START));
    Assert.assertTrue("script does not have end ]]> ", output.contains(CommentUtils.INLINE_SCRIPT_COMMENT + CommentUtils.CDATA_SIMPLE_END));
}
Also used : HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)

Example 5 with HtmlResponseWriterImpl

use of org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl in project myfaces by apache.

the class HtmlResponseWriterImplTest method testScriptOnHtmlUTF8AndScriptXhmlComments.

public void testScriptOnHtmlUTF8AndScriptXhmlComments() throws IOException {
    _writer = new HtmlResponseWriterImpl(_stringWriter, "text/html", "UTF-8", true);
    String innerScript = "document.write('HELLO');";
    _writer.startDocument();
    _writer.startElement(HTML.SCRIPT_ELEM, null);
    _writer.write(innerScript);
    _writer.endElement(HTML.SCRIPT_ELEM);
    _writer.endDocument();
    String output = _stringWriter.toString();
    Assert.assertNotNull(output);
    Assert.assertTrue("script does not contain body:" + innerScript, output.contains(innerScript));
    Assert.assertTrue("script does not have start comment <!-- ", output.contains(CommentUtils.COMMENT_SIMPLE_START));
    Assert.assertTrue("script does not have end comment --> ", output.contains("//" + CommentUtils.COMMENT_SIMPLE_END));
}
Also used : HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)

Aggregations

HtmlResponseWriterImpl (org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)29 StringWriter (java.io.StringWriter)18 Test (org.junit.Test)17 MyfacesConfig (org.apache.myfaces.config.MyfacesConfig)9 HtmlRenderKitImpl (org.apache.myfaces.renderkit.html.HtmlRenderKitImpl)9 UIViewRoot (jakarta.faces.component.UIViewRoot)8 UIComponent (jakarta.faces.component.UIComponent)7 ResponseWriter (jakarta.faces.context.ResponseWriter)7 HtmlRenderedAttr (org.apache.myfaces.test.utils.HtmlRenderedAttr)6 UIInput (jakarta.faces.component.UIInput)2 NavigationCase (jakarta.faces.application.NavigationCase)1 UIViewParameter (jakarta.faces.component.UIViewParameter)1 ViewMetadata (jakarta.faces.view.ViewMetadata)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FastWriter (org.apache.myfaces.util.lang.FastWriter)1 HelloWorld (org.apache.myfaces.view.facelets.bean.HelloWorld)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1