The built-in JavaScript Class can be applied to develop and manage website at high-level.
The table below demonstrates the process of writing data created by table “A” into “A_prop” table and then publishing it. The website's id is "testsite" and the topic’s code is "news.A”.
|
var pstmt = null; var sql = null; try { var site = session.GetSite("testsite"); var topic = site.GetTopicByCode("news.A"); //write data into “A_prop” table. The data should exist in table “A” while doesn’t exist in “A_prop” table //state=2 means it has been already verified while is pending for publishing sql = "insert into A_prop(id,title,siteid,topic,state) select id,name,?,?,2 from A where not exists(select id from A_prop where A.id=A_PROP.id)"; pstmt = session.PrepareStatement(sql); pstmt.SetString(1,site.id); pstmt.SetString(2,topic.id); pstmt.ExecuteUpdate(); session.Commit(); pstmt.Close(); //publish articles of topic “news.A” topic.Build(false); } catch(e) { out.Error(e); } finally { if(pstmt!=null) pstmt.Close(); } |
The table below demonstrates how to use fulltext search engine to get the list of articles daily published,and write the list to "/xml/my.xml". The website's ID is “testsite”.
|
var xmlfile = null; try { xmlfile = new NpsFile("/xml/my.xml"); xmlfile.OpenWriter(false); var site = session.GetSite("testsite"); var query = "publishdate:[NOW/DAY-1DAY TO NOW/DAY"; var arts = site.FTSearch(query,0); for(var i=0;i<arts.count;i++) { var art = arts.GetNthArticle(i); xmlfile.WriteString("<id>"); xmlfile.WriteString(art.id); xmlfile.WriteString("</id>"); xmlfile.WriteString("<title>"); xmlfile.WriteString(art.title); xmlfile.WriteString("</title>"); xmlfile.WriteString("<url>"); xmlfile.WriteString(art.url); xmlfile.WriteString("</url>"); art.Clear(); } } catch(e) { out.Error(e); } finally { if(xmlfile!=null) xmlfile.Close(); } |