• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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
0
AboutLotus
Asked:
AboutLotus
  • 4
  • 2
2 Solutions
 
HemanthaKumarCommented:
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

~Hemanth
0
 
qwaleteeCommented:
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.
0
 
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.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

and it worked.

Thanks guys.

0
 
AboutLotusAuthor Commented:
Even now it is not sorted.

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

Thanks,
NB
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now