mirror of
https://gitee.com/jiniannet/jntemplate.git
synced 2025-12-06 10:58:59 +08:00
V1.4
This commit is contained in:
0
.tgitconfig
Normal file
0
.tgitconfig
Normal file
@@ -1,3 +1,18 @@
|
||||
Version 1.4 -
|
||||
==============================================
|
||||
- <20><><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ͨ<><CDA8><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>Դ<EFBFBD><D4B4>ļ<EFBFBD>,FTP,HTTP<54>ȶ<EFBFBD><C8B6>ַ<EFBFBD>ʽ<EFBFBD><CABD>;<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>foreach<63><68>ǩ<EFBFBD><C7A9>elseif<69><66>ǩ<EFBFBD><C7A9>д<EFBFBD><D0B4>(ԭд<D4AD><D0B4>ͬ<EFBFBD><CDAC>֧<EFBFBD><D6A7>)
|
||||
- foreach in ֧<>ּ<EFBFBD>д<EFBFBD><D0B4> for in
|
||||
- elseif ֧<>ּ<EFBFBD>д<EFBFBD><D0B4> elif
|
||||
- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
|
||||
- <20><><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>,ʹ<>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
- ȥ<><C8A5><EFBFBD><EFBFBD>һЩ<D2BB><D0A9>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>û<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
Version 1.3(1.3.3) -
|
||||
==============================================
|
||||
- <20><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>沨<EFBFBD><E6B2A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BUG
|
||||
- <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>V1.4<EFBFBD><EFBFBD>
|
||||
|
||||
Version 1.3(1.3.2) - 09/13/2017
|
||||
==============================================
|
||||
- <20><><EFBFBD><EFBFBD>.Net Core֧<65><D6A7>(1.1+)
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
///********************************************************************************
|
||||
// Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// ********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
|
||||
namespace JinianNet.JNTemplate.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// 简易内存缓存
|
||||
/// </summary>
|
||||
public class MemoryCache : ICache
|
||||
{
|
||||
private Dictionary<String, Object> dictionary;
|
||||
/// <summary>
|
||||
/// 内存缓存
|
||||
/// </summary>
|
||||
public MemoryCache()
|
||||
{
|
||||
this.dictionary = new Dictionary<String, Object>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前缓存数量
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return this.dictionary.Count; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加缓存
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void Set(String key, Object value)
|
||||
{
|
||||
this.dictionary[key] = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取键为key的缓存
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public object Get(String key)
|
||||
{
|
||||
Object value;
|
||||
if (this.dictionary.TryGetValue(key, out value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 移除键为key的缓存
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public object Remove(string key)
|
||||
{
|
||||
Object value = Get(key);
|
||||
this.dictionary.Remove(key);
|
||||
return value;
|
||||
}
|
||||
//namespace JinianNet.JNTemplate.Caching
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// 简易内存缓存
|
||||
// /// </summary>
|
||||
// public class MemoryCache : ICache
|
||||
// {
|
||||
// private Dictionary<String, Object> dictionary;
|
||||
// /// <summary>
|
||||
// /// 内存缓存
|
||||
// /// </summary>
|
||||
// public MemoryCache()
|
||||
// {
|
||||
// this.dictionary = new Dictionary<String, Object>();
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 当前缓存数量
|
||||
// /// </summary>
|
||||
// public int Count
|
||||
// {
|
||||
// get { return this.dictionary.Count; }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 添加缓存
|
||||
// /// </summary>
|
||||
// /// <param name="key"></param>
|
||||
// /// <param name="value"></param>
|
||||
// public void Set(String key, Object value)
|
||||
// {
|
||||
// this.dictionary[key] = value;
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 获取键为key的缓存
|
||||
// /// </summary>
|
||||
// /// <param name="key"></param>
|
||||
// /// <returns></returns>
|
||||
// public object Get(String key)
|
||||
// {
|
||||
// Object value;
|
||||
// if (this.dictionary.TryGetValue(key, out value))
|
||||
// {
|
||||
// return value;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 移除键为key的缓存
|
||||
// /// </summary>
|
||||
// /// <param name="key"></param>
|
||||
// /// <returns></returns>
|
||||
// public object Remove(string key)
|
||||
// {
|
||||
// Object value = Get(key);
|
||||
// this.dictionary.Remove(key);
|
||||
// return value;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Enumerator
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public System.Collections.IEnumerator GetEnumerator()
|
||||
{
|
||||
return this.dictionary.GetEnumerator();
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Enumerator
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public System.Collections.IEnumerator GetEnumerator()
|
||||
// {
|
||||
// return this.dictionary.GetEnumerator();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 释放非托管资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.dictionary.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 释放非托管资源
|
||||
// /// </summary>
|
||||
// public void Dispose()
|
||||
// {
|
||||
// this.dictionary.Clear();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符扫描器
|
||||
@@ -625,12 +625,22 @@ namespace JinianNet.JNTemplate.Common
|
||||
/// <returns></returns>
|
||||
public static Object Calculate(String x, String y, String value)
|
||||
{
|
||||
|
||||
StringComparison sc;
|
||||
if (Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
sc = StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
else
|
||||
{
|
||||
sc = StringComparison.Ordinal;
|
||||
}
|
||||
switch (value)
|
||||
{
|
||||
case "==":
|
||||
return x.Equals(y, Engine.ComparisonIgnoreCase);
|
||||
return x.Equals(y, sc);
|
||||
case "!=":
|
||||
return !x.Equals(y, Engine.ComparisonIgnoreCase);
|
||||
return !x.Equals(y, sc);
|
||||
case "+":
|
||||
return String.Concat(x, y);
|
||||
default:
|
||||
|
||||
@@ -49,9 +49,18 @@ namespace JinianNet.JNTemplate.Common
|
||||
/// <returns></returns>
|
||||
public static Boolean IsEqual(String x, String y)
|
||||
{
|
||||
StringComparison sc;
|
||||
if (Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
sc = StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
else
|
||||
{
|
||||
sc = StringComparison.Ordinal;
|
||||
}
|
||||
if (x == null || y == null)
|
||||
return x == y;
|
||||
return String.Equals(x, y, Engine.ComparisonIgnoreCase);
|
||||
return String.Equals(x, y, sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace JinianNet.JNTemplate.Configuration
|
||||
/// </summary>
|
||||
public class ConfigBase
|
||||
{
|
||||
private String[] _resourceDirectories;
|
||||
private Char _tagFlag;
|
||||
private String _tagPrefix;
|
||||
private String _tagSuffix;
|
||||
@@ -33,16 +32,6 @@ namespace JinianNet.JNTemplate.Configuration
|
||||
get { return this._charset; }
|
||||
set { this._charset = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public String[] ResourceDirectories
|
||||
{
|
||||
get { return this._resourceDirectories; }
|
||||
set { this._resourceDirectories = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标签前缀
|
||||
/// </summary>
|
||||
@@ -137,13 +126,13 @@ namespace JinianNet.JNTemplate.Configuration
|
||||
#else
|
||||
IEnumerable<PropertyInfo> pis = this.GetType().GetProperties();
|
||||
#endif
|
||||
#if NOTDNX
|
||||
#if NET20 || NET40
|
||||
Type type = typeof(VariableAttribute);
|
||||
#endif
|
||||
foreach (PropertyInfo pi in pis)
|
||||
{
|
||||
#if NOTDNX
|
||||
if( Attribute.IsDefined(pi, type))
|
||||
#if NET20 || NET40
|
||||
if (Attribute.IsDefined(pi, type))
|
||||
{
|
||||
dic[pi.Name] = (pi.GetValue(this, null) ?? string.Empty).ToString();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace JinianNet.JNTemplate.Configuration
|
||||
{
|
||||
EngineConfig conf = new EngineConfig();
|
||||
//conf.CachingProvider = "JinianNet.JNTemplate.Caching.MemoryCache";
|
||||
conf.ResourceDirectories = new String[0];
|
||||
conf.StripWhiteSpace = true;
|
||||
conf.TagFlag = '$';
|
||||
conf.TagPrefix = "${";
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
isNumberRegex = new Regex("[0-9]+", RegexOptions.Compiled);
|
||||
}
|
||||
|
||||
#region 获取属性或索引
|
||||
#region 获取属性或索引
|
||||
/// <summary>
|
||||
/// 获取属性或字段
|
||||
/// </summary>
|
||||
@@ -56,13 +56,13 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
{
|
||||
key = String.Concat("Dynamic.IL.GetPropertyOrField.", type.FullName, ".", propertyName);
|
||||
}
|
||||
Object result;
|
||||
if ((result = Engine.Cache.Get(key)) != null)
|
||||
{
|
||||
return (GetPropertyOrFieldDelegate)result;
|
||||
}
|
||||
//Object result;
|
||||
//if ((result = Engine.Cache.Get(key)) != null)
|
||||
//{
|
||||
// return (GetPropertyOrFieldDelegate)result;
|
||||
//}
|
||||
GetPropertyOrFieldDelegate gpf = CreateGetPropertyOrFieldProxy(type, value, propertyName);
|
||||
Engine.Cache.Set(key, gpf);
|
||||
//Engine.Cache.Set(key, gpf);
|
||||
return gpf;
|
||||
}
|
||||
private GetPropertyOrFieldDelegate CreateGetPropertyOrFieldProxy(Type type, Object value, String propertyName)
|
||||
@@ -96,7 +96,14 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
}
|
||||
il.Emit(OpCodes.Stloc_0);
|
||||
|
||||
if ((mi = type.GetMethod(String.Concat("get_", propertyName), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | Engine.BindIgnoreCase, null,
|
||||
BindingFlags bind = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
||||
|
||||
if (Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
bind = bind | BindingFlags.IgnoreCase;
|
||||
}
|
||||
|
||||
if ((mi = type.GetMethod(String.Concat("get_", propertyName), bind, null,
|
||||
Type.EmptyTypes,
|
||||
null)) != null)
|
||||
{
|
||||
@@ -104,7 +111,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
Call(type, il, mi);
|
||||
returnType = mi.ReturnType;
|
||||
}
|
||||
else if (isNumberRegex.Match(propertyName).Success && (mi = type.GetMethod("get_Item", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | Engine.BindIgnoreCase, null,
|
||||
else if (isNumberRegex.Match(propertyName).Success && (mi = type.GetMethod("get_Item", bind, null,
|
||||
new Type[] {
|
||||
typeof(int)
|
||||
},
|
||||
@@ -115,7 +122,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
Call(type, il, mi);
|
||||
returnType = mi.ReturnType;
|
||||
}
|
||||
else if ((mi = type.GetMethod("get_Item", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | Engine.BindIgnoreCase, null,
|
||||
else if ((mi = type.GetMethod("get_Item", bind, null,
|
||||
new Type[] {
|
||||
stringType
|
||||
},
|
||||
@@ -152,10 +159,10 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
il.Emit(OpCodes.Ret);
|
||||
return dynamicMethod.CreateDelegate(typeof(GetPropertyOrFieldDelegate)) as GetPropertyOrFieldDelegate;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
#region 执行方法
|
||||
#region 执行方法
|
||||
/// <summary>
|
||||
/// 执行方法
|
||||
/// </summary>
|
||||
@@ -198,38 +205,47 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
Dictionary<String, DynamicMethodInfo> itemDic = null;
|
||||
DynamicMethodInfo d;
|
||||
|
||||
if ((value = Engine.Cache.Get(key)) != null)
|
||||
//if ((value = Engine.Cache.Get(key)) != null)
|
||||
//{
|
||||
// dic = (Dictionary<Int32, Dictionary<String, DynamicMethodInfo>>)value;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
dic = new Dictionary<Int32, Dictionary<String, DynamicMethodInfo>>();
|
||||
MethodInfo[] mis = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
Type[] types;
|
||||
StringComparison sc;
|
||||
if (Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
dic = (Dictionary<Int32, Dictionary<String, DynamicMethodInfo>>)value;
|
||||
sc = StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
else
|
||||
{
|
||||
dic = new Dictionary<Int32, Dictionary<String, DynamicMethodInfo>>();
|
||||
MethodInfo[] mis = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
Type[] types;
|
||||
for (Int32 i = 0; i < mis.Length; i++)
|
||||
{
|
||||
if (!mis[i].Name.Equals(methodName, Engine.ComparisonIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pis = mis[i].GetParameters();
|
||||
types = new Type[pis.Length];
|
||||
for (Int32 j = 0; j < pis.Length; j++)
|
||||
{
|
||||
types[j] = pis[j].ParameterType;
|
||||
}
|
||||
itemKey = GetArgsTypeKey(types);
|
||||
if (!dic.TryGetValue(types.Length, out itemDic))
|
||||
{
|
||||
itemDic = new Dictionary<string, DynamicMethodInfo>();
|
||||
dic[types.Length] = itemDic;
|
||||
}
|
||||
//if (!itemDic.TryGetValue(itemKey,out d))
|
||||
itemDic[itemKey] = CreateExcuteMethodProxy(type, mis[i]);
|
||||
}
|
||||
Engine.Cache.Set(key, dic);
|
||||
sc = StringComparison.Ordinal;
|
||||
}
|
||||
for (Int32 i = 0; i < mis.Length; i++)
|
||||
{
|
||||
if (!mis[i].Name.Equals(methodName, sc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pis = mis[i].GetParameters();
|
||||
types = new Type[pis.Length];
|
||||
for (Int32 j = 0; j < pis.Length; j++)
|
||||
{
|
||||
types[j] = pis[j].ParameterType;
|
||||
}
|
||||
itemKey = GetArgsTypeKey(types);
|
||||
if (!dic.TryGetValue(types.Length, out itemDic))
|
||||
{
|
||||
itemDic = new Dictionary<string, DynamicMethodInfo>();
|
||||
dic[types.Length] = itemDic;
|
||||
}
|
||||
//if (!itemDic.TryGetValue(itemKey,out d))
|
||||
itemDic[itemKey] = CreateExcuteMethodProxy(type, mis[i]);
|
||||
}
|
||||
//Engine.Cache.Set(key, dic);
|
||||
//}
|
||||
|
||||
if (!dic.TryGetValue(args.Length, out itemDic))
|
||||
{
|
||||
@@ -349,9 +365,9 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
return model;
|
||||
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 共用方法
|
||||
#region 共用方法
|
||||
private Boolean HasNull(Object[] args)
|
||||
{
|
||||
if (args != null)
|
||||
@@ -479,7 +495,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
private readonly Char[] expressionPartSeparator;
|
||||
//private readonly Char[] indexExprEndChars;
|
||||
//private readonly Char[] indexExprStartChars;
|
||||
|
||||
#if NET20 || NET40
|
||||
private BindingFlags _bindingIgnoreCase;
|
||||
private StringComparison _stringIgnoreCase;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// 反射构造函数
|
||||
/// </summary>
|
||||
@@ -28,6 +31,18 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
expressionPartSeparator = new Char[] { '.' };
|
||||
//indexExprEndChars = new Char[] { ']', ')' };
|
||||
//indexExprStartChars = new Char[] { '[', '(' };
|
||||
#if NET20 || NET40
|
||||
if (Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
_bindingIgnoreCase = BindingFlags.IgnoreCase;
|
||||
_stringIgnoreCase = StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
else
|
||||
{
|
||||
_bindingIgnoreCase = BindingFlags.Default;
|
||||
_stringIgnoreCase = StringComparison.Ordinal;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#region EVAL解析
|
||||
#region 4.0版本
|
||||
@@ -96,7 +111,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
#if NETSTANDARD
|
||||
t.GetRuntimeProperty(propName);
|
||||
#else
|
||||
t.GetProperty(propName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | Engine.BindIgnoreCase);
|
||||
t.GetProperty(propName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |_bindingIgnoreCase);
|
||||
#endif
|
||||
//取属性
|
||||
if (p != null)
|
||||
@@ -105,7 +120,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
}
|
||||
#if NEEDFIELD
|
||||
//取字段
|
||||
FieldInfo f = t.GetField(propName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | Engine.BindIgnoreCase);
|
||||
FieldInfo f = t.GetField(propName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |_bindingIgnoreCase);
|
||||
if (f != null)
|
||||
{
|
||||
return f.GetValue(container);
|
||||
@@ -247,7 +262,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
{
|
||||
#if NOTDNX
|
||||
method = type.GetMethod(methodName,
|
||||
BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | Engine.BindIgnoreCase,
|
||||
BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | _bindingIgnoreCase,
|
||||
null, args, null);
|
||||
#elif NETSTANDARD
|
||||
method = type.GetRuntimeMethod(methodName, args);
|
||||
@@ -270,12 +285,12 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
#if NETSTANDARD
|
||||
type.GetRuntimeMethods();
|
||||
#else
|
||||
type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | Engine.BindIgnoreCase);
|
||||
type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | _bindingIgnoreCase);
|
||||
#endif
|
||||
foreach (MethodInfo m in ms)
|
||||
{
|
||||
|
||||
if (m.Name.Equals(methodName, Engine.ComparisonIgnoreCase))
|
||||
if (m.Name.Equals(methodName, _stringIgnoreCase))
|
||||
{
|
||||
pi = m.GetParameters();
|
||||
|
||||
@@ -411,7 +426,7 @@ namespace JinianNet.JNTemplate.Dynamic
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using System.Text;
|
||||
using JinianNet.JNTemplate.Parser;
|
||||
using JinianNet.JNTemplate.Configuration;
|
||||
using System.Reflection;
|
||||
using JinianNet.JNTemplate.Caching;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
@@ -18,18 +16,52 @@ namespace JinianNet.JNTemplate
|
||||
/// </summary>
|
||||
public class Engine
|
||||
{
|
||||
private static Dictionary<String, String> _variable;
|
||||
private static String[] _resourceDirectories;
|
||||
private static Object _lockObject = new Object();
|
||||
private static VariableScope _scope;
|
||||
private static ITagTypeResolver _tagResolver;
|
||||
private static StringComparison _stringComparison;
|
||||
#if !NETSTANDARD
|
||||
private static BindingFlags _bindingFlags;
|
||||
#endif
|
||||
private static StringComparer _stringComparer;
|
||||
private static ICache _cache;
|
||||
#region 私有变量
|
||||
/// <summary>
|
||||
/// 实例
|
||||
/// </summary>
|
||||
private static EngineInfo _instance;
|
||||
|
||||
/// <summary>
|
||||
/// 对象实例
|
||||
/// </summary>
|
||||
|
||||
internal static EngineInfo Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
Configure(Configuration.EngineConfig.CreateDefault());
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 属性
|
||||
/// <summary>
|
||||
/// 配置加载器
|
||||
/// </summary>
|
||||
/// <param name="loder"></param>
|
||||
public static void SetLoder(ILoader loder)
|
||||
{
|
||||
Instance.Loder = loder;
|
||||
}
|
||||
/// <summary>
|
||||
/// 解析器
|
||||
/// </summary>
|
||||
public List<ITagParser> Parsers
|
||||
{
|
||||
get
|
||||
{
|
||||
return Instance.Parsers;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 引擎配置
|
||||
/// <summary>
|
||||
/// 引擎配置
|
||||
/// </summary>
|
||||
@@ -41,9 +73,11 @@ namespace JinianNet.JNTemplate
|
||||
{
|
||||
throw new ArgumentNullException("\"conf\" cannot be null.");
|
||||
}
|
||||
Configure(conf.ToDictionary(),
|
||||
conf.ResourceDirectories,
|
||||
conf.TagParsers, scope);
|
||||
if (conf.TagParsers == null || conf.TagParsers.Length == 0)
|
||||
{
|
||||
conf.TagParsers = Field.RSEOLVER_TYPES;
|
||||
}
|
||||
Configure(conf.ToDictionary(), scope, LoadParsers(conf.TagParsers), new FileLoader());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,94 +89,28 @@ namespace JinianNet.JNTemplate
|
||||
/// <param name="scope">全局数据,可空</param>
|
||||
public static void Configure(
|
||||
IDictionary<String, String> conf,
|
||||
String[] directories,
|
||||
String[] parsers,
|
||||
VariableScope scope)
|
||||
VariableScope scope, ITagParser[] parsers, ILoader loader)
|
||||
{
|
||||
if (conf == null)
|
||||
{
|
||||
throw new ArgumentNullException("\"conf\" cannot be null.");
|
||||
}
|
||||
|
||||
_scope = scope;
|
||||
|
||||
InitializationEnvironment(conf);
|
||||
|
||||
if (_cache != null)
|
||||
_instance = new EngineInfo();
|
||||
_instance.Data = scope;
|
||||
InitializationEnvironment(conf);
|
||||
if (parsers == null || parsers.Length == 0)
|
||||
{
|
||||
_cache.Dispose();
|
||||
parsers = LoadParsers(Field.RSEOLVER_TYPES);
|
||||
}
|
||||
_cache = null;
|
||||
if (!String.IsNullOrEmpty(GetEnvironmentVariable("CachingProvider")))
|
||||
for (Int32 i = 0; i < parsers.Length; i++)
|
||||
{
|
||||
Type cacheType = Type.GetType(GetEnvironmentVariable("CachingProvider"));
|
||||
_cache = (ICache)Activator.CreateInstance(cacheType);
|
||||
if (parsers[i] != null)
|
||||
{
|
||||
Instance.Parsers.Add(parsers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Common.Utility.ToBoolean(GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
#if NETSTANDARD
|
||||
//_bindingFlags = true;
|
||||
#else
|
||||
_bindingFlags = BindingFlags.IgnoreCase;
|
||||
#endif
|
||||
_stringComparer = StringComparer.OrdinalIgnoreCase;
|
||||
_stringComparison = StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
else
|
||||
{
|
||||
_stringComparison = StringComparison.Ordinal;
|
||||
#if NETSTANDARD
|
||||
//_bindingFlags = false;
|
||||
#else
|
||||
_bindingFlags = BindingFlags.DeclaredOnly;
|
||||
#endif
|
||||
_stringComparer = StringComparer.Ordinal;
|
||||
}
|
||||
if (directories == null)
|
||||
{
|
||||
_resourceDirectories = new String[] {
|
||||
//Environment.CurrentDirectory
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
_resourceDirectories = directories;
|
||||
}
|
||||
InitializationParser(parsers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化环境变量配置
|
||||
/// </summary>
|
||||
/// <param name="conf">配置内容</param>
|
||||
private static void InitializationEnvironment(IDictionary<String, String> conf)
|
||||
{
|
||||
_variable = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (KeyValuePair<String, String> node in conf)
|
||||
{
|
||||
SetEnvironmentVariable(node.Key, node.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化标签分析器
|
||||
/// </summary>
|
||||
/// <param name="parsers">解析器类型</param>
|
||||
private static void InitializationParser(String[] parsers)
|
||||
{
|
||||
if (parsers == null)
|
||||
{
|
||||
parsers = Field.RSEOLVER_TYPES;
|
||||
}
|
||||
ITagParser[] tps = new ITagParser[parsers.Length];
|
||||
|
||||
for (Int32 i = 0; i < tps.Length; i++)
|
||||
{
|
||||
tps[i] = (ITagParser)Activator.CreateInstance(Type.GetType(parsers[i]));
|
||||
}
|
||||
_tagResolver = new Parser.TagTypeResolver(tps);
|
||||
SetLoder(loader ?? new FileLoader());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,17 +122,21 @@ namespace JinianNet.JNTemplate
|
||||
Configure(conf, null);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 对外方法
|
||||
/// <summary>
|
||||
/// 创建模板上下文
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static TemplateContext CreateContext()
|
||||
{
|
||||
if (_scope == null)
|
||||
if (Instance.Data == null)
|
||||
{
|
||||
return new TemplateContext();
|
||||
}
|
||||
return new TemplateContext(_scope);
|
||||
return new TemplateContext(Instance.Data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -195,65 +167,58 @@ namespace JinianNet.JNTemplate
|
||||
/// <returns>ITemplate</returns>
|
||||
public static ITemplate LoadTemplate(String path, TemplateContext ctx)
|
||||
{
|
||||
ResourceInfo info = Instance.Loder.Load(path, ctx.Charset);
|
||||
Template template;
|
||||
|
||||
String fullPath;
|
||||
String text = Resources.Load(ResourceDirectories, path, ctx.Charset, out fullPath);
|
||||
Template template = new Template(ctx, text);
|
||||
if (fullPath != null)
|
||||
if (info != null)
|
||||
{
|
||||
template.TemplateKey = fullPath;
|
||||
ctx.CurrentPath = System.IO.Path.GetDirectoryName(fullPath);
|
||||
template = new Template(ctx, info.Content);
|
||||
template.TemplateKey = info.FullPath;
|
||||
ctx.CurrentPath = Instance.Loder.GetDirectoryName(info.FullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
template = new Template(ctx, String.Empty);
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓存
|
||||
/// </summary>
|
||||
public static ICache Cache
|
||||
{
|
||||
get { return _cache; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标签类型解析器
|
||||
/// 分析标签
|
||||
/// </summary>
|
||||
public static Parser.ITagTypeResolver TagResolver
|
||||
/// <param name="parser">模板解析器</param>
|
||||
/// <param name="tc">TOKEN集合</param>
|
||||
/// <returns></returns>
|
||||
public static Node.Tag Resolve(TemplateParser parser, TokenCollection tc)
|
||||
{
|
||||
get { return _tagResolver; }
|
||||
|
||||
Tag t;
|
||||
for (Int32 i = 0; i < Instance.Parsers.Count; i++)
|
||||
{
|
||||
if (Instance.Parsers[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
t = Instance.Parsers[i].Parse(parser, tc);
|
||||
if (t != null)
|
||||
{
|
||||
t.FirstToken = tc.First;
|
||||
|
||||
if (t.Children.Count == 0
|
||||
|| (t.LastToken = t.Children[t.Children.Count - 1].LastToken ?? t.Children[t.Children.Count - 1].FirstToken) == null
|
||||
|| tc.Last.CompareTo(t.LastToken) > 0)
|
||||
{
|
||||
t.LastToken = tc.Last;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串大小写排序配置
|
||||
/// </summary>
|
||||
internal static StringComparison ComparisonIgnoreCase
|
||||
{
|
||||
get { return _stringComparison; }
|
||||
}
|
||||
|
||||
#if !NETSTANDARD
|
||||
/// <summary>
|
||||
/// 绑定大小写配置
|
||||
/// </summary>
|
||||
internal static BindingFlags BindIgnoreCase
|
||||
{
|
||||
get { return _bindingFlags; }
|
||||
}
|
||||
#endif
|
||||
/// <summary>
|
||||
/// 字符串大小写比较配置
|
||||
/// </summary>
|
||||
internal static StringComparer ComparerIgnoreCase
|
||||
{
|
||||
get { return _stringComparer; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public static String[] ResourceDirectories
|
||||
{
|
||||
get { return _resourceDirectories; }
|
||||
}
|
||||
#endregion
|
||||
#region 环境变量
|
||||
|
||||
/// <summary>
|
||||
/// 获取环境变量
|
||||
@@ -263,33 +228,14 @@ namespace JinianNet.JNTemplate
|
||||
public static String GetEnvironmentVariable(String variable)
|
||||
{
|
||||
String value;
|
||||
Dictionary<String, String> dic = (Dictionary<String, String>)GetEnvironmentVariables();
|
||||
|
||||
if (dic.TryGetValue(variable, out value))
|
||||
if (Instance.EnvironmentVariable.TryGetValue(variable, out value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有环境变量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IDictionary GetEnvironmentVariables()
|
||||
{
|
||||
if (_variable == null)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
if (_variable == null)
|
||||
{
|
||||
Configure(EngineConfig.CreateDefault());
|
||||
}
|
||||
}
|
||||
}
|
||||
return _variable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置环境变量
|
||||
@@ -304,12 +250,42 @@ namespace JinianNet.JNTemplate
|
||||
}
|
||||
if (value == null)
|
||||
{
|
||||
GetEnvironmentVariables().Remove(variable);
|
||||
Instance.EnvironmentVariable.Remove(variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetEnvironmentVariables()[variable] = value;
|
||||
Instance.EnvironmentVariable[variable] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
/// <summary>
|
||||
/// 初始化环境变量配置
|
||||
/// </summary>
|
||||
/// <param name="conf">配置内容</param>
|
||||
private static void InitializationEnvironment(IDictionary<String, String> conf)
|
||||
{
|
||||
foreach (KeyValuePair<String, String> node in conf)
|
||||
{
|
||||
SetEnvironmentVariable(node.Key, node.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载标签分析器
|
||||
/// </summary>
|
||||
/// <param name="arr">解析器类型</param>
|
||||
private static ITagParser[] LoadParsers(string[] arr)
|
||||
{
|
||||
ITagParser[] list = new ITagParser[arr.Length];
|
||||
for (Int32 i = 0; i < arr.Length; i++)
|
||||
{
|
||||
list[i] = ((ITagParser)Activator.CreateInstance(Type.GetType(arr[i])));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
64
src/JinianNet.JNTemplate/EngineInfo.cs
Normal file
64
src/JinianNet.JNTemplate/EngineInfo.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
public class EngineInfo
|
||||
{
|
||||
#region 字段
|
||||
private Dictionary<String, String> _environmentVariable;
|
||||
private VariableScope _data;
|
||||
private List<ITagParser> _parsers;
|
||||
private ILoader _loder;
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 引擎信息
|
||||
/// </summary>
|
||||
public EngineInfo()
|
||||
{
|
||||
_environmentVariable = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
||||
_parsers = new List<ITagParser>();
|
||||
}
|
||||
|
||||
#region 实列
|
||||
/// <summary>
|
||||
/// 环境变量
|
||||
/// </summary>
|
||||
public Dictionary<String, String> EnvironmentVariable
|
||||
{
|
||||
get { return _environmentVariable; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 全局初始数据
|
||||
/// </summary>
|
||||
public VariableScope Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标签分析器
|
||||
/// </summary>
|
||||
public List<ITagParser> Parsers
|
||||
{
|
||||
get { return _parsers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载器
|
||||
/// </summary>
|
||||
public ILoader Loder
|
||||
{
|
||||
get { return _loder; }
|
||||
set { _loder = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,11 @@ namespace JinianNet.JNTemplate
|
||||
/// <summary>
|
||||
/// 当前程序版本
|
||||
/// </summary>
|
||||
public const String Version = "1.3";
|
||||
public const String Version = "1.4";
|
||||
internal const String KEY_FOREACH = "foreach";
|
||||
internal const String KEY_IF = "if";
|
||||
internal const String KEY_ELSEIF = "elseif";
|
||||
internal const String KEY_ELIF = "elif";
|
||||
internal const String KEY_ELSE = "else";
|
||||
internal const String KEY_SET = "set";
|
||||
internal const String KEY_LOAD = "load";
|
||||
|
||||
264
src/JinianNet.JNTemplate/FileLoader.cs
Normal file
264
src/JinianNet.JNTemplate/FileLoader.cs
Normal file
@@ -0,0 +1,264 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
public class FileLoader : ILoader
|
||||
{
|
||||
public FileLoader()
|
||||
{
|
||||
this.ResourceDirectories = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 基本资源路径
|
||||
/// </summary>
|
||||
public List<String> ResourceDirectories { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取父目录
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <returns></returns>
|
||||
public String GetDirectoryName(String fullPath)
|
||||
{
|
||||
return System.IO.Path.GetDirectoryName(fullPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源
|
||||
/// </summary>
|
||||
/// <param name="filename">文件名,可以是纯文件名,也可以是完整的路径</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <param name="directory">追加查找目录</param>
|
||||
/// <returns></returns>
|
||||
public ResourceInfo Load(String filename, Encoding encoding, params string[] directory)
|
||||
{
|
||||
ResourceInfo info = new ResourceInfo();
|
||||
string fullPath;
|
||||
if ((directory == null
|
||||
|| directory.Length == 0
|
||||
|| (info.Content = Load(directory, filename, encoding, out fullPath)) == null)
|
||||
&& (info.Content = Load(this.ResourceDirectories, filename, encoding, out fullPath)) == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
info.FullPath = fullPath;
|
||||
return info;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找指定文件
|
||||
/// </summary>
|
||||
/// <param name="filename">文件名 允许相对路径.路径分隔符只能使用/</param>
|
||||
/// <param name="fullPath">查找结果:完整路径</param>
|
||||
/// <returns>路径索引</returns>
|
||||
public Int32 FindPath(String filename, out String fullPath)
|
||||
{
|
||||
return FindPath(this.ResourceDirectories, filename, out fullPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找指定文件
|
||||
/// </summary>
|
||||
/// <param name="paths">检索路径</param>
|
||||
/// <param name="filename">文件名 允许相对路径.路径分隔符只能使用/</param>
|
||||
/// <param name="fullPath">查找结果:完整路径</param>
|
||||
/// <returns>路径索引</returns>
|
||||
public Int32 FindPath(IEnumerable<String> paths, String filename, out String fullPath)
|
||||
{
|
||||
//filename 允许单纯的文件名或相对路径
|
||||
fullPath = null;
|
||||
|
||||
if (!String.IsNullOrEmpty(filename))
|
||||
{
|
||||
if ((filename = NormalizePath(filename)) == null) //路径非法,比如用户试图跳出当前目录时(../header.txt)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
Int32 i = 0;
|
||||
foreach (String checkUrl in paths)
|
||||
{
|
||||
if (checkUrl[checkUrl.Length - 1] != System.IO.Path.DirectorySeparatorChar)
|
||||
{
|
||||
fullPath = String.Concat(checkUrl, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
fullPath = String.Concat(checkUrl.Remove(checkUrl.Length - 1, 1), filename);
|
||||
}
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源
|
||||
/// </summary>
|
||||
/// <param name="paths">检索路径</param>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <returns>文本内容</returns>
|
||||
public String Load(IEnumerable<String> paths, String filename, Encoding encoding)
|
||||
{
|
||||
if (paths == null && String.IsNullOrEmpty(filename))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (encoding == null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
String full;
|
||||
if (FindPath(paths, filename, out full) != -1)
|
||||
{
|
||||
return LoadResource(full, encoding);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 载入文件
|
||||
/// </summary>
|
||||
/// <param name="fullPath">完整文件路径</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <returns>文本内容</returns>
|
||||
public String LoadResource(String fullPath, Encoding encoding)
|
||||
{
|
||||
if (!System.IO.File.Exists(fullPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (encoding == null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
return System.IO.File.ReadAllText(fullPath, encoding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据文件名(允许有相对路径)查找并读取文件
|
||||
/// </summary>
|
||||
/// <param name="paths">检索目录</param>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <param name="fullName">完整路径</param>
|
||||
/// <returns></returns>
|
||||
public String Load(IEnumerable<String> paths, String filename, Encoding encoding, out String fullName)
|
||||
{
|
||||
if (IsLocalPath(filename))
|
||||
{
|
||||
fullName = filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
Int32 index = FindPath(paths, filename, out fullName); //如果是相对路径,则进行路径搜索
|
||||
if (index == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return LoadResource(fullName, encoding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否WIN风格本地路径
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
private Boolean IsWindowsLocalPath(String path)
|
||||
{
|
||||
return path.IndexOf(System.IO.Path.VolumeSeparatorChar) != -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否Unix风格本地路径
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
private Boolean IsUnixLocalPath(String path)
|
||||
{
|
||||
return path[0] == '/'; ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否本地路径表达形式
|
||||
/// </summary>
|
||||
/// <param name="path">路径</param>
|
||||
/// <returns></returns>
|
||||
public Boolean IsLocalPath(String path)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//win系统
|
||||
System.OperatingSystem osInfo = System.Environment.OSVersion;
|
||||
if (osInfo.Platform == PlatformID.Win32NT
|
||||
|| osInfo.Platform == PlatformID.Win32S
|
||||
|| osInfo.Platform == PlatformID.Win32Windows
|
||||
|| osInfo.Platform == PlatformID.WinCE
|
||||
|| osInfo.Platform == PlatformID.Xbox)
|
||||
{
|
||||
return IsWindowsLocalPath(path);
|
||||
}
|
||||
//mac or unix
|
||||
if (osInfo.Platform == PlatformID.MacOSX
|
||||
|| osInfo.Platform == PlatformID.Unix)
|
||||
{
|
||||
return IsUnixLocalPath(path);
|
||||
}
|
||||
|
||||
return IsUnixLocalPath(path) || IsWindowsLocalPath(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路径处理
|
||||
/// </summary>
|
||||
/// <param name="filename">待处理文件</param>
|
||||
/// <returns>处理后的路径</returns>
|
||||
public String NormalizePath(String filename)
|
||||
{
|
||||
if (String.IsNullOrEmpty(filename) || filename.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> values = new List<String>(filename.Split('/'));
|
||||
|
||||
for (Int32 i = 0; i < values.Count; i++)
|
||||
{
|
||||
if (values[i] == "." || String.IsNullOrEmpty(values[i]))
|
||||
{
|
||||
values.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
else if (values[i] == "..")
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
values.RemoveAt(i);
|
||||
i--;
|
||||
values.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
values.Insert(0, String.Empty);
|
||||
|
||||
return String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), values.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/JinianNet.JNTemplate/ILoader.cs
Normal file
31
src/JinianNet.JNTemplate/ILoader.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System.Text;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 模板加载器
|
||||
/// </summary>
|
||||
public interface ILoader
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载资源
|
||||
/// </summary>
|
||||
/// <param name="filename">文件名,可以是纯文件名,也可以是完整的路径</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <param name="directory">追加查找目录</param>
|
||||
/// <returns></returns>
|
||||
ResourceInfo Load(String filename, Encoding encoding, params string[] directory);
|
||||
|
||||
/// <summary>
|
||||
/// 获取父目录
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <returns></returns>
|
||||
String GetDirectoryName(String fullPath);
|
||||
}
|
||||
}
|
||||
@@ -66,18 +66,21 @@
|
||||
<Compile Include="Dynamic\ILProvider.cs" />
|
||||
<Compile Include="Dynamic\ReflectionProvider.cs" />
|
||||
<Compile Include="Engine.cs" />
|
||||
<Compile Include="EngineInfo.cs" />
|
||||
<Compile Include="Exception\CompileException.cs" />
|
||||
<Compile Include="Exception\TemplateException.cs" />
|
||||
<Compile Include="Exception\ParseException.cs" />
|
||||
<Compile Include="Field.cs" />
|
||||
<Compile Include="FileLoader.cs" />
|
||||
<Compile Include="FuncHandler.cs" />
|
||||
<Compile Include="Caching\ICache.cs" />
|
||||
<Compile Include="ILoader.cs" />
|
||||
<Compile Include="ITemplate.cs" />
|
||||
<Compile Include="Common\ExpressionEvaluator.cs" />
|
||||
<Compile Include="LexerMode.cs" />
|
||||
<Compile Include="Operator.cs" />
|
||||
<Compile Include="Parser\BooleanParser.cs" />
|
||||
<Compile Include="Parser\CharScanner.cs" />
|
||||
<Compile Include="CharScanner.cs" />
|
||||
<Compile Include="Parser\ComplexParser.cs" />
|
||||
<Compile Include="Parser\EleseParser.cs" />
|
||||
<Compile Include="Parser\ElseifParser.cs" />
|
||||
@@ -90,39 +93,39 @@
|
||||
<Compile Include="Parser\ITagParser.cs" />
|
||||
<Compile Include="Parser\ITagTypeResolver.cs" />
|
||||
<Compile Include="Parser\LoadParser.cs" />
|
||||
<Compile Include="Parser\Node\SimpleTag.cs" />
|
||||
<Compile Include="Parser\Node\TypeTag.cs" />
|
||||
<Compile Include="Parser\Node\BlockTag.cs" />
|
||||
<Compile Include="Parser\Node\BooleanTag.cs" />
|
||||
<Compile Include="Parser\Node\ElseifTag.cs" />
|
||||
<Compile Include="Parser\Node\ElseTag.cs" />
|
||||
<Compile Include="Parser\Node\EndTag.cs" />
|
||||
<Compile Include="Parser\Node\ExpressionTag.cs" />
|
||||
<Compile Include="Parser\Node\ForeachTag.cs" />
|
||||
<Compile Include="Parser\Node\ForTag.cs" />
|
||||
<Compile Include="Parser\Node\FunctaionTag.cs" />
|
||||
<Compile Include="Parser\Node\IfTag.cs" />
|
||||
<Compile Include="Parser\Node\IncludeTag.cs" />
|
||||
<Compile Include="Parser\Node\LoadTag.cs" />
|
||||
<Compile Include="Parser\Node\NullTag.cs" />
|
||||
<Compile Include="Parser\Node\NumberTag.cs" />
|
||||
<Compile Include="Parser\Node\ReferenceTag.cs" />
|
||||
<Compile Include="Parser\Node\SetTag.cs" />
|
||||
<Compile Include="Parser\Node\TagBase.cs" />
|
||||
<Compile Include="Parser\Node\StringTag.cs" />
|
||||
<Compile Include="Parser\Node\Tag.cs" />
|
||||
<Compile Include="Parser\Node\TextTag.cs" />
|
||||
<Compile Include="Parser\Node\Token.cs" />
|
||||
<Compile Include="Parser\Node\TokenCollection.cs" />
|
||||
<Compile Include="Parser\Node\VariableTag.cs" />
|
||||
<Compile Include="Node\SimpleTag.cs" />
|
||||
<Compile Include="Node\TypeTag.cs" />
|
||||
<Compile Include="Node\BlockTag.cs" />
|
||||
<Compile Include="Node\BooleanTag.cs" />
|
||||
<Compile Include="Node\ElseifTag.cs" />
|
||||
<Compile Include="Node\ElseTag.cs" />
|
||||
<Compile Include="Node\EndTag.cs" />
|
||||
<Compile Include="Node\ExpressionTag.cs" />
|
||||
<Compile Include="Node\ForeachTag.cs" />
|
||||
<Compile Include="Node\ForTag.cs" />
|
||||
<Compile Include="Node\FunctaionTag.cs" />
|
||||
<Compile Include="Node\IfTag.cs" />
|
||||
<Compile Include="Node\IncludeTag.cs" />
|
||||
<Compile Include="Node\LoadTag.cs" />
|
||||
<Compile Include="Node\NullTag.cs" />
|
||||
<Compile Include="Node\NumberTag.cs" />
|
||||
<Compile Include="Node\ReferenceTag.cs" />
|
||||
<Compile Include="Node\SetTag.cs" />
|
||||
<Compile Include="Node\TagBase.cs" />
|
||||
<Compile Include="Node\StringTag.cs" />
|
||||
<Compile Include="Node\Tag.cs" />
|
||||
<Compile Include="Node\TextTag.cs" />
|
||||
<Compile Include="Node\Token.cs" />
|
||||
<Compile Include="Node\TokenCollection.cs" />
|
||||
<Compile Include="Node\VariableTag.cs" />
|
||||
<Compile Include="Parser\NumberParser.cs" />
|
||||
<Compile Include="Parser\TagTypeResolver.cs" />
|
||||
<Compile Include="Parser\SetParser.cs" />
|
||||
<Compile Include="Parser\StringParser.cs" />
|
||||
<Compile Include="Parser\TemplateLexer.cs" />
|
||||
<Compile Include="Parser\TemplateParser.cs" />
|
||||
<Compile Include="ResourceInfo.cs" />
|
||||
<Compile Include="TemplateLexer.cs" />
|
||||
<Compile Include="TemplateParser.cs" />
|
||||
<Compile Include="Parser\VariableParser.cs" />
|
||||
<Compile Include="Parser\VariableScope.cs" />
|
||||
<Compile Include="VariableScope.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Resources.cs" />
|
||||
<Compile Include="Template.cs" />
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 标签块
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 布尔标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// else标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// ELSE if 标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 结束标签,用于if for等复合标签的结束
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 表达式
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// FOR标签
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// Foreach标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 函数(方法)标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// IF标签
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// INCLUDE标签
|
||||
@@ -21,21 +21,21 @@ namespace JinianNet.JNTemplate.Parser.Node
|
||||
get { return this._path; }
|
||||
set { this._path = value; }
|
||||
}
|
||||
|
||||
|
||||
private String LoadResource(Object path, TemplateContext context)
|
||||
{
|
||||
if (path != null)
|
||||
{
|
||||
IEnumerable<String> paths;
|
||||
if (String.IsNullOrEmpty(context.CurrentPath))
|
||||
string[] paths = null;
|
||||
if (!string.IsNullOrEmpty(context.CurrentPath))
|
||||
{
|
||||
paths = Engine.ResourceDirectories;
|
||||
paths = new[] { context.CurrentPath };
|
||||
}
|
||||
else
|
||||
ResourceInfo info = Engine.Instance.Loder.Load(path.ToString(), context.Charset, paths);
|
||||
if (info != null)
|
||||
{
|
||||
paths = Resources.MergerPaths(Engine.ResourceDirectories, context.CurrentPath);
|
||||
return info.Content;
|
||||
}
|
||||
return Resources.Load(paths, path.ToString(), context.Charset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// LOAD标签
|
||||
@@ -48,16 +48,17 @@ namespace JinianNet.JNTemplate.Parser.Node
|
||||
{
|
||||
if (path != null)
|
||||
{
|
||||
IEnumerable<String> paths;
|
||||
if (String.IsNullOrEmpty(context.CurrentPath))
|
||||
string[] paths = null;
|
||||
if (!string.IsNullOrEmpty(context.CurrentPath))
|
||||
{
|
||||
paths = Engine.ResourceDirectories;
|
||||
paths = new[] { context.CurrentPath };
|
||||
}
|
||||
else
|
||||
ResourceInfo info = Engine.Instance.Loder.Load(path.ToString(), context.Charset, paths);
|
||||
if (info != null)
|
||||
{
|
||||
paths = Resources.MergerPaths(Engine.ResourceDirectories, context.CurrentPath);
|
||||
TemplateContent = info.Content;
|
||||
}
|
||||
TemplateContent = Resources.Load(paths, path.ToString(), context.Charset);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 空标签
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 数字标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 组合标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 赋值标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 简单标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串标签
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 标签基类
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 基本标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 文本标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// TOKEN
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// TOKEN集合
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 基本类型标签
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser.Node
|
||||
namespace JinianNet.JNTemplate.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量标签
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
@@ -20,7 +20,7 @@ namespace JinianNet.JNTemplate.Parser
|
||||
/// <param name="parser">TemplateParser</param>
|
||||
/// <param name="tc">Token集合</param>
|
||||
/// <returns></returns>
|
||||
public Tag Parse(JinianNet.JNTemplate.Parser.TemplateParser parser, TokenCollection tc)
|
||||
public Tag Parse(TemplateParser parser, TokenCollection tc)
|
||||
{
|
||||
if (tc != null
|
||||
&& parser != null
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
@@ -24,24 +24,22 @@ namespace JinianNet.JNTemplate.Parser
|
||||
if (tc != null
|
||||
&& parser != null
|
||||
&& tc.Count > 3
|
||||
&& Common.Utility.IsEqual(tc.First.Text, Field.KEY_ELSEIF))
|
||||
&& (Common.Utility.IsEqual(tc.First.Text, Field.KEY_ELSEIF) || Common.Utility.IsEqual(tc.First.Text, Field.KEY_ELIF))
|
||||
&& tc[1].TokenKind == TokenKind.LeftParentheses
|
||||
&& tc.Last.TokenKind == TokenKind.RightParentheses)
|
||||
{
|
||||
ElseifTag tag = new ElseifTag();
|
||||
|
||||
if (tc[1].TokenKind == TokenKind.LeftParentheses
|
||||
&& tc.Last.TokenKind == TokenKind.RightParentheses)
|
||||
{
|
||||
ElseifTag tag = new ElseifTag();
|
||||
TokenCollection coll = new TokenCollection();
|
||||
coll.Add(tc, 2, tc.Count - 2);
|
||||
tag.Test = parser.Read(coll);
|
||||
|
||||
TokenCollection coll = new TokenCollection();
|
||||
coll.Add(tc, 2, tc.Count - 2);
|
||||
tag.Test = parser.Read(coll);
|
||||
|
||||
return tag;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception.ParseException(String.Concat("syntax error near if:", tc), tc.First.BeginLine, tc.First.BeginColumn);
|
||||
}
|
||||
return tag;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// throw new Exception.ParseException(String.Concat("syntax error near if:", tc), tc.First.BeginLine, tc.First.BeginColumn);
|
||||
//}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
@@ -23,39 +23,36 @@ namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
if (tc != null
|
||||
&& parser != null
|
||||
&& tc.Count > 0
|
||||
&& Common.Utility.IsEqual(Field.KEY_FOREACH, tc.First.Text))
|
||||
&& tc.Count > 5
|
||||
&& (Common.Utility.IsEqual(Field.KEY_FOREACH, tc.First.Text) || Common.Utility.IsEqual(Field.KEY_FOR, tc.First.Text))
|
||||
&& tc[1].TokenKind == TokenKind.LeftParentheses
|
||||
&& tc[2].TokenKind == TokenKind.TextData
|
||||
&& Common.Utility.IsEqual(tc[3].Text, Field.KEY_IN)
|
||||
&& tc.Last.TokenKind == TokenKind.RightParentheses)
|
||||
{
|
||||
if (tc.Count > 5
|
||||
&& tc[1].TokenKind == TokenKind.LeftParentheses
|
||||
&& tc[2].TokenKind == TokenKind.TextData
|
||||
&& Common.Utility.IsEqual(tc[3].Text, Field.KEY_IN)
|
||||
&& tc.Last.TokenKind == TokenKind.RightParentheses)
|
||||
{
|
||||
ForeachTag tag = new ForeachTag();
|
||||
tag.Name = tc[2].Text;
|
||||
TokenCollection coll = new TokenCollection();
|
||||
coll.Add(tc, 4, tc.Count - 2);
|
||||
tag.Source = parser.Read(coll);
|
||||
|
||||
while (parser.MoveNext())
|
||||
ForeachTag tag = new ForeachTag();
|
||||
tag.Name = tc[2].Text;
|
||||
TokenCollection coll = new TokenCollection();
|
||||
coll.Add(tc, 4, tc.Count - 2);
|
||||
tag.Source = parser.Read(coll);
|
||||
|
||||
while (parser.MoveNext())
|
||||
{
|
||||
tag.Children.Add(parser.Current);
|
||||
if (parser.Current is EndTag)
|
||||
{
|
||||
tag.Children.Add(parser.Current);
|
||||
if (parser.Current is EndTag)
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
throw new Exception.ParseException(String.Concat("foreach is not properly closed by a end tag:", tc), tc.First.BeginLine, tc.First.BeginColumn);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception.ParseException(String.Concat("syntax error near foreach:", tc), tc.First.BeginLine, tc.First.BeginColumn);
|
||||
}
|
||||
|
||||
throw new Exception.ParseException(String.Concat("foreach is not properly closed by a end tag:", tc), tc.First.BeginLine, tc.First.BeginColumn);
|
||||
|
||||
//else
|
||||
//{
|
||||
// throw new Exception.ParseException(String.Concat("syntax error near foreach:", tc), tc.First.BeginLine, tc.First.BeginColumn);
|
||||
//}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
///********************************************************************************
|
||||
// Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// ********************************************************************************/
|
||||
//using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
/// <summary>
|
||||
/// 标签类型分析器
|
||||
/// </summary>
|
||||
public interface ITagTypeResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// 解析标签
|
||||
/// </summary>
|
||||
/// <param name="parser">TemplateParser</param>
|
||||
/// <param name="tc">Token集合</param>
|
||||
/// <returns></returns>
|
||||
Tag Resolver(TemplateParser parser, TokenCollection tc);
|
||||
}
|
||||
}
|
||||
//namespace JinianNet.JNTemplate.Parser
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// 标签类型分析器
|
||||
// /// </summary>
|
||||
// public interface ITagTypeResolver
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 解析标签
|
||||
// /// </summary>
|
||||
// /// <param name="parser">TemplateParser</param>
|
||||
// /// <param name="tc">Token集合</param>
|
||||
// /// <returns></returns>
|
||||
// Tag Resolver(TemplateParser parser, TokenCollection tc);
|
||||
// }
|
||||
//}
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
/// <summary>
|
||||
/// 分析器
|
||||
/// </summary>
|
||||
public class TagTypeResolver : ITagTypeResolver, ICollection<ITagParser>
|
||||
{
|
||||
private readonly List<ITagParser> _collection;
|
||||
/// <summary>
|
||||
/// 标签类型分析器
|
||||
/// </summary>
|
||||
public TagTypeResolver()
|
||||
: this(null)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 标签类型分析器
|
||||
/// </summary>
|
||||
/// <param name="parsers">各类标签分析器集合</param>
|
||||
public TagTypeResolver(IEnumerable<ITagParser> parsers)
|
||||
{
|
||||
if (parsers != null)
|
||||
{
|
||||
this._collection = new List<ITagParser>(parsers);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._collection = new List<ITagParser>();
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 解析标签
|
||||
/// </summary>
|
||||
/// <param name="parser">TemplateParser</param>
|
||||
/// <param name="tc">Token集合</param>
|
||||
/// <returns></returns>
|
||||
public Tag Resolver(TemplateParser parser, TokenCollection tc)
|
||||
{
|
||||
Tag t;
|
||||
for (Int32 i = 0; i < this._collection.Count; i++)
|
||||
{
|
||||
if (this._collection[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
t = this._collection[i].Parse(parser, tc);
|
||||
if (t != null)
|
||||
{
|
||||
t.FirstToken = tc.First;
|
||||
|
||||
if (t.Children.Count == 0
|
||||
|| (t.LastToken = t.Children[t.Children.Count - 1].LastToken ?? t.Children[t.Children.Count - 1].FirstToken) == null
|
||||
|| tc.Last.CompareTo(t.LastToken) > 0)
|
||||
{
|
||||
t.LastToken = tc.Last;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加一个标签分析器
|
||||
/// </summary>
|
||||
/// <param name="item">标签分析器</param>
|
||||
public void Add(ITagParser item)
|
||||
{
|
||||
this._collection.Add(item);
|
||||
}
|
||||
/// <summary>
|
||||
/// 插入一个标签分析器
|
||||
/// </summary>
|
||||
/// <param name="index">插入索引</param>
|
||||
/// <param name="item">标签分析器</param>
|
||||
public void Insert(Int32 index, ITagParser item)
|
||||
{
|
||||
this._collection.Insert(index, item);
|
||||
}
|
||||
/// <summary>
|
||||
/// 清除所有分析器
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
this._collection.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果在集合中找到 item,则为 true,否则为 false。
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public Boolean Contains(ITagParser item)
|
||||
{
|
||||
return this._collection.Contains(item);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将整个 ITagParser[] 复制到兼容的一维数组中,从目标数组的指定索引位置开始放置。
|
||||
/// </summary>
|
||||
/// <param name="array">待复制的集合</param>
|
||||
/// <param name="arrayIndex">开始位置</param>
|
||||
public void CopyTo(ITagParser[] array, Int32 arrayIndex)
|
||||
{
|
||||
this._collection.CopyTo(array, arrayIndex);
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回集合个数
|
||||
/// </summary>
|
||||
public Int32 Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._collection.Count;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 集合是否只读
|
||||
/// </summary>
|
||||
public Boolean IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取或设置集合的指定索引位置的值
|
||||
/// </summary>
|
||||
/// <param name="index">索引</param>
|
||||
/// <returns>ITagParser</returns>
|
||||
public ITagParser this[Int32 index]
|
||||
{
|
||||
set { this._collection[index] = value; }
|
||||
get { return this._collection[index]; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 分析器中 中移除特定对象的第一个匹配项。
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public Boolean Remove(ITagParser item)
|
||||
{
|
||||
return this._collection.Remove(item);
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回循环访问 ITagParser的枚举器。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerator<ITagParser> GetEnumerator()
|
||||
{
|
||||
return this._collection.GetEnumerator();
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回循环访问 ITagParser的枚举器。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
for (Int32 i = 0; i < Count; i++)
|
||||
{
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
|
||||
@@ -16,5 +16,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: ComVisible(true)]
|
||||
[assembly: CLSCompliant(true)]
|
||||
[assembly: Guid("de260545-c1e6-4349-bfd2-da6ce96393dd")]
|
||||
[assembly: AssemblyVersion("1.3.2.3")]
|
||||
[assembly: AssemblyFileVersion("1.3.2")]
|
||||
[assembly: AssemblyVersion("1.4.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.4.0")]
|
||||
17
src/JinianNet.JNTemplate/ResourceInfo.cs
Normal file
17
src/JinianNet.JNTemplate/ResourceInfo.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public class ResourceInfo
|
||||
{
|
||||
public String Content { get; set; }
|
||||
public string FullPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,220 +1,220 @@
|
||||
/********************************************************************************
|
||||
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
///********************************************************************************
|
||||
// Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// ********************************************************************************/
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
///资源操作
|
||||
/// </summary>
|
||||
public class Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// 合并集合
|
||||
/// </summary>
|
||||
/// <param name="oldPaths">原路径集合</param>
|
||||
/// <param name="newPaths">待合并的路径集合</param>
|
||||
/// <returns>新的路径集合</returns>
|
||||
public static IEnumerable<String> MergerPaths(IEnumerable<String> oldPaths, params String[] newPaths)
|
||||
{
|
||||
List<String> list = new List<String>();
|
||||
if (newPaths != null)
|
||||
{
|
||||
list.AddRange(newPaths);
|
||||
}
|
||||
if (oldPaths != null)
|
||||
{
|
||||
list.AddRange(oldPaths);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
//namespace JinianNet.JNTemplate
|
||||
//{
|
||||
// /// <summary>
|
||||
// ///资源操作
|
||||
// /// </summary>
|
||||
// public class Resources
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 合并集合
|
||||
// /// </summary>
|
||||
// /// <param name="oldPaths">原路径集合</param>
|
||||
// /// <param name="newPaths">待合并的路径集合</param>
|
||||
// /// <returns>新的路径集合</returns>
|
||||
// public static IEnumerable<String> MergerPaths(IEnumerable<String> oldPaths, params String[] newPaths)
|
||||
// {
|
||||
// List<String> list = new List<String>();
|
||||
// if (newPaths != null)
|
||||
// {
|
||||
// list.AddRange(newPaths);
|
||||
// }
|
||||
// if (oldPaths != null)
|
||||
// {
|
||||
// list.AddRange(oldPaths);
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 查找指定文件
|
||||
/// </summary>
|
||||
/// <param name="filename">文件名 允许相对路径.路径分隔符只能使用/</param>
|
||||
/// <param name="fullPath">查找结果:完整路径</param>
|
||||
/// <returns>路径索引</returns>
|
||||
public static Int32 FindPath(String filename, out String fullPath)
|
||||
{
|
||||
return FindPath(Engine.ResourceDirectories, filename, out fullPath);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 查找指定文件
|
||||
// /// </summary>
|
||||
// /// <param name="filename">文件名 允许相对路径.路径分隔符只能使用/</param>
|
||||
// /// <param name="fullPath">查找结果:完整路径</param>
|
||||
// /// <returns>路径索引</returns>
|
||||
// public static Int32 FindPath(String filename, out String fullPath)
|
||||
// {
|
||||
// return FindPath(Engine.ResourceDirectories, filename, out fullPath);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 查找指定文件
|
||||
/// </summary>
|
||||
/// <param name="paths">检索路径</param>
|
||||
/// <param name="filename">文件名 允许相对路径.路径分隔符只能使用/</param>
|
||||
/// <param name="fullPath">查找结果:完整路径</param>
|
||||
/// <returns>路径索引</returns>
|
||||
public static Int32 FindPath(IEnumerable<String> paths, String filename, out String fullPath)
|
||||
{
|
||||
//filename 允许单纯的文件名或相对路径
|
||||
fullPath = null;
|
||||
// /// <summary>
|
||||
// /// 查找指定文件
|
||||
// /// </summary>
|
||||
// /// <param name="paths">检索路径</param>
|
||||
// /// <param name="filename">文件名 允许相对路径.路径分隔符只能使用/</param>
|
||||
// /// <param name="fullPath">查找结果:完整路径</param>
|
||||
// /// <returns>路径索引</returns>
|
||||
// public static Int32 FindPath(IEnumerable<String> paths, String filename, out String fullPath)
|
||||
// {
|
||||
// //filename 允许单纯的文件名或相对路径
|
||||
// fullPath = null;
|
||||
|
||||
if (!String.IsNullOrEmpty(filename))
|
||||
{
|
||||
if ((filename = NormalizePath(filename)) == null) //路径非法,比如用户试图跳出当前目录时(../header.txt)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// if (!String.IsNullOrEmpty(filename))
|
||||
// {
|
||||
// if ((filename = NormalizePath(filename)) == null) //路径非法,比如用户试图跳出当前目录时(../header.txt)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
Int32 i = 0;
|
||||
foreach (String checkUrl in paths)
|
||||
{
|
||||
if (checkUrl[checkUrl.Length - 1] != System.IO.Path.DirectorySeparatorChar)
|
||||
{
|
||||
fullPath = String.Concat(checkUrl, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
fullPath = String.Concat(checkUrl.Remove(checkUrl.Length - 1, 1), filename);
|
||||
}
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
// Int32 i = 0;
|
||||
// foreach (String checkUrl in paths)
|
||||
// {
|
||||
// if (checkUrl[checkUrl.Length - 1] != System.IO.Path.DirectorySeparatorChar)
|
||||
// {
|
||||
// fullPath = String.Concat(checkUrl, filename);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// fullPath = String.Concat(checkUrl.Remove(checkUrl.Length - 1, 1), filename);
|
||||
// }
|
||||
// if (System.IO.File.Exists(fullPath))
|
||||
// {
|
||||
// return i;
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// }
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源
|
||||
/// </summary>
|
||||
/// <param name="paths">检索路径</param>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <returns>文本内容</returns>
|
||||
public static String Load(IEnumerable<String> paths, String filename, Encoding encoding)
|
||||
{
|
||||
if (paths == null && String.IsNullOrEmpty(filename))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (encoding == null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
String full;
|
||||
if (FindPath(paths, filename, out full) != -1)
|
||||
{
|
||||
return LoadResource(full, encoding);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 加载资源
|
||||
// /// </summary>
|
||||
// /// <param name="paths">检索路径</param>
|
||||
// /// <param name="filename">文件名</param>
|
||||
// /// <param name="encoding">编码</param>
|
||||
// /// <returns>文本内容</returns>
|
||||
// public static String Load(IEnumerable<String> paths, String filename, Encoding encoding)
|
||||
// {
|
||||
// if (paths == null && String.IsNullOrEmpty(filename))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// if (encoding == null)
|
||||
// {
|
||||
// encoding = Encoding.UTF8;
|
||||
// }
|
||||
// String full;
|
||||
// if (FindPath(paths, filename, out full) != -1)
|
||||
// {
|
||||
// return LoadResource(full, encoding);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源
|
||||
/// </summary>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <returns>文本内容</returns>
|
||||
public static String Load(String filename, Encoding encoding)
|
||||
{
|
||||
return Load(Engine.ResourceDirectories, filename, encoding);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 加载资源
|
||||
// /// </summary>
|
||||
// /// <param name="filename">文件名</param>
|
||||
// /// <param name="encoding">编码</param>
|
||||
// /// <returns>文本内容</returns>
|
||||
// public static String Load(String filename, Encoding encoding)
|
||||
// {
|
||||
// return Load(Engine.ResourceDirectories, filename, encoding);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 载入文件
|
||||
/// </summary>
|
||||
/// <param name="fullPath">完整文件路径</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <returns>文本内容</returns>
|
||||
public static String LoadResource(String fullPath, Encoding encoding)
|
||||
{
|
||||
if (!System.IO.File.Exists(fullPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (encoding == null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
return System.IO.File.ReadAllText(fullPath, encoding);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 载入文件
|
||||
// /// </summary>
|
||||
// /// <param name="fullPath">完整文件路径</param>
|
||||
// /// <param name="encoding">编码</param>
|
||||
// /// <returns>文本内容</returns>
|
||||
// public static String LoadResource(String fullPath, Encoding encoding)
|
||||
// {
|
||||
// if (!System.IO.File.Exists(fullPath))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// if (encoding == null)
|
||||
// {
|
||||
// encoding = Encoding.UTF8;
|
||||
// }
|
||||
// return System.IO.File.ReadAllText(fullPath, encoding);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 根据文件名(允许有相对路径)查找并读取文件
|
||||
/// </summary>
|
||||
/// <param name="paths">检索目录</param>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <param name="fullName">完整路径</param>
|
||||
/// <returns></returns>
|
||||
public static String Load(IEnumerable<String> paths, String filename, Encoding encoding, out String fullName)
|
||||
{
|
||||
if (IsLocalPath(filename))
|
||||
{
|
||||
fullName = filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
Int32 index = Resources.FindPath(paths,filename, out fullName); //如果是相对路径,则进行路径搜索
|
||||
if (index == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return LoadResource(fullName, encoding);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 根据文件名(允许有相对路径)查找并读取文件
|
||||
// /// </summary>
|
||||
// /// <param name="paths">检索目录</param>
|
||||
// /// <param name="filename">文件名</param>
|
||||
// /// <param name="encoding">编码</param>
|
||||
// /// <param name="fullName">完整路径</param>
|
||||
// /// <returns></returns>
|
||||
// public static String Load(IEnumerable<String> paths, String filename, Encoding encoding, out String fullName)
|
||||
// {
|
||||
// if (IsLocalPath(filename))
|
||||
// {
|
||||
// fullName = filename;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Int32 index = Resources.FindPath(paths,filename, out fullName); //如果是相对路径,则进行路径搜索
|
||||
// if (index == -1)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// return LoadResource(fullName, encoding);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 是否本地路径表达形式
|
||||
/// </summary>
|
||||
/// <param name="path">路径</param>
|
||||
/// <returns></returns>
|
||||
public static Boolean IsLocalPath(String path)
|
||||
{
|
||||
return !String.IsNullOrEmpty(path) &&
|
||||
(path.IndexOf(System.IO.Path.VolumeSeparatorChar) != -1 //win下判断是否包含卷分隔符(即:) c:\user\Administrator\default.html
|
||||
|| path[0] == '/');
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 是否本地路径表达形式
|
||||
// /// </summary>
|
||||
// /// <param name="path">路径</param>
|
||||
// /// <returns></returns>
|
||||
// public static Boolean IsLocalPath(String path)
|
||||
// {
|
||||
// return !String.IsNullOrEmpty(path) &&
|
||||
// (path.IndexOf(System.IO.Path.VolumeSeparatorChar) != -1 //win下判断是否包含卷分隔符(即:) c:\user\Administrator\default.html
|
||||
// || path[0] == '/');
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 路径处理
|
||||
/// </summary>
|
||||
/// <param name="filename">待处理文件</param>
|
||||
/// <returns>处理后的路径</returns>
|
||||
public static String NormalizePath(String filename)
|
||||
{
|
||||
if (String.IsNullOrEmpty(filename) || filename.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 路径处理
|
||||
// /// </summary>
|
||||
// /// <param name="filename">待处理文件</param>
|
||||
// /// <returns>处理后的路径</returns>
|
||||
// public static String NormalizePath(String filename)
|
||||
// {
|
||||
// if (String.IsNullOrEmpty(filename) || filename.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
List<String> values = new List<String>(filename.Split('/'));
|
||||
// List<String> values = new List<String>(filename.Split('/'));
|
||||
|
||||
for (Int32 i = 0; i < values.Count; i++)
|
||||
{
|
||||
if (values[i] == "." || String.IsNullOrEmpty(values[i]))
|
||||
{
|
||||
values.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
else if (values[i] == "..")
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
values.RemoveAt(i);
|
||||
i--;
|
||||
values.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
// for (Int32 i = 0; i < values.Count; i++)
|
||||
// {
|
||||
// if (values[i] == "." || String.IsNullOrEmpty(values[i]))
|
||||
// {
|
||||
// values.RemoveAt(i);
|
||||
// i--;
|
||||
// }
|
||||
// else if (values[i] == "..")
|
||||
// {
|
||||
// if (i == 0)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// values.RemoveAt(i);
|
||||
// i--;
|
||||
// values.RemoveAt(i);
|
||||
// i--;
|
||||
// }
|
||||
// }
|
||||
|
||||
values.Insert(0, String.Empty);
|
||||
// values.Insert(0, String.Empty);
|
||||
|
||||
return String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), values.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
// return String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), values.ToArray());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -5,9 +5,9 @@
|
||||
#define ALLOWCOMMENT
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 词素分析器
|
||||
@@ -4,9 +4,9 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// TemplateParser
|
||||
@@ -144,7 +144,7 @@ namespace JinianNet.JNTemplate.Parser
|
||||
{
|
||||
throw new Exception.ParseException("Invalid TokenCollection!");//无效的标签集合
|
||||
}
|
||||
return Engine.TagResolver.Resolver(this, tc);
|
||||
return Engine.Resolve(this, tc);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
********************************************************************************/
|
||||
using System;
|
||||
using JinianNet.JNTemplate.Parser;
|
||||
using JinianNet.JNTemplate.Parser.Node;
|
||||
using JinianNet.JNTemplate.Node;
|
||||
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
@@ -64,23 +64,23 @@ namespace JinianNet.JNTemplate
|
||||
Tag[] collection = null;
|
||||
if (!String.IsNullOrEmpty(this._content))
|
||||
{
|
||||
Object value;
|
||||
if (Engine.Cache != null && !String.IsNullOrEmpty(this._key))
|
||||
{
|
||||
if ((value = Engine.Cache.Get(this._key)) != null)
|
||||
{
|
||||
collection = (Tag[])value;
|
||||
}
|
||||
else
|
||||
{
|
||||
collection = ParseTag();
|
||||
Engine.Cache.Set(this._key, collection);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
collection = ParseTag();
|
||||
}
|
||||
//Object value;
|
||||
//if (Engine.Cache != null && !String.IsNullOrEmpty(this._key))
|
||||
//{
|
||||
// if ((value = Engine.Cache.Get(this._key)) != null)
|
||||
// {
|
||||
// collection = (Tag[])value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// collection = ParseTag();
|
||||
// Engine.Cache.Set(this._key, collection);
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
collection = ParseTag();
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JinianNet.JNTemplate.Parser
|
||||
namespace JinianNet.JNTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量域
|
||||
@@ -43,7 +43,18 @@ namespace JinianNet.JNTemplate.Parser
|
||||
public VariableScope(VariableScope parent, IDictionary<String, Object> dictionary)
|
||||
{
|
||||
this._parent = parent;
|
||||
this._dic = dictionary ?? new Dictionary<String, Object>(Engine.ComparerIgnoreCase);
|
||||
if (dictionary == null)
|
||||
{
|
||||
if (Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("IgnoreCase")))
|
||||
{
|
||||
dictionary= new Dictionary<String, Object>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionary = new Dictionary<String, Object>();
|
||||
}
|
||||
}
|
||||
this._dic = dictionary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
Reference in New Issue
Block a user