public void initialize(RuntimeServices rsvc) { config = new Config(); config.maxActive = rsvc.getInt(Props.MAX_ACTIVE, Props.MAX_ACTIVE_DEFAULT); config.maxIdle = rsvc.getInt(Props.MAX_IDLE, Props.MAX_IDLE_DEFAULT); config.maxWait = rsvc.getInt(Props.MAX_WAIT, Props.MAX_WAIT_DEFAULT); config.timeBetweenEvictionRunsMillis = -1; // -1 to disable evictor thread. pool = new GenericObjectPool(new ParserFactory(rsvc), config); if (rsvc.getLog().isDebugEnabled()) { rsvc.getLog().debug("Created parser pool: " + this); } }
/** * init - generates the Introspector. As the setup code makes sure that the log gets set before * this is called, we can initialize the Introspector using the log object. */ public void init() { String[] badPackages = runtimeServices .getConfiguration() .getStringArray(RuntimeConstants.INTROSPECTOR_RESTRICT_PACKAGES); String[] badClasses = runtimeServices .getConfiguration() .getStringArray(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES); introspector = new SecureIntrospectorImpl(badClasses, badPackages, log); }
/** * Called automatically when event cartridge is initialized. * * @param rs instance of RuntimeServices */ public void setRuntimeServices(RuntimeServices rs) { nonescapeEqualsKey = StringUtils.trimToNull( rs.getConfiguration().getString("eventhandler.nonescape.html.equals")); nonescapeEndsWithKey = StringUtils.trimToNull( rs.getConfiguration().getString("eventhandler.nonescape.html.endsWith")); if (nonescapeEqualsKey == null || nonescapeEndsWithKey == null) { throw new SchoolWebException( "Check your velocity.properties for the value of eventhandler.nonescape.html.equals and eventhandler.nonescape.html.endsWith"); } }
/** * How this directive is to be initialized. * * @param rs * @param context * @param node * @throws TemplateInitException */ public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { rsvc = rs; String property = getScopeName() + '.' + RuntimeConstants.PROVIDE_SCOPE_CONTROL; this.provideScope = rsvc.getBoolean(property, provideScope); }
/** * Gets the method defined by <code>name</code> and <code>params</code> for the Class <code>c * </code>. * * @return The desired Method object. */ public Method getMethod(Class c, String name, Object[] params) throws Exception { if (c == null) { throw new Exception("Introspector.getMethod(): Class method key was null: " + name); } ClassMap classMap = null; synchronized (classMethodMaps) { classMap = (ClassMap) classMethodMaps.get(c); /* * if we don't have this, check to see if we have it * by name. if so, then we have a classloader change * so dump our caches. */ if (classMap == null) { if (cachedClassNames.contains(c.getName())) { /* * we have a map for a class with same name, but not * this class we are looking at. This implies a * classloader change, so dump */ clearCache(); rsvc.info(CACHEDUMP_MSG); } classMap = createClassMap(c); } } return classMap.findMethod(name, params); }
/** * Chseck to see if included file exists, and display "not found" page if it doesn't. If "not * found" page does not exist, log an error and return null. * * @param includeResourcePath * @param currentResourcePath * @param directiveName * @return message. */ public String includeEvent( String includeResourcePath, String currentResourcePath, String directiveName) { /** check to see if page exists */ boolean exists = (rs.getLoaderNameForResource(includeResourcePath) != null); if (!exists) { context.put("missingResource", includeResourcePath); if (rs.getLoaderNameForResource(notfound) != null) { return notfound; } else { /** can't find not found, so display nothing */ rs.getLog().error("Can't find include not found page: " + notfound); return null; } } else return includeResourcePath; }
@Before public void init() throws Exception { ExtendedProperties config = new ExtendedProperties(); RuntimeServices rsvc = new RuntimeInstance(); config.setProperty("path", "/templates"); config.setProperty("resource.loader", ""); rsvc.setConfiguration(config); rsvc.setProperty(RUNTIME_LOG_LOGSYSTEM, new Slf4jLogChute(log)); rsvc.setApplicationAttribute(SpringResourceLoaderAdapter.SPRING_RESOURCE_LOADER_KEY, factory); rsvc.init(); velocityLoader = new SpringResourceLoaderAdapter(); velocityLoader.commonInit(rsvc, config); velocityLoader.init(config); }
private String render(VelocityContext context, String template) { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); StringReader reader = new StringReader(template); SimpleNode node; try { node = runtimeServices.parse(reader, "Template name"); } catch (ParseException e) { throw new ServerError(e); } Template t = new Template(); t.setRuntimeServices(runtimeServices); t.setData(node); t.initDocument(); StringWriter writer = new StringWriter(); t.merge(context, writer); writer.write("\n\n\n\n\n"); return writer.toString(); }
/** ******** LogChute methods ************ */ public void init(RuntimeServices rs) { String name = (String) rs.getProperty(LOGCHUTE_COMMONS_LOG_NAME); if (name == null) { name = DEFAULT_LOG_NAME; } log = LogFactory.getLog(name); log(LogChute.DEBUG_ID, "CommonsLogLogChute name is '" + name + "'"); }
public void setRuntimeServices(RuntimeServices rs) { String[] temp = rs.getConfiguration().getStringArray(DirectOutputVariableConfiguration); if (temp != null && temp.length > 0) { for (String s : temp) { if (StringUtils.isNotBlank(s)) { directOutputVariables.add(s.trim()); } } } if (logger.isDebugEnabled()) { logger.debug("init DirectOutputVariable with:" + directOutputVariables); } }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); // 获取缓存提供者 Object _cache = rs.getProperty(CACHE_PROVIDER); if (_cache != null && _cache instanceof Cache) { cache = (MemcachedClient) _cache; } else { throw new TemplateInitException( CACHE_PROVIDER + " Cannot find the direcitive.cache.provider, or the direcitive.cache.provider object is incorrect.", "cache", 0, 0); } // 获取缓存提供者 Object _time = rs.getProperty(CACHE_TIME); if (_time != null) { time = Long.valueOf(_time.toString()); } }
public Object makeObject() throws Exception { Parser newParser = rsvc.createNewParser(); log.trace("Created parser: {}", newParser); return newParser; }
/** CTOR, wraps an ICA */ public VMContext(InternalContextAdapter inner, RuntimeServices rsvc) { localcontextscope = rsvc.getBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, false); wrappedContext = inner; innerContext = inner.getBaseContext(); }
/** * @see * org.apache.velocity.util.RuntimeServicesAware#setRuntimeServices(org.apache.velocity.runtime.RuntimeServices) */ public void setRuntimeServices(RuntimeServices rs) { this.rs = rs; notfound = StringUtils.nullTrim(rs.getString(PROPERTY_NOT_FOUND, DEFAULT_NOT_FOUND)); }
@Override public void commonInit(RuntimeServices rs, ExtendedProperties configuration) { super.commonInit(rs, configuration); this.templateEngine = (ITemplateEngine) rs.getProperty(VELOCITY_TEMPLATE_ENGINE_KEY); }