Roxen.git / server / modules / examples / JavaReflector.java

version» Context lines:

Roxen.git/server/modules/examples/JavaReflector.java:1: - import com.chilimoon.chilimoon.*; + import com.roxen.roxen.*;      import java.util.HashMap;   import java.lang.reflect.Modifier;   import java.lang.reflect.Field;   import java.lang.reflect.Method;   import java.lang.reflect.Constructor;         /* -  * This is an example ChiliMoon location module. +  * This is an example Roxen location module.    * Copyright (c) 2000 - 2001, Roxen IS    */         public class JavaReflector extends AbstractLocationModule   {       String modifierFont, typeFont, variableFont, methodFont, keywordFont;       public String queryName()    {    return "Java Class Reflector";    }       public String info()    {    return "A location module providing an HTML interface to Java Reflection.";    }    -  protected ChiliMoonResponse response(String title, String body) +  protected RoxenResponse response(String title, String body)    {    /*    * Package the content in an HTML page and return it with    * RXML parsing.    */    String page = "<html><head><title>"+title+"</title>\n"+    "<body bgcolor=\"white\" text=\"black\" link=\"#6699cc\" "+    "alink=\"red\" vlink=\"#6677cc\">\n"+    body+    "</body></html>\n";    -  return ChiliMoonLib.httpRXMLAnswer(page); +  return RoxenLib.httpRXMLAnswer(page);    }    -  public ChiliMoonResponse packageList(ChiliMoonRequest id) +  public RoxenResponse packageList(RoxenRequest id)    {    /*    * Default page, lists known packages.    */    StringBuffer page = new StringBuffer();    page.append("<h1>All packages</h1>\n<ul>\n");    Package[] packages = Package.getPackages();    for(int i=0; i<packages.length; i++) {    Package p = packages[i];    page.append(" <li>");    HashMap args = new HashMap();    args.put("href", queryLocation()+p.getName()); -  page.append(ChiliMoonLib.makeContainer("a", args, p.getName())); +  page.append(RoxenLib.makeContainer("a", args, p.getName()));    page.append("</li>\n");    }    page.append("</ul>\n");    /*    * Include a link to the reflection of this class, just    * to get people started...    */    page.append("Class of module: ");    HashMap args = new HashMap();    Class c = getClass();    args.put("href", queryLocation()+c.getName()); -  page.append(ChiliMoonLib.makeContainer("a", args, c.getName())); +  page.append(RoxenLib.makeContainer("a", args, c.getName()));    page.append("\n");    return response("Packages", page.toString());    }    -  public ChiliMoonResponse describePackage(Package p, ChiliMoonRequest id) +  public RoxenResponse describePackage(Package p, RoxenRequest id)    {    /*    * Unfortunately, there is no way to list all classes    * in a package. So this page only contains some manifest info.    */    StringBuffer page = new StringBuffer();    page.append("<h1>Package "+p.getName()+"</h1>\n");    page.append("<table border=1>\n<tr><td></td><th>Title</th>"+    "<th>Vendor</th><th>Version</th></tr>\n");    page.append("<tr><th>Specification</th><td>"); -  page.append(ChiliMoonLib.htmlEncodeString(p.getSpecificationTitle()+"")); +  page.append(RoxenLib.htmlEncodeString(p.getSpecificationTitle()+""));    page.append("</td><td>"); -  page.append(ChiliMoonLib.htmlEncodeString(p.getSpecificationVendor()+"")); +  page.append(RoxenLib.htmlEncodeString(p.getSpecificationVendor()+""));    page.append("</td><td>"); -  page.append(ChiliMoonLib.htmlEncodeString(p.getSpecificationVersion()+"")); +  page.append(RoxenLib.htmlEncodeString(p.getSpecificationVersion()+""));    page.append("</td></tr>\n<tr><th>Implementation</th><td>"); -  page.append(ChiliMoonLib.htmlEncodeString(p.getImplementationTitle()+"")); +  page.append(RoxenLib.htmlEncodeString(p.getImplementationTitle()+""));    page.append("</td><td>"); -  page.append(ChiliMoonLib.htmlEncodeString(p.getImplementationVendor()+"")); +  page.append(RoxenLib.htmlEncodeString(p.getImplementationVendor()+""));    page.append("</td><td>"); -  page.append(ChiliMoonLib.htmlEncodeString(p.getImplementationVersion()+"")); +  page.append(RoxenLib.htmlEncodeString(p.getImplementationVersion()+""));    page.append("</td></tr></table>\n");    return response("Package "+p.getName(), page.toString());    }       static protected void indentedLine(StringBuffer buf, String txt, int indent)    {    /* Append a line with indentation to a StringBuffer */    while(indent-->0) buf.append("&nbsp;");    buf.append(txt);    buf.append("<br>\n");
Roxen.git/server/modules/examples/JavaReflector.java:130:    /* Translate a type to clear text with hyperlinks where applicable */    if(c.isArray())    return classLink(c.getComponentType())+"[]";    String n = c.getName();    String t = typeFont+n.replace('$', '.')+"</font>";    if(c.isPrimitive())    return t;    int i = n.lastIndexOf('$');    HashMap args = new HashMap();    args.put("href", queryLocation()+(i<0? n : n.substring(0, i))); -  return ChiliMoonLib.makeContainer("a", args, t); +  return RoxenLib.makeContainer("a", args, t);    }       protected String classLink(Class[] c)    {    /* Translate a list of types to clear text with hyperlinks */    StringBuffer buf = new StringBuffer();    for(int i=0; i<c.length; i++) {    if(i>0)    buf.append(", ");    buf.append(classLink(c[i]));    }    return buf.toString();    }    -  protected void describe(StringBuffer page, Field f, ChiliMoonRequest id, +  protected void describe(StringBuffer page, Field f, RoxenRequest id,    int indent)    {    /* Append description of a field to a StringBuffer */    indentedLine(page, modifierNames(f.getModifiers())+    classLink(f.getType())+" "+variableFont+    f.getName()+"</font>;", indent);    }    -  protected void describe(StringBuffer page, Method m, ChiliMoonRequest id, +  protected void describe(StringBuffer page, Method m, RoxenRequest id,    int indent)    {    /* Append description of a method to a StringBuffer */    Class[] th = m.getExceptionTypes();    indentedLine(page, modifierNames(m.getModifiers())+    classLink(m.getReturnType())+" "+methodFont+    m.getName()+"</font>("+classLink(m.getParameterTypes())+    ")"+(th.length>0? " "+keywordFont+"throws</font> "+    classLink(th):"")+";", indent);    }    -  protected void describe(StringBuffer page, Constructor c, ChiliMoonRequest id, +  protected void describe(StringBuffer page, Constructor c, RoxenRequest id,    int indent)    {    /* Append description of a constructor to a StringBuffer */    Class[] th = c.getExceptionTypes();    indentedLine(page, modifierNames(c.getModifiers())+    methodFont+simpleClassName(c.getName())+    "</font>("+classLink(c.getParameterTypes())+    ")"+(th.length>0? " "+keywordFont+"throws</font> "+    classLink(th):"")+";", indent);    }    -  protected void describe(StringBuffer page, Class c, ChiliMoonRequest id, +  protected void describe(StringBuffer page, Class c, RoxenRequest id,    int indent)    {    /* Append description of a class or interface to a StringBuffer */    Class[] ifcs = c.getInterfaces();    if(c.isInterface())    indentedLine(page, modifierNames(c.getModifiers())+    keywordFont+"interface</font> "+    methodFont+simpleClassName(c.getName())+"</font> "+    (ifcs.length>0? keywordFont+"extends</font> "+    classLink(ifcs)+" ":"")+
Roxen.git/server/modules/examples/JavaReflector.java:227:    Constructor[] constructors = c.getDeclaredConstructors();    if(constructors.length>0)    indentedLine(page, "", indent);    for(int i=0; i<constructors.length; i++)    describe(page, constructors[i], id, indent);    indentedLine(page, "", indent);    indent -= 2;    indentedLine(page, "}", indent);    }    -  public ChiliMoonResponse describeClass(Class c, ChiliMoonRequest id) +  public RoxenResponse describeClass(Class c, RoxenRequest id)    {    /*    * Page describing a class or interface (including inner classes)    */    StringBuffer page = new StringBuffer();    String ci = (c.isInterface()? "Interface":"Class");    page.append("<h1>"+ci+" "+c.getName()+"</h1>\n");    page.append("\n<tt>\n");    Package p = c.getPackage();    if(p != null) {    page.append(keywordFont+"package</font> ");    HashMap args = new HashMap();    args.put("href", queryLocation()+p.getName()); -  page.append(ChiliMoonLib.makeContainer("a", args, +  page.append(RoxenLib.makeContainer("a", args,    modifierFont+p.getName()+"</font>"));    page.append(";<br><br>\n");    }    describe(page, c, id, 0);    page.append("</tt>\n");    return response(ci+" "+c.getName(), page.toString());    }    -  public ChiliMoonResponse findFile(String f, ChiliMoonRequest id) +  public RoxenResponse findFile(String f, RoxenRequest id)    {    /* If no class or package name is given, show a default page */    if("".equals(f))    return packageList(id);       try {       /* Is it a class/interface ? */       Class c = Class.forName(f);