Seems like the attachments didn't make it. Here's the source:


### DBTextSnippet.jwc

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification PUBLIC
  "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd";>
<!-- generated by Spindle, http://spindle.sourceforge.net -->
<component-specification class="se.pardeike.tapestry.Extras.DBTextSnippet.DBTextSnippet"
  allow-body="no" allow-informal-parameters="no">
<description>A piece of dynamic text fetched from a database</ description> <parameter name="textid" type="java.lang.String" property- name="snippetID" direction="in" required="yes">
    <description>ID of the text snippet</description>
  </parameter>
<parameter name="textloc" type="java.util.Locale" property- name="snippetLocale" direction="in" required="yes">
    <description>Locale of the text snippet</description>
  </parameter>
</component-specification>


### DBTextSnippet.java

package se.pardeike.tapestry.Extras.DBTextSnippet;

import java.lang.reflect.Method;
import java.util.Locale;

import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.PageRedirectException;

public abstract class DBTextSnippet extends AbstractComponent
{
  private static String snippetGetter = "getSnippetText";
  private static Method snippetGetterMethod;
  private static String snippetConverter = "TextEditSnippet2HTML";
  private static Method snippetConverterMethod;
  private static boolean hasSnippetConverter = true;

  public abstract void setSnippetID(String newID);
  public abstract String getSnippetID();

  public abstract void setSnippetLocale(Locale newLocale);
  public abstract Locale getSnippetLocale();

protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
  {
    IPage page = cycle.getPage();
    Object visitObject = page.getVisit();
    if(visitObject == null)
    {
      System.out.println("No visit object so far. Restarting page.");
      throw new PageRedirectException(page);
    }

    Class visitClass = visitObject.getClass();
    Object[] arguments = null;
    try
    {
Class[] parameterTypes = new Class[] {String.class, Locale.class};
      arguments = new Object[] {getSnippetID(), getSnippetLocale()};
      if(snippetGetterMethod == null)
snippetGetterMethod = visitClass.getMethod(snippetGetter, parameterTypes); String txt = (String)snippetGetterMethod.invoke(visitObject, arguments);
      if(txt != null)
      {
        if(hasSnippetConverter)
        {
          parameterTypes = new Class[] {String.class};
          arguments = new Object[] {txt};
          if(snippetConverterMethod == null)
          {
            Method[] methods = visitClass.getMethods();
            for(int i = 0; i < methods.length; i++)
              if(methods[i].getName().equals(snippetConverter))
              {
snippetConverterMethod = visitClass.getMethod (snippetConverter, parameterTypes);
                break;
              }
            if(snippetConverterMethod == null)
              hasSnippetConverter = false;
          }
          if(snippetConverterMethod != null)
txt = (String)snippetConverterMethod.invoke(visitObject, arguments);
        }
        writer.printRaw(txt);
      }
      else
writer.print("[" + getSnippetID() + "/" + getSnippetLocale() + " not found]");
    }
    catch(Exception e)
    {
      writer.print("page: " + page);
      writer.print("visitObject: " + visitObject);
      writer.print("visitClass: " + visitClass);
      writer.print("arguments[0]: " + arguments[0]);
      writer.print("arguments[1]: " + arguments[1]);
      writer.print("snippetGetterMethod: " + snippetGetterMethod);
      writer.printRaw("<hr>");

      writer.print("Component exception : " + e.getMessage());
      writer.printRaw("<hr>");
      StackTraceElement[] st = e.getStackTrace();
      for(int i = 0; i < st.length; i++)
      {
        writer.print(st[i].toString());
        writer.printRaw("<br>");
      }
    }
  }
}


### and inside the visit object, getSnippetText is defined as:

// called by component TextEdit to fetch txt from db
public String getSnippetText(String id, Locale locale)
{
  String localeStr = locale.getLanguage()+','+locale.getCountry();
  Texter snippet = textForID(id, localeStr, true);
  if(snippet != null)
    return snippet.getSnippetText().trim();
  return null;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to