Added: incubator/adffaces/trunk/adf-faces/adf-faces-demo/src/main/webapp/components/outputDocument.jspx URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/adf-faces/adf-faces-demo/src/main/webapp/components/outputDocument.jspx?rev=423795&view=auto ============================================================================== --- incubator/adffaces/trunk/adf-faces/adf-faces-demo/src/main/webapp/components/outputDocument.jspx (added) +++ incubator/adffaces/trunk/adf-faces/adf-faces-demo/src/main/webapp/components/outputDocument.jspx Wed Jul 19 23:08:55 2006 @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?> +<!-- + Copyright 2006 The Apache Software Foundation. + + 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. +--> +<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:afh="http://myfaces.apache.org/adf/faces/html" + xmlns:af="http://myfaces.apache.org/adf/faces" > + <jsp:directive.page contentType="text/html;charset=utf-8"/> + <f:view> + <af:document title="OutputDocument Demo"> + <af:form> + <af:panelGroup layout="vertical"> + <f:facet name="separator"> + <af:objectSeparator /> + </f:facet> + <af:commandLink immediate="true" text="Component Guide" + action="guide"/> + <af:outputFormatted styleUsage="instruction" value="<b>simple outputDocument</b>"/> + <af:outputDocument binding="#{editor.component}" value="Text that is <b>bold</b> +and <i>italicized</i>"> + <f:facet name="title"><af:outputText value="Title"/></f:facet> + <f:facet name="separator"><af:objectSeparator/></f:facet> + </af:outputDocument> + + <jsp:directive.include file="editor.jspf" /> + + </af:panelGroup> + </af:form> + </af:document> + </f:view> +</jsp:root>
Added: incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/OutputDocumentRenderer.java URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/OutputDocumentRenderer.java?rev=423795&view=auto ============================================================================== --- incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/OutputDocumentRenderer.java (added) +++ incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/OutputDocumentRenderer.java Wed Jul 19 23:08:55 2006 @@ -0,0 +1,379 @@ +/* + * OutputDocumentRenderer.java + * + * Created 18-Jul-06 2:29:14 PM + * + * Copyright 2004-2006 The Apache Software Foundation. + * + * 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 org.apache.myfaces.adfinternal.renderkit.core.xhtml; + +import java.io.IOException; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; + +import org.apache.myfaces.adf.bean.FacesBean; +import org.apache.myfaces.adf.bean.PropertyKey; +import org.apache.myfaces.adf.component.core.output.CoreOutputDocument; +import org.apache.myfaces.adfinternal.renderkit.AdfRenderingContext; + +/** + * @author Simon Lessard, Fujitsu Consulting + */ +public class OutputDocumentRenderer extends ValueRenderer +{ + public OutputDocumentRenderer() + { + super(CoreOutputDocument.TYPE); + } + + /** + * [EMAIL PROTECTED] + */ + @Override + protected void encodeBegin( + FacesContext context, + AdfRenderingContext arc, + UIComponent comp, + FacesBean bean) throws IOException + { + ResponseWriter rw = context.getResponseWriter(); + rw.startElement(_ROOT_ELEMENT, comp); + + renderId(context, comp); + renderAllAttributes(context, arc, bean); + } + + /** + * [EMAIL PROTECTED] + */ + @Override + public void encodeEnd( + FacesContext context, + AdfRenderingContext arc, + UIComponent comp, + FacesBean bean) throws IOException + { + ResponseWriter rw = context.getResponseWriter(); + String value = getConvertedString(context, comp, bean); + + _renderTitle(context, arc, comp, bean); + + boolean firstParagraphRendered = false; + + UIComponent separator = getFacet(comp, CoreOutputDocument.SEPARATOR_FACET); + // Cache the separator existence in a variable in order to + // evaluate a potential rendered EL only once. + boolean hasSeparator = separator != null; + + int length = value.length(); + StringBuilder builder = new StringBuilder(length); + + for (int i = 0; i < length; i++) + { + char character = value.charAt(i); + if (_isLineFeed(character)) + { + // Paragraph change, but only if the last one was not empty + // That might happen often whe \n\r sequence is found + if (builder.length() > 0) + { + _renderParagraph(context, builder); + firstParagraphRendered = true; + } + } + else + { + if (builder.length() == 0) + { + // The first character that is not a line break found + // for the current paragraph, so start a new one + if (firstParagraphRendered && hasSeparator) + { + // If a separator was specified and the paragraph being rendered + // is not the first, render the separator + _renderSeparator(context, arc, separator, bean); + } + + _renderParagraphStart(context, arc, bean); + } + + builder.append(character); + } + } + + // There's more characters to print + if(builder.length() > 0) + { + _renderParagraph(context, builder); + } + + rw.endElement(_ROOT_ELEMENT); + } + + /** + * [EMAIL PROTECTED] + */ + @Override + protected void findTypeConstants(FacesBean.Type type) + { + super.findTypeConstants(type); + + _separatorClassKey = type.findKey(_SEPARATOR_CLASS_ATTRIBUTE); + _titleClassKey = type.findKey(_TITLE_CLASS_ATTRIBUTE); + } + + /** + * Gets the separator class of the rendered document. That class will be + * combined with the skin class, not override it. + * + * @param bean the property holder for the rendered document. + * + * @return the separator class for the rendered document or <code>null</code> + * if none was specified. + */ + protected String getSeparatorClass(FacesBean bean) + { + return toString(bean.getProperty(_separatorClassKey)); + } + + /** + * Gets the title class of the rendered document. That class will be + * combined with the skin class, not override it. + * + * @param bean the property holder for the rendered document. + * + * @return the title class for the rendered document or <code>null</code> + * if none was specified. + */ + protected String getTitleClass(FacesBean bean) + { + return toString(bean.getProperty(_titleClassKey)); + } + + /** + * [EMAIL PROTECTED] + */ + @Override + protected void renderStyleAttributes( + FacesContext context, + AdfRenderingContext arc, + FacesBean bean) throws IOException + { + renderStyleAttributes(context, arc, bean, _ROOT_SELECTOR); + } + + /** + * Gets the array of style classes to be used by the currently rendered + * document's facet. + * + * @param arc the current adf rendering context + * @param bean the property holder for the rendered document. + * @param key the property key of the style class property for the + * current facet being rendered. + * @param skinSelector the skin selector associated with the currently + * rendered facet. + * + * @return the array of style classes to add to the current facet. + */ + private String[] _getStyleClasses( + AdfRenderingContext arc, + FacesBean bean, + PropertyKey key, + String skinSelector) + { + // Pre-conditions that would cause NullPointerException if not met + assert bean != null; + + String specifiedClass = toString(bean.getProperty(key)); + if (specifiedClass != null) + { + return new String[] { specifiedClass, skinSelector }; + } + else + { + return new String[] { skinSelector }; + } + } + + /** + * Determiens if the specified character can be considered as a line feed + * for the purpose of separating the paragraphs + * + * @param character the character to evaluate + * + * @return <code>true</code> if the specified character can be considered a + * line feed, <code>false</code> otherwise. + */ + private boolean _isLineFeed(char character) + { + return character == _LINE_FEED || character == _CARRIAGE_RETURN; + } + + /** + * Renders the currently opened paragraph with the currently buffered content, + * escaping it if necessary, then close it and flush the buffer. + * + * @param rw the response writer used to put content in the underlying + * response. + * @param bean the property holder for the rendered document. + * @param builder the content buffer + * + * @throws IOException if a problem occurs while writing the content to the + * underlying response. + */ + private void _renderParagraph( + FacesContext context, + StringBuilder builder) throws IOException + { + // Pre-conditions that would cause NullPointerException if not met + assert builder != null; + assert context != null; + + renderFormattedText(context, builder.toString()); + + context.getResponseWriter().endElement(_PARAGRAPH_ELEMENT); + + // Clear buffer content + builder.delete(0, builder.length()); + } + + /** + * Renders the beginning of a paragraph. + * + * @param context the current Faces context + * @param arc the current ADF rendering context + * @param bean the property holder for the rendered document. + * + * @throws IOException if a problem occurs while writing the content to the + * underlying response. + */ + private void _renderParagraphStart( + FacesContext context, + AdfRenderingContext arc, + FacesBean bean) throws IOException + { + ResponseWriter rw = context.getResponseWriter(); + + rw.startElement(_PARAGRAPH_ELEMENT, null); + + renderStyleClasses(context, arc, new String[]{_PARAGRAPH_SELECTOR}); + } + + /** + * Renders a separator between 2 paragraphs. + * + * @param context the current Faces context + * @param arc the current ADF rendering context + * @param separator the component to render as a separator + * @param bean the property holder for the rendered document. + * + * @throws IOException if a problem occurs while writing the content to the + * underlying response. + */ + private void _renderSeparator( + FacesContext context, + AdfRenderingContext arc, + UIComponent separator, + FacesBean bean) throws IOException + { + ResponseWriter rw = context.getResponseWriter(); + + rw.startElement(_SEPARATOR_ELEMENT, null); + + String[] classes = _getStyleClasses(arc, + bean, + _separatorClassKey, + _SEPARATOR_SELECTOR); + + renderStyleClasses(context, arc, classes); + + encodeChild(context, separator); + + rw.endElement(_SEPARATOR_ELEMENT); + } + + /** + * Renders the title of the rendered document. + * + * @param context the current Faces context + * @param arc the current ADF rendering context + * @param comp the document component + * @param bean the property holder for the rendered document. + * + * @throws IOException if a problem occurs while writing the content to the + * underlying response. + */ + private void _renderTitle( + FacesContext context, + AdfRenderingContext arc, + UIComponent comp, + FacesBean bean) throws IOException + { + UIComponent title = getFacet(comp, CoreOutputDocument.TITLE_FACET); + if (title != null) + { + ResponseWriter rw = context.getResponseWriter(); + + rw.startElement(_TITLE_ELEMENT, null); + + String[] classes = _getStyleClasses(arc, + bean, + _titleClassKey, + _TITLE_SELECTOR); + + renderStyleClasses(context, arc, classes); + + encodeChild(context, title); + + rw.endElement(_TITLE_ELEMENT); + } + } + + // Line feed charaters + private static final char _LINE_FEED = '\n'; + private static final char _CARRIAGE_RETURN = '\r'; + + // Elements + private static final String _PARAGRAPH_ELEMENT = XhtmlConstants.PARAGRAPH_ELEMENT; + + private static final String _ROOT_ELEMENT = XhtmlConstants.DIV_ELEMENT; + + private static final String _SEPARATOR_ELEMENT = XhtmlConstants.DIV_ELEMENT; + + private static final String _TITLE_ELEMENT = XhtmlConstants.DIV_ELEMENT; + + // Property names + private static final String _SEPARATOR_CLASS_ATTRIBUTE = "separatorClass"; + + private static final String _TITLE_CLASS_ATTRIBUTE = "titleClass"; + + // Skin selectors + private static final String _PARAGRAPH_SELECTOR = XhtmlConstants.AF_OUTPUT_DOCUMENT_PARAGRAPH_STYLE_CLASS; + + private static final String _ROOT_SELECTOR = XhtmlConstants.AF_OUTPUT_DOCUMENT_STYLE_CLASS; + + private static final String _SEPARATOR_SELECTOR = XhtmlConstants.AF_OUTPUT_DOCUMENT_SEPARATOR_STYLE_CLASS; + + private static final String _TITLE_SELECTOR = XhtmlConstants.AF_OUTPUT_DOCUMENT_TITLE_STYLE_CLASS; + + // Property keys + private PropertyKey _separatorClassKey; + + private PropertyKey _titleClassKey; + +} \ No newline at end of file Modified: incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/XhtmlConstants.java URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/XhtmlConstants.java?rev=423795&r1=423794&r2=423795&view=diff ============================================================================== --- incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/XhtmlConstants.java (original) +++ incubator/adffaces/trunk/adf-faces/adf-faces-impl/src/main/java/org/apache/myfaces/adfinternal/renderkit/core/xhtml/XhtmlConstants.java Wed Jul 19 23:08:55 2006 @@ -1,67 +1,80 @@ -/* - * Copyright 2005,2006 The Apache Software Foundation. - * - * 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 org.apache.myfaces.adfinternal.renderkit.core.xhtml; - -public interface XhtmlConstants - extends org.apache.myfaces.adfinternal.ui.laf.base.xhtml.XhtmlLafConstants, - org.apache.myfaces.adfinternal.ui.UIConstants -{ - public static final String DEBUG_PARTIAL_RESPONSES_PARAM = - "org.apache.myfaces.adfinternal.DEBUG_PARTIAL_RESPONSES"; - - static public String STYLES_CACHE_DIRECTORY = "/adf/styles/cache/"; - static public String OUTPUT_MODE_PORTLET = FACET_PORTLET; - - // - // Copied from BaseDesktopConstants - // - - // =-=AEW Is this still a legit style class??? - public static final String HEADER_NEST_STYLE_CLASS = - "p_OraHeaderNest"; - // Header style classes - // if icon attribute is set, this is the style for it. - // I wouldn't normally have style in the name, but I don't want it to be - // confused with a icon. - public static final String AF_PANEL_HEADER_ICON_STYLE_CLASS = - "af|panelHeader::icon-style"; - - public static final String AF_PANEL_BOX_LIGHT_STYLE_CLASS = - "af|panelBox::light"; - public static final String AF_PANEL_BOX_MEDIUM_STYLE_CLASS = - "af|panelBox::medium"; - public static final String AF_PANEL_BOX_DARK_STYLE_CLASS = - "af|panelBox::dark"; - public static final String AF_PANEL_BOX_TRANSPARENT_STYLE_CLASS = - "af|panelBox::transparent"; - public static final String AF_PANEL_BOX_CONTENT_LIGHT_STYLE_CLASS = - "af|panelBox::content-light"; - public static final String AF_PANEL_BOX_CONTENT_MEDIUM_STYLE_CLASS = - "af|panelBox::content-medium"; - public static final String AF_PANEL_BOX_CONTENT_DARK_STYLE_CLASS = - "af|panelBox::content-dark"; - public static final String AF_PANEL_BOX_CONTENT_TRANSPARENT_STYLE_CLASS = - "af|panelBox::content-transparent"; - public static final String AF_PANEL_BOX_HEADER_STYLE_CLASS = - "af|panelBox::header"; - public static final String AF_PANEL_BOX_BODY_STYLE_CLASS = - "af|panelBox::body"; - - // =============PROPERTY NAMES================ - - public static final String AF_PANELHEADER_INDENT_CONTENT = - "af|panelHeader-ora-indent-content"; -} +/* + * Copyright 2005,2006 The Apache Software Foundation. + * + * 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 org.apache.myfaces.adfinternal.renderkit.core.xhtml; + +public interface XhtmlConstants + extends org.apache.myfaces.adfinternal.ui.laf.base.xhtml.XhtmlLafConstants, + org.apache.myfaces.adfinternal.ui.UIConstants +{ + public static final String DEBUG_PARTIAL_RESPONSES_PARAM = + "org.apache.myfaces.adfinternal.DEBUG_PARTIAL_RESPONSES"; + + static public String STYLES_CACHE_DIRECTORY = "/adf/styles/cache/"; + static public String OUTPUT_MODE_PORTLET = FACET_PORTLET; + + // + // Copied from BaseDesktopConstants + // + + // =-=AEW Is this still a legit style class??? + public static final String HEADER_NEST_STYLE_CLASS = + "p_OraHeaderNest"; + // Header style classes + // if icon attribute is set, this is the style for it. + // I wouldn't normally have style in the name, but I don't want it to be + // confused with a icon. + public static final String AF_PANEL_HEADER_ICON_STYLE_CLASS = + "af|panelHeader::icon-style"; + + public static final String AF_PANEL_BOX_LIGHT_STYLE_CLASS = + "af|panelBox::light"; + public static final String AF_PANEL_BOX_MEDIUM_STYLE_CLASS = + "af|panelBox::medium"; + public static final String AF_PANEL_BOX_DARK_STYLE_CLASS = + "af|panelBox::dark"; + public static final String AF_PANEL_BOX_TRANSPARENT_STYLE_CLASS = + "af|panelBox::transparent"; + public static final String AF_PANEL_BOX_CONTENT_LIGHT_STYLE_CLASS = + "af|panelBox::content-light"; + public static final String AF_PANEL_BOX_CONTENT_MEDIUM_STYLE_CLASS = + "af|panelBox::content-medium"; + public static final String AF_PANEL_BOX_CONTENT_DARK_STYLE_CLASS = + "af|panelBox::content-dark"; + public static final String AF_PANEL_BOX_CONTENT_TRANSPARENT_STYLE_CLASS = + "af|panelBox::content-transparent"; + public static final String AF_PANEL_BOX_HEADER_STYLE_CLASS = + "af|panelBox::header"; + public static final String AF_PANEL_BOX_BODY_STYLE_CLASS = + "af|panelBox::body"; + + // ============= Output Document ============== + public static final String AF_OUTPUT_DOCUMENT_STYLE_CLASS = + "af|outputDocument"; + public static final String AF_OUTPUT_DOCUMENT_PARAGRAPH_STYLE_CLASS = + "af|outputDocument::paragraph"; + public static final String AF_OUTPUT_DOCUMENT_SEPARATOR_STYLE_CLASS = + "af|outputDocument::separator"; + public static final String AF_OUTPUT_DOCUMENT_TITLE_STYLE_CLASS = + "af|outputDocument::title"; + + // =============PROPERTY NAMES================ + + public static final String AF_PANELHEADER_INDENT_CONTENT = + "af|panelHeader-ora-indent-content"; + + // ============= Html elements ================ + public static final String PARAGRAPH_ELEMENT = "p"; +}
