Change history for NVelocity-0.4.2.8580

Source: Internet
Author: User

Because there is another development record tool that does not write Development notes on cnblog. however, I think this is a serious problem and I think it is necessary to let more people know how to handle it. Therefore, I also put my previous article on cnblog to spread it widely.

--------------------------------------------------

First Modification

--------------------------------------------------

The use of NVelocity is believed by most netizens because Velocity is used in java, just like me. Therefore, C # requires a similar toolkit. the search result is NVelocity.

I used NVelocity two or three years ago, so I don't think there will be any problems with it. as shown in the following example, you can add a project to search for it on the Internet. expected "It appears that no class was specified as the ResourceManager... ", I am not confused, because it is estimated from experience that a dll reference is not included. as a result, a variety of files and online examples are not correct. A morning passed without knowing it. I felt a little serious and put down my mind and opened my previous project. there are several differences:
1. Previously, the company used vs2010 and vs2008.

2. In the previous project, there was only one NVelocity. dll file and no source code, but this download included multiple files, such as NVelocity. dll, NVelocity. http. dll, and source code.

Okay, I'll take this NVelocity. the dll has been replaced. however, an error is reported during compilation. The version information of the file is displayed, which is. net 4.0, of course, simply use vs2010. however, my situation is a little special. The production environment is. net 2.0 is not too convenient for people to upgrade.. net environment sometimes becomes a disaster-I used to upgrade. net 3.5 has encountered many times, although. net 4.0 is much better. I really don't want to develop anything out of the box.

Well, I 've searched for countless similar questions online. none. during this period, we can see that because NVelocity is maintained by xxx, there are multiple source code versions of NVelocity. at this time, I accidentally found something useful in the example of a netizen. net 2.0 version NVelocity. dll, but its file does not have version information. It is obviously not official, but this Netizen's article shows that the information on how to modify it has been reposted for many times. the file I downloaded is located in (NVelocity-0.4.2.8580 ):

Http://nvelocity.sourceforge.net/

This is the first google search, and the first baidu search is the for. net 4.0 version:

Http://nvelocity.codeplex.com/

The one available by netizens.. net 2.0 is no longer available. to be honest, I cannot understand why sourceforge.net is useless. The files provided by such a famous control on such a famous website are incorrect. for other information I searched, the corresponding bug should have been submitted by someone. I do not know why it was not submitted to sourceforge.net.

Well, no matter how many, at least on my Chinese version of vs2008, You need to modify the following parts for normal use:

File ResourceLocator. cs

Try
{// Clq
Foreach (Assembly a in assemblies)
{
String prefix = a. FullName. Substring (0, a. FullName. IndexOf (","). ToLower ();
String [] names = a. GetManifestResourceNames ();
Try
{// Clq // This is correct. It should be caused by the previous two statements.
Foreach (String s in names)
{

If (s. ToLower (). Equals (fn) | s. ToLower (). Equals (prefix + "." + fn ))
{
This. filename = s;
Assembly =;
IsResource = true;
}
}
}
Catch (System. Exception ex)
{
String s = ex. Message;
System. Console. WriteLine ("bbbbbb:" + s );
} // Clq
}
} Catch (System. Exception ex)
{
String s = ex. Message;
System. Console. WriteLine ("aaaaaa:" + s );
} // Clq

} // If clq

According to my test, the possible cause of an error is that a resource file does not support an interface during the reflection mechanism search, causing it to exit the processing of the remaining resources abnormally. so simply add a few try (ps: Reflection implementation, I'm afraid the efficiency is not high ).

After this modification, the following code can be run.

VelocityEngine vltEngine = new VelocityEngine ();
// 4.0 RuntimeConstants. RESOURCE_LOADER
VltEngine. SetProperty (RuntimeConstants_Fields.RESOURCE_LOADER, "file ");
String path = _ this. Server. MapPath ("~ /");
VltEngine. SetProperty (RuntimeConstants_Fields.FILE_RESOURCE_LOADER_PATH, path );
VltEngine. Init (); // The library code is not modified. An error is reported here.

--------------------------------------------------

Second modification

--------------------------------------------------

After the above modification, many of my tool chains do not support utf8 (or very troublesome). Here, we change the template to a normal gbk encoding method. this version cannot correct the encoding format. I modified a place. the normal code correction code is:

VltEngine. SetProperty (RuntimeConstants_Fields.OUTPUT_ENCODING, "GB2312"); // modify the source code of the NVelocity-0.4.2.8580 before using the two, and preferably with GBK
VltEngine. SetProperty (RuntimeConstants_Fields.INPUT_ENCODING, "GB2312 ");//

This version does not work in nvelocity and needs to be modified:

Template. cs File

// System. IO. StreamReader br = new System. IO. StreamReader (new System. IO. StreamReader (is_Renamed, System. Text. Encoding. GetEncoding (encoding). BaseStream );
System. IO. streamReader br = new System. IO. streamReader (new System. IO. streamReader (is_Renamed, System. text. encoding. getEncoding (encoding )). baseStream, System. text. encoding. getEncoding (encoding); // clq 2014.05.23

Apparently, the author may be a foreigner, and the location specified by the Code is incorrect.

--------------------------------------------------

For your reference, I have put all the modified project files. The debug version is used here. If you have an environment that requires efficiency, compile other versions automatically. there are not many changes to the code. You can search for "// clq" in the full text to find the code. Other codes cannot be changed because of their limited level. I don't plan to make major changes in the future for reasons of stability and don't want to get into trouble. I can use it in my current small project.

Is:

Http://files.cnblogs.com/-clq/NVelocity-0.4.2.8580%5B2014.05.23%5D%5Bclq_modify%5D.zip

--------------------------------------------------

If there are other bugs, I will upload the new version again. I also hope that some netizens will be familiar with the cause of the confusion of nvelocity.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.