org.apache.velocity.runtime.RuntimeSingleton类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中org.apache.velocity.runtime.RuntimeSingleton类的一些代码示例,展示了RuntimeSingleton类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RuntimeSingleton类的具体详情如下:
包路径:org.apache.velocity.runtime.RuntimeSingleton
类名称:RuntimeSingleton

RuntimeSingleton介绍

[英]This is the Runtime system for Velocity. It is the single access point for all functionality in Velocity. It adheres to the mediator pattern and is the only structure that developers need to be familiar with in order to get Velocity to perform. The Runtime will also cooperate with external systems like Turbine. Runtime properties can set and then the Runtime is initialized. Turbine for example knows where the templates are to be loaded from, and where the velocity log file should be placed. So in the case of Velocity cooperating with Turbine the code might look something like the following:

RuntimeSingleton.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath); 
RuntimeSingleton.setProperty(RuntimeConstants.RUNTIME_LOG, pathToVelocityLog); 
RuntimeSingleton.init();
----------------------------------------------------------------------- 
N O T E S  O N  R U N T I M E  I N I T I A L I Z A T I O N 
----------------------------------------------------------------------- 
RuntimeSingleton.init() 
If Runtime.init() is called by itself the Runtime will 
initialize with a set of default values. 
----------------------------------------------------------------------- 
RuntimeSingleton.init(String/Properties) 
In this case the default velocity properties are layed down 
first to provide a solid base, then any properties provided 
in the given properties object will override the corresponding 
default property. 
-----------------------------------------------------------------------

[中]这是Velocity的运行时系统。它是Velocity中所有功能的单一接入点。它遵循中介模式,是开发人员为了获得执行速度而需要熟悉的唯一结构。运行时还将与涡轮机等外部系统合作。可以设置运行时属性,然后初始化运行时。例如,Turbine知道从哪里加载模板,以及速度日志文件应该放在哪里。因此,在速度与涡轮机配合的情况下,代码可能如下所示:

RuntimeSingleton.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath); 
RuntimeSingleton.setProperty(RuntimeConstants.RUNTIME_LOG, pathToVelocityLog); 
RuntimeSingleton.init();
----------------------------------------------------------------------- 
N O T E S  O N  R U N T I M E  I N I T I A L I Z A T I O N 
----------------------------------------------------------------------- 
RuntimeSingleton.init() 
If Runtime.init() is called by itself the Runtime will 
initialize with a set of default values. 
----------------------------------------------------------------------- 
RuntimeSingleton.init(String/Properties) 
In this case the default velocity properties are layed down 
first to provide a solid base, then any properties provided 
in the given properties object will override the corresponding 
default property. 
-----------------------------------------------------------------------

代码示例

代码示例来源:origin: pippo-java/pippo

@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
  // create the velocity context
  VelocityContext context = createVelocityContext(model);
  // merge the template
  try {
    RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
    StringReader reader = new StringReader(templateContent);
    SimpleNode node = runtimeServices.parse(reader, "StringTemplate");
    Template template = new Template();
    template.setRuntimeServices(runtimeServices);
    template.setData(node);
    template.initDocument();
    template.merge(context, writer);
  } catch (Exception e) {
    throw new PippoRuntimeException(e);
  }
}

代码示例来源:origin: velocity/velocity-dep

/**
 *  Parse the input and return the root of the AST node structure.
 *
 * @param InputStream inputstream retrieved by a resource loader
 * @param String name of the template being parsed
 * @param dumpNamespace flag to dump the Velocimacro namespace for this template
 */
public static SimpleNode parse( Reader reader, String templateName, boolean dumpNamespace )
  throws ParseException
{
  return RuntimeSingleton.parse( reader, templateName, dumpNamespace );
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.velocity

/**
 * String property accessor method to hide the configuration implementation
 * @param key  property key
 * @return   value of key or null
 */
public static String getString(String key)
{
  return RuntimeSingleton.getString( key );
}

代码示例来源:origin: velocity/velocity-dep

nodeTree = RuntimeSingleton.parse( reader, logTag );
    nodeTree.init( ica, RuntimeSingleton.getRuntimeServices() );
    RuntimeSingleton.error("Velocity.evaluate() : init exception for tag = "
           + logTag + " : " + e );

代码示例来源:origin: velocity/velocity-dep

/**
 * Default constructor: sets up the Velocity
 * Runtime, creates the visitor for traversing
 * the node structure and then produces the
 * visual representation by the visitation.
 */
public TemplateNodeView(String template)
{
  try
  {
    RuntimeSingleton.init("velocity.properties");
    InputStreamReader isr = new InputStreamReader(
                  new FileInputStream(template),
                  RuntimeSingleton.getString(RuntimeSingleton.INPUT_ENCODING));
    BufferedReader br = new BufferedReader( isr );
                       document = RuntimeSingleton.parse( br, template);
    visitor = new NodeViewMode();
    visitor.setContext(null);
    visitor.setWriter(new PrintWriter(System.out));
    document.jjtAccept(visitor, null);
  }
  catch (Exception e)
  {
    System.out.println(e);
    e.printStackTrace();
  }
}

代码示例来源:origin: velocity/velocity-dep

/**
 *  Returns a <code>Template</code> from the Velocity
 *  resource management system.
 *
 * @param name The file name of the desired template.
 * @return     The template.
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException if template cannot be parsed due
 *          to syntax (or other) error.
 * @throws Exception if an error occurs in template initialization
 */
public static Template getTemplate(String name)
  throws ResourceNotFoundException, ParseErrorException, Exception
{
  return RuntimeSingleton.getTemplate( name );
}

代码示例来源:origin: velocity/velocity-dep

/**
 * Initialize the Velocity Runtime with a Properties
 * object.
 *
 * @param Properties
 */
public static void init(Properties p) throws Exception
{
  RuntimeSingleton.init(p);
}

代码示例来源:origin: org.apache.velocity/velocity-engine-core

/**
 * Clear a Velocity Runtime property.
 *
 * @param key of property to clear
 */
public static void clearProperty(String key)
{
  RuntimeSingleton.clearProperty(key);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.velocity

/**
 * Add a Velocity Runtime property.
 *
 * @param key The property key.
 * @param value The property value.
 */
public static void addProperty(String key, Object value)
{
  RuntimeSingleton.addProperty(key,value);
}

代码示例来源:origin: org.apache.velocity/velocity-engine-core

/**
 *  Returns a <code>Template</code> from the Velocity
 *  resource management system.
 *
 * @param name The file name of the desired template.
 * @return     The template.
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException if template cannot be parsed due
 *          to syntax (or other) error.
 */
public static Template getTemplate(String name)
  throws ResourceNotFoundException, ParseErrorException
{
  return RuntimeSingleton.getTemplate( name );
}

代码示例来源:origin: org.apache.velocity/com.springsource.org.apache.velocity

/**
 * Initialize the Velocity Runtime with the name of
 * ExtendedProperties object.
 *
 * @param configurationFile The name of a properties file.
 * @throws Exception When a problem occurs during init.
 */
public static void init(String configurationFile)
  throws Exception
{
  RuntimeSingleton.init( configurationFile );
}

代码示例来源:origin: velocity/velocity-dep

/**
 * Clear the values pertaining to a particular
 * property.
 *
 * @param String key of property to clear
 */
public static void clearProperty(String key)
{
  RuntimeSingleton.clearProperty( key );
}

代码示例来源:origin: org.apache.velocity/com.springsource.org.apache.velocity

/**
 * Add a Velocity Runtime property.
 *
 * @param key The property key.
 * @param value The property value.
 */
public static void addProperty(String key, Object value)
{
  RuntimeSingleton.addProperty(key,value);
}

代码示例来源:origin: org.apache.velocity/velocity-engine-core

/**
 * Invokes a currently registered Velocimacro with the params provided
 * and places the rendered stream into the writer.
 * <br>
 * Note : currently only accepts args to the VM if they are in the context.
 *
 * @param vmName name of Velocimacro to call
 * @param logTag string to be used for template name in case of error. if null,
 *               the vmName will be used
 * @param params keys for args used to invoke Velocimacro, in java format
 *               rather than VTL (eg  "foo" or "bar" rather than "$foo" or "$bar")
 * @param context Context object containing data/objects used for rendering.
 * @param writer  Writer for output stream
 * @return true if Velocimacro exists and successfully invoked, false otherwise.
 */
public static  boolean invokeVelocimacro( String vmName, String logTag,
                     String params[], Context context,
                     Writer writer )
{
  return RuntimeSingleton.getRuntimeServices()
    .invokeVelocimacro(vmName, logTag, params, context, writer);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.velocity

/**
 * Parse the input and return the root of the AST node structure.
 *
 * @see #parse(Reader, String)
 *
 * @param reader A reader returning the template input stream.
 * @param templateName name of the template being parsed
 * @param dumpNamespace flag to dump the Velocimacro namespace for this template.
 * @return The root node of an AST structure for the template input stream.
 * @throws ParseException When the input stream is not parsable.
 */
public static SimpleNode parse( Reader reader, String templateName, boolean dumpNamespace )
  throws ParseException
{
  return RuntimeSingleton.parse( reader, templateName, dumpNamespace );
}

代码示例来源:origin: com.samskivert/samskivert

/**
 * Chooses the output character encoding to be used as the value for the "charset=" portion of
 * the HTTP Content-Type header (and thus returned by
 * <code>response.getCharacterEncoding()</code>). Called by {@link #setContentType} if an
 * encoding isn't already specified by Content-Type.  By default, chooses the value of
 * RuntimeSingleton's <code>output.encoding</code> property.
 */
protected String chooseCharacterEncoding (HttpServletRequest request)
{
  return RuntimeSingleton.getString(
    RuntimeConstants.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.velocity

/**
 *  Returns a <code>Template</code> from the Velocity
 *  resource management system.
 *
 * @param name The file name of the desired template.
 * @return     The template.
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException if template cannot be parsed due
 *          to syntax (or other) error.
 */
public static Template getTemplate(String name)
  throws ResourceNotFoundException, ParseErrorException
{
  return RuntimeSingleton.getTemplate( name );
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.velocity

/**
 *  initialize the Velocity runtime engine, using default properties
 *  plus the properties in the passed in java.util.Properties object
 *
 *  @param p  Properties object containing initialization properties
 */
public static void init( Properties p )
{
  RuntimeSingleton.init( p );
}

代码示例来源:origin: org.apache.velocity/com.springsource.org.apache.velocity

/**
 * Clear a Velocity Runtime property.
 *
 * @param key of property to clear
 */
public static void clearProperty(String key)
{
  RuntimeSingleton.clearProperty(key);
}

代码示例来源:origin: org.apache.velocity/velocity-engine-core

/**
 * Add a Velocity Runtime property.
 *
 * @param key The property key.
 * @param value The property value.
 */
public static void addProperty(String key, Object value)
{
  RuntimeSingleton.addProperty(key, value);
}

相关文章