Java Code Examples for javax.faces.context.ResponseWriter#write()

The following examples show how to use javax.faces.context.ResponseWriter#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PopupRenderer.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * <p>Render end of ANCHOR.</p>
 *
 * @param context   FacesContext for the request we are processing
 * @param component UIComponent to be rendered
 *
 *  @param context   <code>FacesContext</code> for the current request
 *  @param component <code>UIComponent</code> being rendered
 *
 * @throws IOException if an input/output error occurs
 */
public void encodeEnd(FacesContext context, UIComponent component) throws
    IOException {
  if (!component.isRendered())
  {
    return;
  }

  ResponseWriter writer = context.getResponseWriter();
  String buttonSwitch = (String) RendererUtil.getAttribute(context, component, "useButton");
  boolean useButton = Boolean.getBoolean(
      RendererUtil.makeSwitchString(buttonSwitch, false, true, true, false, false, false));

  if (!useButton) {
    writer.write("</a>");
  }
}
 
Example 2
Source File: GroupBoxRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
	ResponseWriter writer = context.getResponseWriter();
	writer.write("<fieldset>");
	String title = (String) RendererUtil.getAttribute(context, component, "title");
	if (title != null)
	{
		writer.write("<legend>" + title + "</legend>\n");
	}
}
 
Example 3
Source File: SyllabusIfNotRender.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeEnd(FacesContext context, UIComponent component)
throws IOException
{
  ResponseWriter writer = context.getResponseWriter();
  
  String test = (String) component.getAttributes().get("test");
  if(test!=null)
    test = test.trim();

  if((test!=null) && (!test.equals("")))
  {
    writer.write("</div>");
  }  
}
 
Example 4
Source File: HideDivisionRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {

	if (!component.isRendered()) {
		return;
	}

	ResponseWriter writer = context.getResponseWriter();
	String jsfId = (String) RendererUtil.getAttribute(context, component, "id");
	String id = jsfId;

	if (component.getId() != null &&
			!component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
	{
		id = component.getClientId(context);
	}

	String title = (String) RendererUtil.getAttribute(context, component, "title");
	Object tmpFoldStr = RendererUtil.getAttribute(context, component, "hideByDefault");
	String key = (String)RendererUtil.getAttribute(context, component, "key");
	
	writer.write("<fieldset>");
	writer.write("<legend>");
	writer.write("<a role='button' data-toggle='collapse' aria-expanded='true' aria-target='" + id + "' href='#" + id + "' data-target=\"[id='" + id + "']\">" + title + "</a>");
	writer.write("</legend>");

	writer.write("<div class='collapse in' " +
		" id=\"" + id + "\">");
}
 
Example 5
Source File: InputRichTextRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void writeFilesArray(ResponseWriter writer, String arrayVar,
                               Object attchedFiles, MessageFormat format,
                               boolean includeLabel) throws IOException {
   StringWriter buffer = new StringWriter();

   char startChar = '[';
   char endChar = ']';

   if (LIST_ITEM_FORMAT_HTML.equals(format)) {
      startChar = '{';
      endChar = '}';
   }

   buffer.write("  var " + arrayVar + " = "+startChar+"\n");

   if (includeLabel) {
      buffer.write("\"select a file url to insert\" : \"\"");
   }

   if (attchedFiles instanceof Map) {
      buffer.write(outputFiles((Map)attchedFiles, format, !includeLabel));
   }
   else {
      buffer.write(outputFiles((List)attchedFiles, format, !includeLabel));
   }

   buffer.write(endChar + ";\n");
   String result = buffer.toString();
   writer.write(result);
}
 
Example 6
Source File: MultiColumnRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * encodeEnd no-op (debug comment line)
 *
 * @param context FacesContext
 * @param component UIComponent
 */

public void encodeBegin(FacesContext context,
                        UIComponent component) throws IOException
{
  ResponseWriter writer = context.getResponseWriter();
  writer.write("<!-- *** DEBUG MULTICOLUMN *** -->");
}
 
Example 7
Source File: ToolBarRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
    if(!component.isRendered()){
        //tool_bar tag is not to be rendered, return now
        return;
    }
    ResponseWriter writer = context.getResponseWriter();
    writer.write("<ul class=\"navIntraTool actionToolbar\">");
}
 
Example 8
Source File: GroupBoxRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
	ResponseWriter writer = context.getResponseWriter();
	writer.write("<fieldset>");
	String title = (String) RendererUtil.getAttribute(context, component, "title");
	if (title != null)
	{
		writer.write("<legend>" + title + "</legend>\n");
	}
}
 
Example 9
Source File: ToolBarRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
    if(!component.isRendered()){
        //tool_bar tag is not to be rendered, return now
        return;
    }
    ResponseWriter writer = context.getResponseWriter();
    writer.write("<ul class=\"navIntraTool actionToolbar\">");
}
 
Example 10
Source File: InputRichTextRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void writeAttachedFiles(FacesContext context, UIComponent component,
                                  String configVar, ResponseWriter writer, String toolbar) throws IOException {
   Object attchedFiles = RendererUtil.getAttribute(context,  component, "attachedFiles");
   if (attchedFiles != null && getSize(attchedFiles) > 0) {
      String arrayVar = configVar + "_Resources";

      writeFilesArray(writer, arrayVar, attchedFiles, LIST_ITEM_FORMAT_HTML, true);

      writer.write(  "sakaiRegisterResourceList(");
      writer.write(configVar + ",'" + INSERT_IMAGE_LOC + "'," + arrayVar);
      writer.write(");\n");

      writer.write("  " + configVar + ".toolbar = " + addToolbar(toolbar) + ";\n");
   }
}
 
Example 11
Source File: HelpSetDefaultActionComponent.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/** 
 * @see javax.faces.component.UIComponent#encodeEnd(javax.faces.context.FacesContext)
 */
public void encodeEnd(FacesContext context) throws IOException
{
  ResponseWriter writer = context.getResponseWriter();
  UIComponent actionComponent = super.getParent();
  String acionElement = actionComponent.getClientId(context);
  UIForm form = getForm(actionComponent);
  if (form != null)
  {

    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);

    String functionCode = "if (document.layers) \n"
        + "document.captureEvents(Event.KEYDOWN); \n"
        + "document.onkeydown =" + "function (evt) \n {"
        + " var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : "
        + "event.keyCode; \n"
        + "var eventTarget = evt ? evt.target : event.srcElement;  \n"
        + "var textField = eventTarget.type == 'text';  \n"
        + "if (keyCode == 13 && textField) { \n "
        + "document.getElementById('" + acionElement
        + "').click();return false; }  \n" + "else  return true; }";

    writer.write(functionCode);

    writer.endElement("script");
  }
}
 
Example 12
Source File: RendererUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @param context FacesContext for the request we are processing
 * @param writer ResponseWriter to be used
 * @param key key to use to look up the value in the request
 * @param path path to the file
 * @exception IOException if an input/output error occurs while rendering
 */
public static void writeExternalCSSDependencies(FacesContext context, 
      ResponseWriter writer, String key, String path) throws IOException
{
   HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
   String cssInclude = (String) req.getAttribute(key);
   
   if (cssInclude == null || cssInclude.length() == 0)
   {
      // include default stylesheet
      cssInclude = "<link href=\"" + path + "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
      req.setAttribute(key, cssInclude);
      writer.write(cssInclude);
   }
}
 
Example 13
Source File: PagerRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/** Output an HTML button */
private static void writeButton(ResponseWriter out, boolean render, String name, String label, boolean disabled, String title, String accesskey)
	throws IOException
{
	if (!render) return;
	
	//SAK-22812 wrap each button with a fieldset and legend, for accessibility
	out.startElement("fieldset", null);
	out.startElement("legend", null);
	out.writeText(title, null);
	out.endElement("legend");
	
	out.startElement("input", null);
	out.writeAttribute("type", "submit", null);
	out.writeAttribute("name", name, null);
	out.writeAttribute("value", label, null);
	// TODO: i18n
	if (!disabled)
	{
		out.writeAttribute("title", title, null);
		if (accesskey != null) out.writeAttribute("accesskey", accesskey, null);
		//out.writeAttribute("onclick", "javascript:this.form.submit(); return false;", null);
	}
	else
	{
		out.writeAttribute("disabled", "disabled", null);
	}
	out.endElement("input");
	out.endElement("fieldset");
	out.write("\n");
}
 
Example 14
Source File: JQ.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
protected static final void startInlineF(ResponseWriter rw, String cId) throws IOException {
    rw.startElement(SCRIPT, null);
    rw.writeAttribute("id", cId.concat(JS_SUFFIX), null);
    rw.writeAttribute("type", TEXT_JS, null);
    rw.write(START_F);
}
 
Example 15
Source File: ToolBarMessageRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
  ResponseWriter writer = context.getResponseWriter();
  writer.write("<h1>");
}
 
Example 16
Source File: ContextSensitiveTreeRender.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
  * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
  */
 public void encodeBegin(FacesContext context, UIComponent component)
     throws IOException
 {
   HttpServletRequest req = ((HttpServletRequest) context.getExternalContext().getRequest());
   String sakaiHeader = (String) req.getAttribute("sakai.html.head");

Locale locale = LocaleUtil.getLocale(context);
String lang = locale.getLanguage();
if (lang == null || lang.equals("")) lang = "en";

   String jsLibraryUrl = "../js";
   
   ResponseWriter writer = context.getResponseWriter();
   writer.write("<!DOCTYPE html>\n");
   writer.write("<html lang=\"" + lang + "\">");
   writer.write("<head>\n");            
   writer.write("<title>Help Index</title>\n");            
   writer.write("<script type=\"text/javascript\" src=\"" + jsLibraryUrl
       + "/csTree.js\"></script>\n");
   if (sakaiHeader != null) writer.write(sakaiHeader);
   writer.write("<link href=\"../css/csTree.css\" type=\"text/css\" rel=\"stylesheet\" />");
   //writer.write("<body onload='collapseAll([\"ol\"]); openBookMark();'>");
   writer.write("</head>\n");

   writer.write("<body class=\"helpIndexBody\">\n");
   writer.write("<ol id=\"root\">");
   UIData data = (UIData) component;
   Object value = data.getValue();

   // Get and validate the help id requested
   String helpDocId = req.getParameter("help");

   if (helpDocId != null) {
    Pattern p = Pattern.compile(HELP_DOC_REGEXP);
    Matcher m = p.matcher(helpDocId);
    
    if (!m.matches()) {
    	helpDocId = "unknown";
    }
   }

   // TODO: make use of the userRole
   String userRole = req.getParameter("userRole");
   
   Set categories = (Set) value;
   
   // filter to only include top-level categories
   for (Iterator i = categories.iterator(); i.hasNext();){
     Category c = (Category) i.next();      
     if (c.getParent() != null || "home".equalsIgnoreCase(c.getName())){
       i.remove();
     }
   }
   
   encodeRecursive(writer, categories, helpDocId);
   writer.write("</ol>");

   if (helpDocId != null)
   {
     writer.write("<script type=\"text/javascript\" src=\"" + jsLibraryUrl
         + "/search.js\"></script>\n");
   }
   writer.write("</body></html>");
 }
 
Example 17
Source File: RowGroupDataTableRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void renderCategoryRow(int rowNumber, int columns, UIData uiData, ResponseWriter writer, boolean firstCategory) throws IOException {
	FacesContext facesContext = FacesContext.getCurrentInstance();

	// Cast the uiData into our custom component
	RowGroupDataTable rowGroupDataTable;
	try {
		rowGroupDataTable = (RowGroupDataTable)uiData;
	} catch (ClassCastException cce) {
		log.warn(cce.getMessage());
		return;
	}

	// Get the current section
	RowGroupable rowGroupable;
	List list = (List)uiData.getValue();
	try {
		rowGroupable = (RowGroupable)list.get(rowNumber);
	} catch (IndexOutOfBoundsException ioobe) {
		log.warn(ioobe.getMessage());
		return;
	}

	// For Daisy's CM Home tool
	if (rowNumber == 0){
		// reset rowGroupDataTable.category
		rowGroupDataTable.category = null;
	}

	// Is this section different from the previous RowGroup?
	if( ! rowGroupable.getRowGroupId().equals(rowGroupDataTable.category)) {
		// Update the SectionTable's current RowGroup
		rowGroupDataTable.category = rowGroupable.getRowGroupId();

		// Render a table row for the RowGroup header
		beforeRow(facesContext, uiData);
		HtmlRendererUtils.writePrettyLineSeparator(facesContext);

        writer.startElement(HTML.TR_ELEM, uiData);
    	if(firstCategory) {
            writer.writeAttribute(HTML.CLASS_ATTR, FIRST_CATEGORY_HEADER_STYLE_CLASS, null);
    	} else {
            writer.writeAttribute(HTML.CLASS_ATTR, CATEGORY_HEADER_STYLE_CLASS, null);
        }
        
        Object rowId = uiData.getAttributes().get(JSFAttr.ROW_ID);

        if (rowId != null) {
            writer.writeAttribute(HTML.ID_ATTR, rowId.toString(), null);
        }

		// Render a single colspanned cell displaying the current RowGroup
		writer.startElement(HTML.TD_ELEM, uiData);
		writer.writeAttribute(HTML.COLSPAN_ATTR, columns, null);
		writer.write(JsfUtil.getLocalizedMessage("section_table_category_header", new String[] {rowGroupable.getRowGroupTitle()}));
		writer.endElement(HTML.TD_ELEM);

		renderRowEnd(facesContext, writer, uiData);
		afterRow(facesContext, uiData);
	}
}
 
Example 18
Source File: ProgressBarRenderer.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
* <p>Faces render output method .</p>
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

    if (!component.isRendered())
    {
      return;
     }

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

     if (component.getId() != null &&
       !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
     {
       clientId = component.getClientId(context);
     }

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

     Map attrMap = component.getAttributes();

     writer.write("\n");
     writer.write("\n<script language=\"javascript\">");
     writer.write("\n// Timer Bar - Version 1.0");
     writer.write(
         "\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
     writer.write(
         "\n  var loadedcolor='blue' ;            // PROGRESS BAR COLOR");
     writer.write(
         "\n  var unloadedcolor='white';         // COLOR OF UNLOADED AREA");
     writer.write(
         "\n  var bordercolor='white';            // COLOR OF THE BORDER");
     writer.write("\n  var barheight = 45; // HEIGHT OF PROGRESS BAR IN PIXELS");
     writer.write("\n  var barwidth = 300; // WIDTH OF THE BAR IN PIXELS");
     writer.write("\n  var waitTime = " + attrMap.get("wait") +
                  "; // NUMBER OF SECONDS FOR PROGRESSBAR");
     writer.write("\n  var loaded = 0; // TENTHS OF A SECOND ELAPSED");
     writer.write(
         "\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
     writer.write("\n");
     writer.write("\n  var action = function()");
     writer.write("\n {");
     writer.write("\n }");
     writer.write("\n</script>");
     writer.write("\n<script language=\"javascript\" src=\"" +
          "/" + RESOURCE_PATH + "/" + SCRIPT_PATH + "\"></script>");
     writer.write("\n");

     if (clientId != null) {
       writer.endElement("span");
     }
 }
 
Example 19
Source File: CarouselRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public void writeJSScript(FacesContext context, ResponseWriter w, UICarousel c) throws IOException {
    // Write the javascript method that starts the carousel
    
    // Get carousel id
    String userId  = c.getId();
    boolean isId   = HtmlUtil.isUserId(userId);
    
    if(isId) {
        // Write carousel activation method "carousel.carousel()" with given parameters
        String clientId = c.getClientId(context);

        // Get the carousel parameters
        // Get isAutoCycle property
        boolean isAuto = c.isAutoCycle();
        // Get slide interval value in milliseconds
        int interval    = c.getSlideInterval();
        String slideInt    = interval == 0 ? "" : Integer.toString(interval); //"" + (interval != 0 ? interval : (java.lang.Integer)getProperty(PROP_SLIDE_INTERVAL));
        // Get whether carousel is wrapped, paused on hover
        boolean wrapped = c.isWrapped();
        String pause = c.getPause();
        String isPause   = StringUtil.isEmpty(pause) ? "" : 
                           (StringUtil.equals(pause, "hover")  || // $NON-NLS-1$
                            StringUtil.equals(pause, "true")  // $NON-NLS-1$
                               ? "hover"  // $NON-NLS-1$
                               : pause);
        
        // write the script element
        w.startElement("script", c); // $NON-NLS-1$
        w.writeAttribute(TYPE, "text/javascript", null); // $NON-NLS-1$
        
        // Build the carousel function
        StringBuilder b = new StringBuilder();
        // Find the carousel element
        b.append("$(document).ready(function(){var carousel = x$("); // $NON-NLS-1$
        JSUtil.addSingleQuoteString(b, clientId);
        b.append(");");
        // Call the carousel method from bootstrap.js
        b.append("carousel.carousel({"); // $NON-NLS-1$
        if(isAuto) {
            if(StringUtil.isNotEmpty(slideInt)) {
                b.append("interval:"); // $NON-NLS-1$
                JSUtil.addString(b, slideInt);
                b.append(",");
            }
        }else{
            b.append("interval:"); // $NON-NLS-1$
            JSUtil.addBoolean(b, false);
            b.append(",");
        }
        if(!wrapped){
            b.append("wrap:"); // $NON-NLS-1$
            JSUtil.addBoolean(b, wrapped);
            b.append(",");
        }
        if(StringUtil.isNotEmpty(isPause)) {
            b.append("pause:"); // $NON-NLS-1$
            JSUtil.addSingleQuoteString(b, isPause);
        }
        b.append("});});");
        w.write(b.toString());
        w.endElement("script"); // $NON-NLS-1$
    }
}
 
Example 20
Source File: DocSectionRenderer.java    From sakai with Educational Community License v2.0 2 votes vote down vote up
/**
 * @param context FacesContext for the request we are processing
 * @param component UIComponent to be rendered
 * @exception IOException if an input/output error occurs while rendering
 * @exception NullPointerException if <code>context</code> or <code>component</code> is null
 */
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
	ResponseWriter writer = context.getResponseWriter();
	writer.write("</p>");
}