velocity

16:53:54.401 INFO  jd.cli.Main - Decompiling velocity.jar
package org.apache.velocity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.List;
import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapterImpl;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.loader.ResourceLoader;

public class Template
  extends Resource
{
  private VelocityException errorCondition = null;
  
  public Template()
  {
    setType(1);
  }
  
  public boolean process()
    throws ResourceNotFoundException, ParseErrorException, IOException
  {
    data = null;
    InputStream is = null;
    errorCondition = null;
    try
    {
      is = resourceLoader.getResourceStream(name);
    }
    catch (ResourceNotFoundException rnfe)
    {
      errorCondition = rnfe;
      throw rnfe;
    }
    if (is != null) {
      try
      {
        BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding));
        data = rsvc.parse(br, name);
        initDocument();
        return true;
      }
      catch (UnsupportedEncodingException uce)
      {
        String msg = "Template.process : Unsupported input encoding : " + encoding + " for template " + name;
        
        errorCondition = new ParseErrorException(msg);
        throw errorCondition;
      }
      catch (ParseException pex)
      {
        errorCondition = new ParseErrorException(pex);
        throw errorCondition;
      }
      catch (TemplateInitException pex)
      {
        errorCondition = new ParseErrorException(pex);
        throw errorCondition;
      }
      catch (RuntimeException e)
      {
        throw new RuntimeException("Exception thrown processing Template " + getName(), e);
      }
      finally
      {
        is.close();
      }
    }
    errorCondition = new ResourceNotFoundException("Unknown resource error for resource " + name);
    throw errorCondition;
  }
  
  public void initDocument()
    throws TemplateInitException
  {
    InternalContextAdapterImpl ica = new InternalContextAdapterImpl(new VelocityContext());
    try
    {
      ica.pushCurrentTemplateName(name);
      ica.setCurrentResource(this);
      
      ((SimpleNode)data).init(ica, rsvc);
    }
    finally
    {
      ica.popCurrentTemplateName();
      ica.setCurrentResource(null);
    }
  }
  
  public void merge(Context context, Writer writer)
    throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException
  {
    merge(context, writer, null);
  }
  
  public void merge(Context context, Writer writer, List macroLibraries)
    throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException
  {
    if (errorCondition != null) {
      throw errorCondition;
    }
    if (data != null)
    {
      InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);
      
      ica.setMacroLibraries(macroLibraries);
      if (macroLibraries != null) {
        for (int i = 0; i < macroLibraries.size(); i++) {
          try
          {
            rsvc.getTemplate((String)macroLibraries.get(i));
          }
          catch (ResourceNotFoundException re)
          {
            rsvc.getLog().error("template.merge(): cannot find template " + (String)macroLibraries.get(i));
            
            throw re;
          }
          catch (ParseErrorException pe)
          {
            rsvc.getLog().error("template.merge(): syntax error in template " + (String)macroLibraries.get(i) + ".");
            
            throw pe;
          }
          catch (Exception e)
          {
            throw new RuntimeException("Template.merge(): parse failed in template  " + (String)macroLibraries.get(i) + ".", e);
          }
        }
      }
      try
      {
        ica.pushCurrentTemplateName(name);
        ica.setCurrentResource(this);
        
        ((SimpleNode)data).render(ica, writer);
      }
      finally
      {
        ica.popCurrentTemplateName();
        ica.setCurrentResource(null);
      }
    }
    else
    {
      String msg = "Template.merge() failure. The document is null, most likely due to parsing error.";
      
      throw new RuntimeException(msg);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.Template
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.velocity.context.AbstractContext;
import org.apache.velocity.context.Context;

public class VelocityContext
  extends AbstractContext
  implements Cloneable
{
  private static final long serialVersionUID = 9033846851064645037L;
  private Map context = null;
  
  public VelocityContext()
  {
    this(null, null);
  }
  
  public VelocityContext(Map context)
  {
    this(context, null);
  }
  
  public VelocityContext(Context innerContext)
  {
    this(null, innerContext);
  }
  
  public VelocityContext(Map context, Context innerContext)
  {
    super(innerContext);
    this.context = (context == null ? new HashMap() : context);
  }
  
  public Object internalGet(String key)
  {
    return context.get(key);
  }
  
  public Object internalPut(String key, Object value)
  {
    return context.put(key, value);
  }
  
  public boolean internalContainsKey(Object key)
  {
    return context.containsKey(key);
  }
  
  public Object[] internalGetKeys()
  {
    return context.keySet().toArray();
  }
  
  public Object internalRemove(Object key)
  {
    return context.remove(key);
  }
  
  public Object clone()
  {
    VelocityContext clone = null;
    try
    {
      clone = (VelocityContext)super.clone();
      context = new HashMap(context);
    }
    catch (CloneNotSupportedException ignored) {}
    return clone;
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.VelocityContext
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import com.werken.xpath.XPath;
import java.util.List;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class AnakiaElement
  extends Element
{
  private static final long serialVersionUID = 8429597252274491314L;
  private static final XMLOutputter DEFAULT_OUTPUTTER = new XMLOutputter();
  
  static
  {
    DEFAULT_OUTPUTTER.getFormat().setLineSeparator(System.getProperty("line.separator"));
  }
  
  public AnakiaElement(String name, Namespace namespace)
  {
    super(name, namespace);
  }
  
  public AnakiaElement(String name)
  {
    super(name);
  }
  
  public AnakiaElement(String name, String uri)
  {
    super(name, uri);
  }
  
  public AnakiaElement(String name, String prefix, String uri)
  {
    super(name, prefix, uri);
  }
  
  public NodeList selectNodes(String xpathExpression)
  {
    return new NodeList(XPathCache.getXPath(xpathExpression).applyTo(this), false);
  }
  
  public String toString()
  {
    return DEFAULT_OUTPUTTER.outputString(this);
  }
  
  public List getContent()
  {
    return new NodeList(super.getContent(), false);
  }
  
  public List getChildren()
  {
    return new NodeList(super.getChildren(), false);
  }
  
  public List getChildren(String name)
  {
    return new NodeList(super.getChildren(name));
  }
  
  public List getChildren(String name, Namespace ns)
  {
    return new NodeList(super.getChildren(name, ns));
  }
  
  public List getAttributes()
  {
    return new NodeList(super.getAttributes());
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.AnakiaElement
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import org.jdom.DefaultJDOMFactory;
import org.jdom.Element;
import org.jdom.Namespace;

public class AnakiaJDOMFactory
  extends DefaultJDOMFactory
{
  public Element element(String name, Namespace namespace)
  {
    return new AnakiaElement(name, namespace);
  }
  
  public Element element(String name)
  {
    return new AnakiaElement(name);
  }
  
  public Element element(String name, String uri)
  {
    return new AnakiaElement(name, uri);
  }
  
  public Element element(String name, String prefix, String uri)
  {
    return new AnakiaElement(name, prefix, uri);
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.AnakiaJDOMFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import java.io.File;
import org.apache.tools.ant.BuildException;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;

public class AnakiaTask$Context
{
  private String name;
  private Document contextDoc = null;
  private String file;
  private final AnakiaTask this$0;
  
  public AnakiaTask$Context(AnakiaTask this$0) {}
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    if ((name.equals("relativePath")) || (name.equals("treeWalk")) || (name.equals("xpath")) || (name.equals("escape")) || (name.equals("date")) || (name.equals("project"))) {
      throw new IllegalArgumentException("Context name '" + name + "' is reserved by Anakia");
    }
    this.name = name;
  }
  
  public void setFile(String file)
  {
    this.file = file;
  }
  
  public long getLastModified()
  {
    return new File(this$0.baseDir, file).lastModified();
  }
  
  public Document getContextDocument()
  {
    if (contextDoc == null)
    {
      File contextFile = new File(this$0.baseDir, file);
      try
      {
        contextDoc = this$0.builder.build(contextFile);
      }
      catch (Exception e)
      {
        throw new BuildException(e);
      }
    }
    return contextDoc;
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.AnakiaTask.Context
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Writer;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.util.StringUtils;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.xml.sax.SAXParseException;

public class AnakiaTask
  extends MatchingTask
{
  SAXBuilder builder;
  private File destDir = null;
  File baseDir = null;
  private String style = null;
  private long styleSheetLastModified = 0L;
  private String projectAttribute = null;
  private File projectFile = null;
  private long projectFileLastModified = 0L;
  private boolean lastModifiedCheck = true;
  private String extension = ".html";
  private String templatePath = null;
  private File velocityPropertiesFile = null;
  private VelocityEngine ve = new VelocityEngine();
  private List contexts = new LinkedList();
  
  public AnakiaTask()
  {
    builder = new SAXBuilder();
    builder.setFactory(new AnakiaJDOMFactory());
  }
  
  public void setBasedir(File dir)
  {
    baseDir = dir;
  }
  
  public void setDestdir(File dir)
  {
    destDir = dir;
  }
  
  public void setExtension(String extension)
  {
    this.extension = extension;
  }
  
  public void setStyle(String style)
  {
    this.style = style;
  }
  
  public void setProjectFile(String projectAttribute)
  {
    this.projectAttribute = projectAttribute;
  }
  
  public void setTemplatePath(File templatePath)
  {
    try
    {
      this.templatePath = templatePath.getCanonicalPath();
    }
    catch (IOException ioe)
    {
      throw new BuildException(ioe);
    }
  }
  
  public void setVelocityPropertiesFile(File velocityPropertiesFile)
  {
    this.velocityPropertiesFile = velocityPropertiesFile;
  }
  
  public void setLastModifiedCheck(String lastmod)
  {
    if ((lastmod.equalsIgnoreCase("false")) || (lastmod.equalsIgnoreCase("no")) || (lastmod.equalsIgnoreCase("off"))) {
      lastModifiedCheck = false;
    }
  }
  
  public void execute()
    throws BuildException
  {
    if (baseDir == null) {
      baseDir = project.resolveFile(".");
    }
    if (destDir == null)
    {
      String msg = "destdir attribute must be set!";
      throw new BuildException(msg);
    }
    if (style == null) {
      throw new BuildException("style attribute must be set!");
    }
    if (velocityPropertiesFile == null) {
      velocityPropertiesFile = new File("velocity.properties");
    }
    if ((!velocityPropertiesFile.exists()) && (templatePath == null)) {
      throw new BuildException("No template path and could not locate velocity.properties file: " + velocityPropertiesFile.getAbsolutePath());
    }
    log("Transforming into: " + destDir.getAbsolutePath(), 2);
    if ((projectAttribute != null) && (projectAttribute.length() > 0))
    {
      projectFile = new File(baseDir, projectAttribute);
      if (projectFile.exists())
      {
        projectFileLastModified = projectFile.lastModified();
      }
      else
      {
        log("Project file is defined, but could not be located: " + projectFile.getAbsolutePath(), 2);
        
        projectFile = null;
      }
    }
    Document projectDocument = null;
    try
    {
      if (velocityPropertiesFile.exists())
      {
        String file = velocityPropertiesFile.getAbsolutePath();
        ExtendedProperties config = new ExtendedProperties(file);
        ve.setExtendedProperties(config);
      }
      if ((templatePath != null) && (templatePath.length() > 0)) {
        ve.setProperty("file.resource.loader.path", templatePath);
      }
      ve.init();
      
      styleSheetLastModified = ve.getTemplate(style).getLastModified();
      if (projectFile != null) {
        projectDocument = builder.build(projectFile);
      }
    }
    catch (Exception e)
    {
      log("Error: " + e.toString(), 2);
      throw new BuildException(e);
    }
    DirectoryScanner scanner = getDirectoryScanner(baseDir);
    
    String[] list = scanner.getIncludedFiles();
    for (int i = 0; i < list.length; i++) {
      process(list[i], projectDocument);
    }
  }
  
  private void process(String xmlFile, Document projectDocument)
    throws BuildException
  {
    File outFile = null;
    File inFile = null;
    Writer writer = null;
    try
    {
      inFile = new File(baseDir, xmlFile);
      
      outFile = new File(destDir, xmlFile.substring(0, xmlFile.lastIndexOf('.')) + extension);
      if ((!lastModifiedCheck) || (inFile.lastModified() > outFile.lastModified()) || (styleSheetLastModified > outFile.lastModified()) || (projectFileLastModified > outFile.lastModified()) || (userContextsModifed(outFile.lastModified())))
      {
        ensureDirectoryFor(outFile);
        
        log("Input:  " + xmlFile, 2);
        
        Document root = builder.build(inFile);
        
        VelocityContext context = new VelocityContext();
        
        String encoding = (String)ve.getProperty("output.encoding");
        if ((encoding == null) || (encoding.length() == 0) || (encoding.equals("8859-1")) || (encoding.equals("8859_1"))) {
          encoding = "ISO-8859-1";
        }
        Format f = Format.getRawFormat();
        f.setEncoding(encoding);
        
        OutputWrapper ow = new OutputWrapper(f);
        
        context.put("root", root.getRootElement());
        context.put("xmlout", ow);
        context.put("relativePath", getRelativePath(xmlFile));
        context.put("treeWalk", new TreeWalker());
        context.put("xpath", new XPathTool());
        context.put("escape", new Escape());
        context.put("date", new Date());
        if (projectDocument != null) {
          context.put("project", projectDocument.getRootElement());
        }
        for (Iterator iter = contexts.iterator(); iter.hasNext();)
        {
          Context subContext = (Context)iter.next();
          if (subContext == null) {
            throw new BuildException("Found an undefined SubContext!");
          }
          if (subContext.getContextDocument() == null) {
            throw new BuildException("Could not build a subContext for " + subContext.getName());
          }
          context.put(subContext.getName(), subContext.getContextDocument().getRootElement());
        }
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), encoding));
        
        Template template = ve.getTemplate(style);
        template.merge(context, writer);
        
        log("Output: " + outFile, 2);
      }
    }
    catch (JDOMException e)
    {
      outFile.delete();
      if (e.getCause() != null)
      {
        Throwable rootCause = e.getCause();
        if ((rootCause instanceof SAXParseException))
        {
          System.out.println("");
          System.out.println("Error: " + rootCause.getMessage());
          System.out.println("       Line: " + ((SAXParseException)rootCause).getLineNumber() + " Column: " + ((SAXParseException)rootCause).getColumnNumber());
          
          System.out.println("");
        }
        else
        {
          rootCause.printStackTrace();
        }
      }
      else
      {
        e.printStackTrace();
      }
    }
    catch (Throwable e)
    {
      if (outFile != null) {
        outFile.delete();
      }
      e.printStackTrace();
    }
    finally
    {
      if (writer != null)
      {
        try
        {
          writer.flush();
        }
        catch (IOException e) {}
        try
        {
          writer.close();
        }
        catch (IOException e) {}
      }
    }
  }
  
  private String getRelativePath(String file)
  {
    if ((file == null) || (file.length() == 0)) {
      return "";
    }
    StringTokenizer st = new StringTokenizer(file, "/\\");
    
    int slashCount = st.countTokens() - 1;
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < slashCount; i++) {
      sb.append("../");
    }
    if (sb.toString().length() > 0) {
      return StringUtils.chop(sb.toString(), 1);
    }
    return ".";
  }
  
  private void ensureDirectoryFor(File targetFile)
    throws BuildException
  {
    File directory = new File(targetFile.getParent());
    if (!directory.exists()) {
      if (!directory.mkdirs()) {
        throw new BuildException("Unable to create directory: " + directory.getAbsolutePath());
      }
    }
  }
  
  private boolean userContextsModifed(long lastModified)
  {
    for (Iterator iter = contexts.iterator(); iter.hasNext();)
    {
      Context ctx = (Context)iter.next();
      if (ctx.getLastModified() > lastModified) {
        return true;
      }
    }
    return false;
  }
  
  public Context createContext()
  {
    Context context = new Context();
    contexts.add(context);
    return context;
  }
  
  public class Context
  {
    private String name;
    private Document contextDoc = null;
    private String file;
    
    public Context() {}
    
    public String getName()
    {
      return name;
    }
    
    public void setName(String name)
    {
      if ((name.equals("relativePath")) || (name.equals("treeWalk")) || (name.equals("xpath")) || (name.equals("escape")) || (name.equals("date")) || (name.equals("project"))) {
        throw new IllegalArgumentException("Context name '" + name + "' is reserved by Anakia");
      }
      this.name = name;
    }
    
    public void setFile(String file)
    {
      this.file = file;
    }
    
    public long getLastModified()
    {
      return new File(baseDir, file).lastModified();
    }
    
    public Document getContextDocument()
    {
      if (contextDoc == null)
      {
        File contextFile = new File(baseDir, file);
        try
        {
          contextDoc = builder.build(contextFile);
        }
        catch (Exception e)
        {
          throw new BuildException(e);
        }
      }
      return contextDoc;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.AnakiaTask
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

public class Escape
{
  public static final String LINE_SEPARATOR = System.getProperty("line.separator");
  
  public static final String getText(String st)
  {
    StringBuffer buff = new StringBuffer();
    char[] block = st.toCharArray();
    String stEntity = null;
    
    int i = 0;
    for (int last = 0; i < block.length; i++)
    {
      switch (block[i])
      {
      case '<': 
        stEntity = "&lt;";
        break;
      case '>': 
        stEntity = "&gt;";
        break;
      case '&': 
        stEntity = "&amp;";
        break;
      case '"': 
        stEntity = "&quot;";
        break;
      case '\n': 
        stEntity = LINE_SEPARATOR;
        break;
      }
      if (stEntity != null)
      {
        buff.append(block, last, i - last);
        buff.append(stEntity);
        stEntity = null;
        last = i + 1;
      }
    }
    if (last < block.length) {
      buff.append(block, last, i - last);
    }
    return buff.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.Escape
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

class NodeList$1 {}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.NodeList.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import java.io.IOException;
import java.io.Writer;
import org.jdom.Attribute;
import org.jdom.output.XMLOutputter;

final class NodeList$AttributeXMLOutputter
  extends XMLOutputter
{
  NodeList$AttributeXMLOutputter(NodeList.1 x0)
  {
    this();
  }
  
  public void output(Attribute attribute, Writer out)
    throws IOException
  {
    out.write(" ");
    out.write(attribute.getQualifiedName());
    out.write("=");
    
    out.write("\"");
    out.write(escapeAttributeEntities(attribute.getValue()));
    out.write("\"");
  }
  
  private NodeList$AttributeXMLOutputter() {}
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.NodeList.AttributeXMLOutputter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import com.werken.xpath.XPath;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.jdom.Attribute;
import org.jdom.CDATA;
import org.jdom.Comment;
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.EntityRef;
import org.jdom.ProcessingInstruction;
import org.jdom.Text;
import org.jdom.output.XMLOutputter;

public class NodeList
  implements List, Cloneable
{
  private static final AttributeXMLOutputter DEFAULT_OUTPUTTER = new AttributeXMLOutputter(null);
  private List nodes;
  
  public NodeList()
  {
    nodes = new ArrayList();
  }
  
  public NodeList(Document document)
  {
    this(document);
  }
  
  public NodeList(Element element)
  {
    this(element);
  }
  
  private NodeList(Object object)
  {
    if (object == null) {
      throw new IllegalArgumentException("Cannot construct NodeList with null.");
    }
    nodes = new ArrayList(1);
    nodes.add(object);
  }
  
  public NodeList(List nodes)
  {
    this(nodes, true);
  }
  
  public NodeList(List nodes, boolean copy)
  {
    if (nodes == null) {
      throw new IllegalArgumentException("Cannot initialize NodeList with null list");
    }
    this.nodes = (copy ? new ArrayList(nodes) : nodes);
  }
  
  public List getList()
  {
    return nodes;
  }
  
  public String toString()
  {
    if (nodes.isEmpty()) {
      return "";
    }
    StringWriter sw = new StringWriter(nodes.size() * 128);
    try
    {
      for (i = nodes.iterator(); i.hasNext();)
      {
        Object node = i.next();
        if ((node instanceof Element)) {
          DEFAULT_OUTPUTTER.output((Element)node, sw);
        } else if ((node instanceof Attribute)) {
          DEFAULT_OUTPUTTER.output((Attribute)node, sw);
        } else if ((node instanceof Text)) {
          DEFAULT_OUTPUTTER.output((Text)node, sw);
        } else if ((node instanceof Document)) {
          DEFAULT_OUTPUTTER.output((Document)node, sw);
        } else if ((node instanceof ProcessingInstruction)) {
          DEFAULT_OUTPUTTER.output((ProcessingInstruction)node, sw);
        } else if ((node instanceof Comment)) {
          DEFAULT_OUTPUTTER.output((Comment)node, sw);
        } else if ((node instanceof CDATA)) {
          DEFAULT_OUTPUTTER.output((CDATA)node, sw);
        } else if ((node instanceof DocType)) {
          DEFAULT_OUTPUTTER.output((DocType)node, sw);
        } else if ((node instanceof EntityRef)) {
          DEFAULT_OUTPUTTER.output((EntityRef)node, sw);
        } else {
          throw new IllegalArgumentException("Cannot process a " + (node == null ? "null node" : new StringBuffer().append("node of class ").append(node.getClass().getName()).toString()));
        }
      }
    }
    catch (IOException e)
    {
      Iterator i;
      throw new Error();
    }
    return sw.toString();
  }
  
  public Object clone()
    throws CloneNotSupportedException
  {
    NodeList clonedList = (NodeList)super.clone();
    clonedList.cloneNodes();
    return clonedList;
  }
  
  private void cloneNodes()
    throws CloneNotSupportedException
  {
    Class listClass = nodes.getClass();
    try
    {
      List clonedNodes = (List)listClass.newInstance();
      clonedNodes.addAll(nodes);
      nodes = clonedNodes;
    }
    catch (IllegalAccessException e)
    {
      throw new CloneNotSupportedException("Cannot clone NodeList since there is no accessible no-arg constructor on class " + listClass.getName());
    }
    catch (InstantiationException e)
    {
      throw new Error();
    }
  }
  
  public int hashCode()
  {
    return nodes.hashCode();
  }
  
  public boolean equals(Object o)
  {
    return (o instanceof NodeList) ? nodes.equals(nodes) : false;
  }
  
  public NodeList selectNodes(String xpathString)
  {
    return new NodeList(XPathCache.getXPath(xpathString).applyTo(nodes), false);
  }
  
  public boolean add(Object o)
  {
    return nodes.add(o);
  }
  
  public void add(int index, Object o)
  {
    nodes.add(index, o);
  }
  
  public boolean addAll(Collection c)
  {
    return nodes.addAll(c);
  }
  
  public boolean addAll(int index, Collection c)
  {
    return nodes.addAll(index, c);
  }
  
  public void clear()
  {
    nodes.clear();
  }
  
  public boolean contains(Object o)
  {
    return nodes.contains(o);
  }
  
  public boolean containsAll(Collection c)
  {
    return nodes.containsAll(c);
  }
  
  public Object get(int index)
  {
    return nodes.get(index);
  }
  
  public int indexOf(Object o)
  {
    return nodes.indexOf(o);
  }
  
  public boolean isEmpty()
  {
    return nodes.isEmpty();
  }
  
  public Iterator iterator()
  {
    return nodes.iterator();
  }
  
  public int lastIndexOf(Object o)
  {
    return nodes.lastIndexOf(o);
  }
  
  public ListIterator listIterator()
  {
    return nodes.listIterator();
  }
  
  public ListIterator listIterator(int index)
  {
    return nodes.listIterator(index);
  }
  
  public Object remove(int index)
  {
    return nodes.remove(index);
  }
  
  public boolean remove(Object o)
  {
    return nodes.remove(o);
  }
  
  public boolean removeAll(Collection c)
  {
    return nodes.removeAll(c);
  }
  
  public boolean retainAll(Collection c)
  {
    return nodes.retainAll(c);
  }
  
  public Object set(int index, Object o)
  {
    return nodes.set(index, o);
  }
  
  public int size()
  {
    return nodes.size();
  }
  
  public List subList(int fromIndex, int toIndex)
  {
    return new NodeList(nodes.subList(fromIndex, toIndex));
  }
  
  public Object[] toArray()
  {
    return nodes.toArray();
  }
  
  public Object[] toArray(Object[] a)
  {
    return nodes.toArray(a);
  }
  
  private static final class AttributeXMLOutputter
    extends XMLOutputter
  {
    AttributeXMLOutputter(NodeList.1 x0)
    {
      this();
    }
    
    public void output(Attribute attribute, Writer out)
      throws IOException
    {
      out.write(" ");
      out.write(attribute.getQualifiedName());
      out.write("=");
      
      out.write("\"");
      out.write(escapeAttributeEntities(attribute.getValue()));
      out.write("\"");
    }
    
    private AttributeXMLOutputter() {}
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.NodeList
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import java.io.IOException;
import java.io.StringWriter;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class OutputWrapper
  extends XMLOutputter
{
  public OutputWrapper() {}
  
  public OutputWrapper(Format f)
  {
    super(f);
  }
  
  public String outputString(Element element, boolean strip)
  {
    StringWriter buff = new StringWriter();
    try
    {
      outputElementContent(element, buff);
    }
    catch (IOException e) {}
    return buff.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.OutputWrapper
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;

public class TreeWalker
{
  public NodeList allElements(Element e)
  {
    ArrayList theElements = new ArrayList();
    treeWalk(e, theElements);
    return new NodeList(theElements, false);
  }
  
  private final void treeWalk(Element e, Collection theElements)
  {
    for (Iterator i = e.getChildren().iterator(); i.hasNext();)
    {
      Element child = (Element)i.next();
      theElements.add(child);
      treeWalk(child, theElements);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.TreeWalker
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import com.werken.xpath.XPath;
import java.util.Map;
import java.util.WeakHashMap;

class XPathCache
{
  private static final Map XPATH_CACHE = new WeakHashMap();
  
  static XPath getXPath(String xpathString)
  {
    XPath xpath = null;
    synchronized (XPATH_CACHE)
    {
      xpath = (XPath)XPATH_CACHE.get(xpathString);
      if (xpath == null)
      {
        xpath = new XPath(xpathString);
        XPATH_CACHE.put(xpathString, xpath);
      }
    }
    return xpath;
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.XPathCache
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.anakia;

import com.werken.xpath.XPath;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;

public class XPathTool
{
  public NodeList applyTo(String xpathSpec, Document doc)
  {
    return new NodeList(XPathCache.getXPath(xpathSpec).applyTo(doc), false);
  }
  
  public NodeList applyTo(String xpathSpec, Element elem)
  {
    return new NodeList(XPathCache.getXPath(xpathSpec).applyTo(elem), false);
  }
  
  public NodeList applyTo(String xpathSpec, List nodeSet)
  {
    return new NodeList(XPathCache.getXPath(xpathSpec).applyTo(nodeSet), false);
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.anakia.XPathTool
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.app;

import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import org.apache.velocity.util.ClassUtils;

public class FieldMethodizer
{
  private HashMap fieldHash = new HashMap();
  
  public FieldMethodizer() {}
  
  public FieldMethodizer(String s)
  {
    try
    {
      addObject(s);
    }
    catch (Exception e)
    {
      System.err.println("Could not add " + s + " for field methodizing: " + e.getMessage());
    }
  }
  
  public FieldMethodizer(Object o)
  {
    try
    {
      addObject(o);
    }
    catch (Exception e)
    {
      System.err.println("Could not add " + o + " for field methodizing: " + e.getMessage());
    }
  }
  
  public void addObject(String s)
    throws Exception
  {
    inspect(ClassUtils.getClass(s));
  }
  
  public void addObject(Object o)
    throws Exception
  {
    inspect(o.getClass());
  }
  
  public Object get(String fieldName)
  {
    Object value = null;
    try
    {
      Field f = (Field)fieldHash.get(fieldName);
      if (f != null) {
        value = f.get(null);
      }
    }
    catch (IllegalAccessException e)
    {
      System.err.println("IllegalAccessException while trying to access " + fieldName + ": " + e.getMessage());
    }
    return value;
  }
  
  private void inspect(Class clas)
  {
    Field[] fields = clas.getFields();
    for (int i = 0; i < fields.length; i++)
    {
      int mod = fields[i].getModifiers();
      if ((Modifier.isStatic(mod)) && (Modifier.isPublic(mod))) {
        fieldHash.put(fields[i].getName(), fields[i]);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.velocity.app.FieldMethodizer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.velocity.app;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.Properties;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeInstance;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.apache.velocity.runtime.log.Log;

public class Velocity
  implements RuntimeConstants
{
  public static void init()
    throws Exception
  {}
  
  public static void init(String propsFilename)
    throws Exception
  {
    RuntimeSingleton.init(propsFilename);
  }
  
  public static void init(Properties p)
    throws Exception
  {
    RuntimeSingleton.init(p);
  }
  
  public static void setProperty(String key, Object value)
  {
    RuntimeSingleton.setProperty(key, value);
  }
  
  public static void addProperty(String key, Object value)
  {
    RuntimeSingleton.addProperty(key, value);
  }
  
  public static void clearProperty(String key)
  {
    RuntimeSingleton.clearProperty(key);
  }
  
  public static void setExtendedProperties(ExtendedProperties configuration)
  {
    RuntimeSingleton.setConfiguration(configuration);
  }
  
  public static Object getProperty(String key)
  {
    return RuntimeSingleton.getProperty(key);
  }
  
  public static boolean evaluate(Context context, Writer out, String logTag, String instring)
    throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException
  {
    return RuntimeSingleton.getRuntimeServices().evaluate(context, out, logTag, instring);
  }
  
  /**
   * @deprecated
   */
  public static boolean evaluate(Context context, Writer writer, String logTag, InputStream instream)
    throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException
  {
    BufferedReader br = null;
    String encoding = null;
    try
    {
      encoding = RuntimeSingleton.getString("input.encoding", "ISO-8859-1");
      br = new BufferedReader(new InputStreamReader(instream, encoding));
    }
    catch (UnsupportedEncodingException uce)
    {
      String msg = "Unsupported input encoding : " + encoding + " for template " + logTag;
      
      throw new ParseErrorException(msg);
    }
    return evaluate(context, writer, logTag, br);
  }
  
  public static boolean evaluate(Context context, Writer writer, String logTag, Reader reader)
    throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException
  {
    return RuntimeSingleton.getRuntimeServices().evaluate(context, writer, logTag, reader);
  }
  
  public static boolean invokeVelocimacro(String vmName, String logTag, String[] params, Context context, Writer writer)
  {
    try
    {
      return RuntimeSingleton.getRuntimeServices().invokeVelocimacro(vmName, logTag, params, context, writer);
    }
    catch (IOException ioe)
    {
      String msg = "Velocity.invokeVelocimacro(" + vmName + ") failed";
      getLog().error(msg, ioe);
      throw new VelocityException(msg, ioe);
    }
  }
  
  /**
   * @deprecated
   */
  public static boolean mergeTemplate(String templateName, Context context, Writer writer)
    throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception
  {
    return mergeTemplate(templateName, RuntimeSingleton.getString("input.encoding", "ISO-8859-1"), context, writer);
  }
  
  public static boolean mergeTemplate(String templateName, String encoding, Context context, Writer writer)
    throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception
  {
    Template template = RuntimeSingleton.getTemplate(templateName, encoding);
    if (template == null)
    {
      String msg = "Velocity.mergeTemplate() was unable to load template '" + templateName + "'";
      
      getLog().error(msg);
      throw new ResourceNotFoundException(msg);
    }
    template.merge(context, writer);
    return true;
  }
  
  public static Template getTemplate(String name)
    throws ResourceNotFoundException, ParseErrorException, Exception
  {
    return RuntimeSingleton.getTemplate(name);
  }
  
  public static Template getTemplate(String name, String encoding)
    throws ResourceNotFoundException, ParseErrorException, Exception
  {
    return RuntimeSingleton.getTemplate(name, encoding);
  }
  
  public static boolean resourceExists(String resourceName)
  {
    return RuntimeSingleton.getLoaderNameForResource(resourceName) != null;
  }
  
  public static Log getLog()
  {
    return RuntimeSingleton.getLog();
  }
  
  /**
   * @deprecated
   */
  public static void warn(Object message)
  {
    getLog().warn(message);
  }
  
  /**
   * @deprecated
   */
  public static void info(Object message)
  {
    getLog().info(message);
  }
  
  /**
   * @deprecated
   */
  public static void error(Object message)
  {
    getLog().error(message);
  }
  
  /**
   * @deprecated
   */
  public static void debug(Object message)
  {
    getLog().debug(message);
  }
  
  public sta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd