Link to home
Start Free TrialLog in
Avatar of AboutLotus
AboutLotus

asked on

Sorting of elements in the html in agent.

This is my Agent

import lotus.domino.*;
import java.io.*;
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();
                              docCat.replaceItemValue("modified",datemod);
                              docCat.save(true);
                              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 = sr.read()) != -1)
                         out.write(c);

                                sr.close();
                                out.close();

            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}


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
NB
SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AboutLotus
AboutLotus

ASKER

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.

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

and it worked.

Thanks guys.

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.
Hey I tried Insertion sort also.Both worked fine, So have splited the points. Thanks a lot guys.

Thanks,
NB