Sorting of elements in the html in agent.

Posted on 2004-11-09
Last Modified: 2013-12-18
This is my Agent

import lotus.domino.*;
import java.util.*;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

            try {
                  Session session = getSession();
                  AgentContext agentContext = session.getAgentContext();

                        Database db = agentContext.getCurrentDatabase();
                              View view = db.getView("xmlMenu");
                              View viewCat = db.getView("xml");
                              String head = new String();
                              String listElements = "";
                              String docparent = "";
                              String docurl = "";
                              String doctitle = "";
                              String menuCat = "";
                              String tmpString = "";
                              String showBook = "yes";
                              Date td = new Date();
                              String datemod = td.toString();

                              head = "<html><head>";
                              String style1 = "<style><!--#foldheader{cursor:pointer;cursor:hand ; font-weight:bold ;list-style-image:url(fold.gif)}#foldinglist{list-style-image:url(list.gif)}//--></style>";
                              String script1 = "<script language=\"JavaScript1.2\" src=\"treemenu.js\"><!-- --></script></head><body><font face=\"arial\"><ul>";
                              String htmlBeg = head+style1+script1;
                              String htmlEnd="</ul></font></body><script language=\"JavaScript1.2\" src=\"treemenu2.js\"><!-- //--></script></html>";
                              Document docCat = viewCat.getFirstDocument();
                              Item item = docCat.getFirstItem("xml");
                              Vector gv = item.getValues();
                              for(int i=0; i < gv.size()-1 ; i++){
                                    tmpString = "";
                              Object obj = gv.elementAt(i);
                                    String dept = obj.toString();
                  DocumentCollection dc = view.getAllDocumentsByKey(obj);
menuCat = "<li id=\"foldheader\">"+dept+"</li><ul id=\"foldinglist\" style=\"display:none\" style=&{head};>";
                                                      Document doc = dc.getFirstDocument();
            while (doc != null) {
                            docurl = doc.getItemValueString("url");
                                                doctitle = doc.getItemValueString("title");
                                                tmpString = tmpString + "<li><a href=\""+docurl+"\">"+doctitle+"</a></li>"                              doc = dc.getNextDocument(doc);                                                    }
            listElements = listElements +menuCat+tmpString+"</ul>";
                  String xmlString = htmlBeg+listElements+htmlEnd;
                 StringReader sr = new StringReader(xmlString);
      File outputFile = new File("c:\\search\\forms_jsmenu.html");
                                       FileWriter out = new FileWriter(outputFile);
                    int c;
                           while ((c = != -1)


            } catch(Exception e) {

I get this html source file when I run this agent

<html><head><style><!--#foldheader{cursor:pointer;cursor:hand ; font-weight:bold ;list-style-image:url(fold.gif)}#foldinglist{list-style-image:url(list.gif)}//--></style><script language="JavaScript1.2" src="treemenu.js"><!-- --></script></head><body><font face="arial"><ul>
<li id="foldheader">Environmental Health and Safety</li><ul id="foldinglist" style="display:none" style=&{head};>
<li><a href="http://TEST1/my/myforms.nsf/Form/Property+Damage+Report?OpenDocument">Property Damage Report</a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Release+of+Hazardous+Substances+or+Spills+of+Oil+Report?OpenDocument">Release of Hazardous Substances or Spills of Oil Report </a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Report+of+Employee+Occupational+Injury+or+Illness?OpenDocument">Report of Employee Occupational Injury or Illness </a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Report+of+Visit+by+Government+Agency?OpenDocument">Report of Visit by Government Agency</a></li></ul>
<li id="foldheader">Global Facilities Management</li><ul id="foldinglist" style="display:none" style=&{head};>
<li><a href="http://TEST1/my/myforms.nsf/Form/Facility+Request+Form?OpenDocument">Facility Request Form</a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Ergonomic+Request+Form?OpenDocument">Ergonomic Request Form</a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Personal+Stationery+Order+Form?OpenDocument"> Personal Stationery Order Form</a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Notepad+Request+Form?OpenDocument"> Notepad Request Form</a></li>
<li><a href="http://TEST1/my/myforms.nsf/Form/Business+Card+Order+Form?OpenDocument"> Business Card Order Form</a></li></ul>
</ul></font></body><script language="JavaScript1.2" src="treemenu2.js"><!-- //--></script></html>

The  titles are sorted alphabetically but I want the list inside the heading also has to be sorted.

Please help me

Thanks in advance
Question by:AboutLotus
    LVL 24

    Assisted Solution

    Usually set or sortedmap would always give you the result sorted.. Since you are using a vector (which is a hetrogeneous place holder.. there is no straight forward method), you can use insertionsort or some sort methods discussed in this link http:Q_20908354.html

    LVL 31

    Accepted Solution

    You are using getAllDocumentsByKey, which returns results in random order.  You may want to just make sure the xmlMenu view sorts the way you like it, and use getAllEntriesByKey, which is USUALLY soreted the way the view has them, or use viewNavigator, which walks the view in the exact order of its index.

    Author Comment

    Qwaletee I tried like this

             ViewEntryCollection vc = view.getAllEntriesByKey(obj);
    menuCat = "<li id=\"foldheader\">"+dept+"</li><ul id=\"foldinglist\" style=\"display:none\" style=&{head};>";
                         ViewEntry ventry = vc.getFirstEntry();            
                        while (ventry != null) {
                 Document doc = ventry.Document;
                     docurl = doc.getItemValueString("url");
              doctitle =  doc.getItemValueString("title");
                                                               tmpString = tmpString + "<li><a href=\""+docurl+"\">"+doctitle+"</a></li>";
                                                            ventry = dc.getNextEntry(ventry);

    But in the java script I get an error as "No Variable Document defined in interface lotus.domino.ViewEntry.

    help me with this.


    Author Comment

    hey i tried using viewentry.getdocument().getItemValueString("url");

    and it worked.

    Thanks guys.


    Author Comment

    Even now it is not sorted.

    Gimme some suggestions
    LVL 24

    Expert Comment

    Did you try the insertion sort ? The link has a example on how to do it.

    Author Comment

    Hey I tried Insertion sort also.Both worked fine, So have splited the points. Thanks a lot guys.


    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
    Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now