Sorting of elements in the html in agent.

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AboutLotusAuthor Commented:
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.

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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

and it worked.

Thanks guys.

AboutLotusAuthor Commented:
Even now it is not sorted.

Gimme some suggestions
Did you try the insertion sort ? The link has a example on how to do it.
AboutLotusAuthor Commented:
Hey I tried Insertion sort also.Both worked fine, So have splited the points. Thanks a lot guys.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.