<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FVelocity%2FVelocity_Event</id>
		<title>Java/Velocity/Velocity Event - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FVelocity%2FVelocity_Event"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Velocity/Velocity_Event&amp;action=history"/>
		<updated>2026-04-21T15:08:19Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Velocity/Velocity_Event&amp;diff=8481&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Velocity/Velocity_Event&amp;diff=8481&amp;oldid=prev"/>
				<updated>2010-06-01T07:07:19Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 07:07, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Velocity/Velocity_Event&amp;diff=8480&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Velocity/Velocity_Event&amp;diff=8480&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:46Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A simple demonstration of how the event handling features of the Velocity Servlet Engine are used ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright 2001,2004 The Apache Software Foundation.&lt;br /&gt;
 * &lt;br /&gt;
 * Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 * you may not use this file except in compliance with the License.&lt;br /&gt;
 * You may obtain a copy of the License at&lt;br /&gt;
 * &lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 * &lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.StringWriter;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import org.apache.velocity.app.Velocity;&lt;br /&gt;
import org.apache.velocity.VelocityContext;&lt;br /&gt;
import org.apache.velocity.exception.ParseErrorException;&lt;br /&gt;
import org.apache.velocity.exception.MethodInvocationException;&lt;br /&gt;
import org.apache.velocity.runtime.log.LogSystem;&lt;br /&gt;
import org.apache.velocity.runtime.RuntimeServices;&lt;br /&gt;
import org.apache.velocity.app.event.EventCartridge;&lt;br /&gt;
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;&lt;br /&gt;
import org.apache.velocity.app.event.MethodExceptionEventHandler;&lt;br /&gt;
import org.apache.velocity.app.event.NullSetEventHandler;&lt;br /&gt;
import org.apache.velocity.context.Context;&lt;br /&gt;
/**&lt;br /&gt;
 *   This class is a simple demonstration of how the event handling&lt;br /&gt;
 *   features of the Velocity Servlet Engine are used.  It uses a&lt;br /&gt;
 *   custom logger as well to check the log message stream&lt;br /&gt;
 *   when testing the NullSetEventHandler&lt;br /&gt;
 *&lt;br /&gt;
 * @author &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Event Handler: Exceptions  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.StringWriter;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
import org.apache.velocity.Template;&lt;br /&gt;
import org.apache.velocity.VelocityContext;&lt;br /&gt;
import org.apache.velocity.app.Velocity;&lt;br /&gt;
import org.apache.velocity.app.event.EventCartridge;&lt;br /&gt;
import org.apache.velocity.app.event.MethodExceptionEventHandler;&lt;br /&gt;
import org.apache.velocity.app.event.NullSetEventHandler;&lt;br /&gt;
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;&lt;br /&gt;
import org.apache.velocity.context.Context;&lt;br /&gt;
public class EventHandler implements ReferenceInsertionEventHandler,&lt;br /&gt;
    NullSetEventHandler, MethodExceptionEventHandler {&lt;br /&gt;
  public EventHandler(Context ctx) {&lt;br /&gt;
    EventCartridge ec = new EventCartridge();&lt;br /&gt;
    ec.addEventHandler(this);&lt;br /&gt;
    ec.attachToContext(ctx);&lt;br /&gt;
  }&lt;br /&gt;
  public Object referenceInsert(String reference, Object data) {&lt;br /&gt;
    System.out.println(&amp;quot;referenceInsert: &amp;quot; + reference + &amp;quot; data: &amp;quot; + data);&lt;br /&gt;
    return data;&lt;br /&gt;
  }&lt;br /&gt;
  public boolean shouldLogOnNullSet(String lhs, String rhs) {&lt;br /&gt;
    System.out.println(&amp;quot;shouldLogOnNullSet&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;lhs:&amp;quot; + lhs + &amp;quot; rhs:&amp;quot; + rhs);&lt;br /&gt;
      return true;&lt;br /&gt;
  }&lt;br /&gt;
  public Object methodException(Class cls, String method, Exception e)&lt;br /&gt;
      throws Exception {&lt;br /&gt;
    return &amp;quot;An &amp;quot; + e.getClass().getName() + &amp;quot; was thrown by the &amp;quot; + method&lt;br /&gt;
        + &amp;quot; method of the &amp;quot; + cls.getName() + &amp;quot; class [&amp;quot; + e.getMessage() + &amp;quot;]&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    Velocity.init();&lt;br /&gt;
    Template t = Velocity.getTemplate(&amp;quot;./src/eventHandler.vm&amp;quot;);&lt;br /&gt;
    Context ctx = new VelocityContext();&lt;br /&gt;
    ctx.put(&amp;quot;person&amp;quot;, &amp;quot;Joe&amp;quot;);&lt;br /&gt;
    ctx.put(&amp;quot;exception&amp;quot;, new ExceptionGenerator());&lt;br /&gt;
    EventHandler hdl = new EventHandler(ctx);&lt;br /&gt;
    Writer writer = new StringWriter();&lt;br /&gt;
    t.merge(ctx, writer);&lt;br /&gt;
    System.out.println(writer);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
import java.util.Random;&lt;br /&gt;
public class ExceptionGenerator {&lt;br /&gt;
  public String generate() throws Exception {&lt;br /&gt;
    Random rnd = new Random();&lt;br /&gt;
    int x = rnd.nextInt(5);&lt;br /&gt;
    if (x == 2) {&lt;br /&gt;
      throw new Exception(&amp;quot;Unlucky!&amp;quot;);&lt;br /&gt;
    } else {&lt;br /&gt;
      return &amp;quot;No Exception&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
-------------------------------------------------------------------------------------&lt;br /&gt;
#set($myNull1 = $validNull)&lt;br /&gt;
#set($myNull2 = $invalidNull)&lt;br /&gt;
This is $person &lt;br /&gt;
$exception.generate()&lt;br /&gt;
$exception.generate()&lt;br /&gt;
$exception.generate()&lt;br /&gt;
$exception.generate()&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>