Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r4655 - in branches/WebAdmin/perfSONARWebAdmin: admin/wizard auxiliary auxiliary/wizard

Subject: perfsonar development work

List archive

perfsonar: r4655 - in branches/WebAdmin/perfSONARWebAdmin: admin/wizard auxiliary auxiliary/wizard


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r4655 - in branches/WebAdmin/perfSONARWebAdmin: admin/wizard auxiliary auxiliary/wizard
  • Date: Thu, 23 Oct 2008 06:41:29 -0400

Author: pgerakios
Date: 2008-10-23 06:41:28 -0400 (Thu, 23 Oct 2008)
New Revision: 4655

Added:
branches/WebAdmin/perfSONARWebAdmin/auxiliary/LoadClass.java
branches/WebAdmin/perfSONARWebAdmin/auxiliary/MaskedException.java
branches/WebAdmin/perfSONARWebAdmin/auxiliary/OrderedSet.java

branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/DescendantIterator.java
Modified:
branches/WebAdmin/perfSONARWebAdmin/admin/wizard/Wizard.java
branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/HTMLOutput.java
branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/WizardProperties.java
Log:
0.9.8b added helper classes

Modified: branches/WebAdmin/perfSONARWebAdmin/admin/wizard/Wizard.java
===================================================================
--- branches/WebAdmin/perfSONARWebAdmin/admin/wizard/Wizard.java
2008-10-22 17:00:00 UTC (rev 4654)
+++ branches/WebAdmin/perfSONARWebAdmin/admin/wizard/Wizard.java
2008-10-23 10:41:28 UTC (rev 4655)
@@ -3,12 +3,9 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-
import java.io.IOException;
-
import java.util.Hashtable;
import java.util.Iterator;
-
import java.util.Properties;

import javax.servlet.ServletConfig;
@@ -66,7 +63,7 @@
// The WizardProperties to be configured
private static WizardProperties properties;

- // Hashatable used for seperating the wizard properties into groups
+ // Hashtable used for seperating the wizard properties into groups
private static Hashtable<String, WizardProperties> groupedProperties
= null;

// The handler that will eventually handle the users input
@@ -96,9 +93,9 @@
try {
output = new HTMLOutput();
// Loading the wizard properties
- properties.loadFromXML(sc.getResourceAsStream("/"+
WizardPropertiesPath));
+ properties.loadFromXML( ServicePath +
WizardPropertiesPath);
// Preparing properties into groups
- groupedProperties = prepareProperties(properties);
+ groupedProperties = properties.prepareProperties();
// Check to see if there is a configuration handler
avalable
String cl = checkForExternalHandler();
if (cl != null) {
@@ -184,7 +181,7 @@
}
// If there are no parameters in the request
this means, that
// the user is request the first page of the
servlet
- // So we will show him all properties!!!
+ // so all properties will be displayed.
if (request.getParameterMap().isEmpty()) {
output

.showAllProperties(groupedProperties,
@@ -263,66 +260,8 @@

}

- //
-----------------------------------------------------------------------
- // private methods
-
/**
- * Method used for grouping properties
- *
- * @param loadedProperties
- * The properties loaded from the configuration file
- * @return A hashtable with the group names as keys and
WizardProperties
- * classes as values
- */
- private Hashtable<String, WizardProperties> prepareProperties(
- WizardProperties loadedProperties) {
-
- // Check to see if any property was actually loaded
- if (!loadedProperties.isEmpty()) {
-
- // Creating new hashtable
- Hashtable<String, WizardProperties> groupTable = new
Hashtable<String, WizardProperties>();
- Iterator it = loadedProperties.keySet().iterator();
- // Iterating through the properties so that we can
divide them into
- // groups
- while (it.hasNext()) {
- // Get the property
- WizardProperty property = loadedProperties
- .getWizardProperty((String)
it.next());
- // If the property group has not been set
then it is placed in a
- // generic "Other" group
- if (property.getGroup() == null) {
-
- if (!groupTable.containsKey("Other"))
{
-
- groupTable.put("Other", new
WizardProperties());
- }
-
- ((WizardProperties)
groupTable.get("Other"))
-
.putWizardProperty(property.getKey(), property);
- } else {
- // If the property group does not
exist as a key yet, we
- // create a new key(group)
value(WizardProperties) pair
- if
(!groupTable.containsKey(property.getGroup())) {
-
groupTable.put(property.getGroup(),
- new
WizardProperties());
- }
- // We add the property to the
WizardProperties of that group
- ((WizardProperties)
groupTable.get(property.getGroup()))
-
.putWizardProperty(property.getKey(), property);
- }
-
- }
- return groupTable;
-
- } else {
- return null;
- }
-
- }
-
- /**
- * Method for retreiving the name of a class implementing the
+ * Method for retrieving the name of a class implementing the
* ConfigurationHandler interface. The name of the class should be
places
* inside the servlet.properties file.
*

Added: branches/WebAdmin/perfSONARWebAdmin/auxiliary/LoadClass.java

Added: branches/WebAdmin/perfSONARWebAdmin/auxiliary/MaskedException.java

Added: branches/WebAdmin/perfSONARWebAdmin/auxiliary/OrderedSet.java

Added:
branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/DescendantIterator.java

Modified: branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/HTMLOutput.java
===================================================================
--- branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/HTMLOutput.java
2008-10-22 17:00:00 UTC (rev 4654)
+++ branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/HTMLOutput.java
2008-10-23 10:41:28 UTC (rev 4655)
@@ -11,6 +11,15 @@
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;

+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.jdom.input.DOMBuilder;
+import org.xml.sax.SAXParseException;
/**
* Class used as front end for creation the html output. It hides the html
* creation details from the user making his job easier(hopefully)
@@ -26,12 +35,19 @@
// The doctype of the html document. Currently Html 4.01 transitional
private static final String doctype = "<!DOCTYPE HTML PUBLIC
\"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\";>";

+ private static final String nbsp = "&nbsp;";
// The servlet output stream that will be used to output the html code
private static ServletOutputStream out = null;

// A Linked List containing the various grouped to be configured
private static LinkedList Groups;

+ private static String times(int i )
+ {
+ String ret="";
+ for(int j = 0 ; j < i ; j++ ) ret += nbsp;
+ return ret;
+ }
//
-----------------------------------------------------------------------
// constructors

@@ -93,42 +109,42 @@
it.next();
}
preempt("default.css");
- out.println("<div class=\"properties\">");
- out.println("<br><p>Please fill in the following fields:");
- out.println("<form action=\"ConfigurationWizard\"
method=\"GET\"> ");
- out.println("<input type=\"hidden\" name=\"function\"
value=\""
+ println("<div class=\"properties\">");
+ println("<br><p>Please fill in the following fields:");
+ println("<form action=\"ConfigurationWizard\" method=\"GET\">
");
+ println("<input type=\"hidden\" name=\"function\" value=\""
+ function + "\" >");
- out.println("<input type=\"hidden\" name=\"phase\"
value=\"final\" >");
- out.println("<table align=\"center\">");
+ println("<input type=\"hidden\" name=\"phase\"
value=\"final\" >");
+ println("<table align=\"center\">");
while (it.hasNext()) {
WizardProperty pr =
showProperties.getWizardProperty((String) it
.next());
- out.println("<tr><td>" + pr.getPropertyComment() +
"</td><td>");
+ println("<tr><td>" + pr.getPropertyComment() +
"</td><td>");
String[] values = pr.getAcceptedValues();
if (values != null) {

for (int i = 0; i < values.length; i++) {
String checked =
values[i].equals(pr.getProposedValue()) ? "checked=\"checked\""
: "";
- out.println("<input type=\"radio\"" +
checked + " name=\""
+ println("<input type=\"radio\"" +
checked + " name=\""
+ pr.getKey() + "\"
value=\"" + values[i] + "\">"
+ values[i] +
"</input>");
}
} else {
- out.println("<input type=\"text\" name=\""
+ pr.getKey()
+ println("<input type=\"text\" name=\"" +
pr.getKey()
+ "\" size=60 value=\"" +
pr.getProposedValue()
+ " \"/>");
}
- out.println("</td></tr>");
+ println("</td></tr>");
}
- out.println("</table><p>");
+ println("</table><p>");
out
.println("<p><input type=\"submit\"
name=\"Submit\" value=\"Submit\"></p>");
- out.println("</form> ");
- out.println("</div>");
- out.println("</div>");
- out.println("</body>");
- out.println("</html>");
+ println("</form> ");
+ println("</div>");
+ println("</div>");
+ println("</body>");
+ println("</html>");
out.close();

}
@@ -152,28 +168,28 @@
String phase) throws IOException {

preempt("default.css");
- out.println("<div class=\"continue\">");
- out.println("<br><p><h3>" + property.getPropertyComment());
- out.println("<form action=\"ConfigurationWizard\"
method=\"GET\"> ");
- out.println("<input type=\"hidden\" name=\"function\"
value=\""
+ println("<div class=\"continue\">");
+ println("<br><p><h3>" + property.getPropertyComment());
+ println("<form action=\"ConfigurationWizard\" method=\"GET\">
");
+ println("<input type=\"hidden\" name=\"function\" value=\""
+ function + "\" >");
- out.println("<input type=\"hidden\" name=\"phase\" value=\""
+ phase
+ println("<input type=\"hidden\" name=\"phase\" value=\"" +
phase
+ "\" >");
String[] values = property.getAcceptedValues();
- // out.println("Values=" + values[1]);
+ // println("Values=" + values[1]);
for (int i = 0; i < values.length; i++) {

- out.println("<input type=\"radio\" name=\"" +
property.getKey()
+ println("<input type=\"radio\" name=\"" +
property.getKey()
+ "\" value=\"" + values[i] + "\" >"
+ values[i]
+ "</input>");
}
out
.println("<p><input type=\"submit\"
name=\"Submit\" value=\"Submit\" ></p>");
- out.println("</form> ");
- out.println("</div>");
- out.println("</div>");
- out.println("</body>");
- out.println("</html>");
+ println("</form> ");
+ println("</div>");
+ println("</div>");
+ println("</body>");
+ println("</html>");
out.close();

}
@@ -189,19 +205,210 @@
*/
public void infoPage(String topMessage, String message) throws
IOException {
preemptModified("default.css");
- out.println("<div align=\"left\" class=\"info\">");
- out.println("<br><h4 class=\"info_wizard\">" + topMessage +
"</h4></br>");
+ println("<div align=\"left\" class=\"info\">");
+ println("<br><h4 class=\"info_wizard\">" + topMessage +
"</h4></br>");
if (message != null) {
- out.println("<p class=\"info_wizard\" >" + message +
"</p>");
+ println("<p class=\"info_wizard\" >" + message +
"</p>");
}
- out.println("</div>");
- out.println("</div>");
- out.println("</body>");
- out.println("</html>");
+ println("</div>");
+ println("</div>");
+ println("</body>");
+ println("</html>");
out.close();

}

+ String html = "";
+ private void println( String string ) throws IOException
+ {
+ System.out.println(string);
+ out.println(string);
+ html += string + "\n";
+ }
+
+ private static String btag( String name , String body , String ...
atts )
+ {
+ String ret = "<" + name + " ";
+ if( atts != null && atts.length > 0 )
+ {
+ for( String s : atts ) ret += s + " ";
+ }
+ return ret + ">" + body + "</" + name + ">";
+ }
+
+ private static String att( String attr, String val )
+ {
+ if( val == null ) return "";
+ else return " " + attr + " = \"" + val + "\"";
+ }
+
+
+ private static String table( boolean b , String body ){
return btag("table",body,att("center",(b?"center":null))); }
+
+ private static String div( String cls , String id , String align,
String style , String body )
+ { return
btag("div",body,att("class",cls),att("id",id),att("align",align),att("style",style));
}
+
+ private static String form( String action, String name , String
method , String onsubmit ,String body )
+ { return
btag("form",body,att("action",action),att("name",name),att("method",method),att("onsubmit",onsubmit));
}
+
+ private static String p( String cls, String body ) {
return btag("p",body,att("class",cls)); }
+
+ private static String input( String type , String name , String value
, String onClick , String body )
+ { return
btag("input",body,att("type",type),att("name",name),att("value",value),att("onClick",onClick));
}
+
+ private static String radio_chk( String type , String name , String
value , String onClick , String body )
+ { return
btag("input",body,att("type",type),att("name",name),att("value",value),att("onClick",onClick),att("checked","true"));
}
+
+ private static String input_id( String type , String id , String
value , String onClick , String body )
+ { return
btag("input",body,att("type",type),att("id",id),att("value",value),att("onClick",onClick));
}
+
+ private static String html( String body ) { return btag("html",body); }
+ private static String body( String bd ) { return btag("body",bd); }
+ private static String head( String bd ) { return btag("head",bd); }
+ private static String title( String bd ) { return btag("title",bd); }
+ private static String ul( String bd ) { return btag("ul",bd); }
+ private static String li( String bd ) { return btag("li",bd); }
+ private static String h1( String bd ) { return btag("h1",bd); }
+ private static String a( String href, String bd ) { return
btag("a",bd,att("href",href)); }
+ private static String br( String body ){ return
btag("br",body); }
+ private static String tr( String body ){ return
btag("tr",body); }
+ private static String td( String body ){ return
btag("td",body); }
+ private static String td_col( String body ){ return
btag("td",body,att("colspan","2")); }
+ private static String span( String cls, String body ){ return
btag("span",body,att("class",cls)); }
+
+ private String groupsHtml()
+ {
+ Iterator it = Groups.iterator();
+ String ret = "";
+ while (it.hasNext()) {
+ String group = (String) it.next();
+ if (group.equals("exist")) ret +=
li(a("ConfigurationWizard?function=exist&phase=initial","Exist
Configuration"));
+ else if (group.equals("ls")) ret +=
li(a("ConfigurationWizard?function=ls&phase=initial","LS Registration
Configuration"));
+ else ret += li(a("ConfigurationWizard?function="+
group + "&phase=initial","Configuration"));
+ }
+ return ret;
+ }
+
+ private String showRadio(WizardProperty pr)
+ {
+ String[] values = pr.getAcceptedValues();
+ String body = "";
+ if (values != null)
+
+ for (int i = 0; i < values.length; i++)
+ {
+ body += btag("radio", nbsp + nbsp +
values[i] + nbsp ,
+ att("checked",
(values[i].equals(pr.getProposedValue()) ? "checked": "")),
+
att("name",pr.getKey()),att("value",values[i]));
+
+ }
+ else body= btag("input","",
att("id",(pr.isRequired()?"required":"")),att("class","input_style"),
+
att("onmouseover","setTip(null,'" + pr.getProposedValue() +
"','#D5E9D4')"),
+
att("type",(pr.isPassword()?"password":"text")),att("name",pr.getKey()),att("size","40"),
+
att("value",(pr.isPassword()?"":pr.getProposedValue())));
+
+ return tr(td(pr.getPropertyComment() + span("greenasterisk",
(pr.isRequired()?"*":"")))+body);
+ }
+
+
+ private static String optionsHtml( WizardProperty pr )
+ {
+ String[] values = pr.getAcceptedValues();
+ String ret = "";
+
+ if (values != null) {
+ for (int i = 0; i < values.length; i++)
+ {
+ if (!values[i].equals(pr.getProposedValue()) )
+ {
+ ret +=
radio_chk("radio",pr.getKey(),values[i],"checkIt(this);", times(2) +
values[i] + nbsp);
+ }
+ }
+ }
+ return ret;
+ }
+
+ private String mainBodyBody( Iterator it, WizardProperty pr ,
WizardProperties pro , boolean equalsLS , boolean equalsCheck )
+ {
+ String body = "";
+ if( !equalsLS && !equalsCheck ) body = showRadio(pr);
+ else if ( equalsLS ) it = pro.orderedKeys();
+ boolean check=false,closed=true;
+ final String id = (equalsLS?"useLS": pr.getKey());
+ while (it.hasNext()) {
+ pr = pro.getWizardProperty((String)
it.next());
+ if(pr.getCheck())
+ body +=
tr(td_col(div("inner_properties",pr.getKey(),null,"none;",
+
input("hidden",pr.getProposedValue(),"Vl_" + pr.getKey(),null,"")
+ +
tr(td(pr.getPropertyComment()) + td(nbsp+optionsHtml(pr)+nbsp)
+ ))));
+ else body += showRadio(pr);
+ } //end while
+
+ return div(null,id,null,"display:"+
((equalsCheck||equalsLS)?"none":"block")+";",table(true,body));
+ }
+
+ private String mainBody( Hashtable<String, WizardProperties>
Properties )
+ {
+ List<String> groupnames = new
ArrayList<String>(Properties.keySet());
+ Collections.sort(groupnames);
+ Iterator groupIt = groupnames.iterator();
+ String ret = "";
+ boolean equalsLS,equalsCheck;
+ while (groupIt.hasNext()) {
+
+ String group = (String) groupIt.next();
+ WizardProperties pro = Properties.get(group);
+ Iterator it = pro.orderedKeys();
+ WizardProperty pr = pro.getWizardProperty((String)
it.next()); // First element not hidden
+
+ ret += p("groupheading", group + " Configuration:");
+ equalsLS = group.equals("LS");
+ equalsCheck = pr.getCheck();
+
+ if( equalsLS ) ret += tr(td("Do you wish to
register with an LS?") +
+
td(times(13)+ input("radio","useLS","yes","checkIt(this);", times(2) +
"yes" + nbsp)+
+
times(5) + radio_chk("radio","useLS","no","checkIt(this);", times(14) +
"yes" + nbsp)));
+ else if ( equalsCheck ) ret =
tr(td(pr.getPropertyComment())) + times(21) + optionsHtml(pr)+ times(21);
+
+ if( equalsLS || equalsCheck )
+ ret+= table(true,
(equalsLS?input("hidden","Vl_useLS","yes",null,""):input("hidden","Vl_"+pr.getKey(),pr.getProposedValue(),null,""))
+
+ ret +
mainBodyBody(it,pr,pro,equalsLS,equalsCheck)
+ );
+ else ret+= mainBodyBody(it,pr,pro,false,false);
+ }
+ return ret;
+ }
+
+ public void showAllProperties_(Hashtable<String, WizardProperties>
Properties, String message)throws IOException {
+ println(doctype);
+ println(
+ html(
+ head(getCSS("default.css")) +
+ title("perfSONAR services
configuration wizard") +
+ body(
+ getScript() +
+
//div("banner",null,"top",null,h1("PerfSONAR")) +
+ div("main",null,null,null,
+
//div("config_option",null,"left",null,
+ // ul(
li("Configuration options") + groupsHtml() +
li(a("ConfigurationWizard?function=finish","Finish Configuration"))))+
+ //
+ //private static
String input( String type , String name , String value , String onClick ,
String body )
+
div("top",null,null,null,br(message) +
+
div("properties","properties",null,null,
+
form("action","wizardForm","GET","return checkStarFields()",
+
input("hidden","function","finish",null,"") +
+
mainBody(Properties) +
+
times(126) +
+
btag("input","",att("align","right"),att("type","submit"),
+

att("class","submit_button"),att("id","Button"),att("name","Submit"))

+ )
+ ))
+ ))
+ )
+ );
+ }
+
/**
* Method used for displaying all properties to be configured, divided
* accodring to the group they belong to.
@@ -220,21 +427,21 @@
Collections.sort(groupnames);
Iterator groupIt = groupnames.iterator();
preemptModified("default.css");
- out.println("<div class=\"top\"><br>" + message +
"</br></div>");
- out.println("<div id=\"properties\" class=\"properties\">");
- out.println("<form action=\"Wizard\" name=\"wizardForm\"
method=\"GET\" onsubmit=\"return checkStarFields()\" > ");
+ println("<div class=\"top\"><br>" + message + "</br></div>");
+ println("<div id=\"properties\" class=\"properties\">");
+ println("<form action=\"Wizard\" name=\"wizardForm\"
method=\"GET\" onsubmit=\"return checkStarFields()\" > ");
out
.println("<input type=\"hidden\"
name=\"function\" value=\"finish\" >");
while (groupIt.hasNext()) {
String group = (String) groupIt.next();
- out.println("<p class=\"groupheading\">" + group + "
Configuration:</p>");
+ println("<p class=\"groupheading\">" + group + "
Configuration:</p>");
WizardProperties pro = Properties.get(group);
Iterator it = pro.orderedKeys();
- WizardProperty pr = pro.getWizardProperty((String)
it.next());
+ WizardProperty pr = pro.getWizardProperty((String)
it.next()); // First element not hidden
String display = "block";
String onClick;
if (pr.getCheck() || group.equals("LS")) {
- out.println("<table align=\"center\">");
+ println("<table align=\"center\">");
display = "none";
onClick = " onclick=\"checkIt(this);\"";
if (group.equals("LS")) {
@@ -242,7 +449,7 @@
out
.println("<input
type=\"hidden\" value=\"yes\" id=\"Vl_useLS\" />");
} else {
- out.println("<input type=\"hidden\"
value=\""
+ println("<input type=\"hidden\"
value=\""
+
pr.getProposedValue() + "\" id=\"Vl_"
+ pr.getKey() + "\"
/>");
}
@@ -256,17 +463,28 @@
if (group.equals("LS")) {

out
- .println("<tr><td>Do
you wish to register with an
LS?</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+ .println("<tr><td>Do
you wish to register with an LS?</td><td>" + times(13));
+ //
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+ //
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
//&nbsp;&nbsp;&nbsp;");
out
.println("<input
type=\"radio\" name=\"useLS\" value=\"yes\" "
- +
onClick + ">&nbsp&nbsp;yes&nbsp;</input>");
+ +
onClick + ">" + times(2) + "yes" + nbsp + "</input>");
out
-
.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"radio\" checked
name=\"useLS\" value=\"no\" "
- +
onClick +
">&nbsp&nbsp;no&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</input></td><td>");
+ .println(times(5)+
+
"<input type=\"radio\" checked name=\"useLS\" value=\"no\" "
+ +
onClick + ">" + times(14) + "</input></td><td>");
+
//&nbsp&nbsp;no&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
//&nbsp;&nbsp;&nbsp;&nbsp;

} else {
- out.println("<tr><td>" +
pr.getPropertyComment()
- +
"</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+ println("<tr><td>" +
pr.getPropertyComment()
+ + "</td><td>"+
times(21));
+
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
String[] values =
pr.getAcceptedValues();
if (values != null) {

@@ -274,50 +492,53 @@
String checked =
!values[i].equals(pr

.getProposedValue()) ? "checked=\"checked\""
: "";
- out.println("<input
type=\"radio\"" + checked
+ println("<input
type=\"radio\"" + checked
+ "
name=\"" + pr.getKey() + "\" value=\""
- +
values[i] + "\" " + onClick + ">&nbsp&nbsp;"
- +
values[i] + "&nbsp;</input></td><td>");
+ +
values[i] + "\" " + onClick + ">" + times(2) //&nbsp&nbsp;"
+ +
values[i] + nbsp + "</input></td><td>");
}
}
-
out.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+ println(times(21));
+
//"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i
+ //
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}
- out.println("</td></tr>");
- out.println("</table>");
+ println("</td></tr>");
+ println("</table>");

id = pr.getKey();
if (group.equals("LS")) {
id = "useLS";
}
- out.println("<div id=\"" + id + "\"
style=\"display:"
+ println("<div id=\"" + id + "\"
style=\"display:"
+ display + ";\">");
- out.println("<table align=\"center\">");
+ println("<table align=\"center\">");
} else {
id = "";
- out.println("<div id=\"" + id + "\"
style=\"display:"
+ println("<div id=\"" + id + "\"
style=\"display:"
+ display + ";\">");
- out.println("<table align=\"center\">");
+ println("<table align=\"center\">" );
this.showProperty(pr);

}

- boolean check=false;
+ boolean check=false,closed=true;
while (it.hasNext()) {
pr = pro.getWizardProperty((String)
it.next());
if(pr.getCheck()){
if(!check){
check=true;
}else{
- out.println("</div>");
+ println("</div>");
}
display = "none";
onClick = "
onclick=\"checkIt(this);\"";
- out.println("<input type=\"hidden\"
value=\""
+ println("<tr><td>" +
pr.getPropertyComment()
+ + "</td><td>" + nbsp
);
+
+ println("<input type=\"hidden\"
value=\""
+
pr.getProposedValue() + "\" id=\"Vl_"
+ pr.getKey() + "\"
/>");
id = pr.getKey();
- out.println("<tr><td>" +
pr.getPropertyComment()
- + "</td><td>&nbsp;");
String[] values =
pr.getAcceptedValues();
if (values != null) {

@@ -325,45 +546,75 @@
String checked =
!values[i].equals(pr

.getProposedValue()) ? "checked=\"checked\""
: "";
- out.println("<input
type=\"radio\"" + checked
+ println("<input
type=\"radio\"" + checked
+ "
name=\"" + pr.getKey() + "\" value=\""
- +
values[i] + "\" " + onClick + ">&nbsp;&nbsp;"
- +
values[i] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</input>");
+ +
values[i] + "\" " + onClick + ">" + nbsp + nbsp +
+
values[i] + times(5)+ "</input>");
}
}
- out.println("&nbsp;");
- out.println("</td></tr>");
- out.println("<tr ><td
colspan=\"2\"><div class=\"inner_properties\" id=\"" + id + "\"
style=\"display:"+ display + ";\"><table>");
+ println(nbsp);
+ println("</td></tr></td></tr>");
+ println("<tr ><td colspan=\"2\"><div
class=\"inner_properties\" id=\"" + id + "\" style=\"display:"+ display +
";\">");
+ closed=false;
}else{
if(pr.getDependency()==null && check){
-
out.println("</table></div></td></tr>");
+
//println("</table></div></td></tr>");
check=false;
}
this.showProperty(pr);
}
-
-
}
if(check){
- out.println("</table></div></td></tr>");
+ println("</table></div></td></tr>");
}

- out.println("</table>");
- out.println("</div>");
+ println("</table>");
+ println("</div>");
}
- for(int i=0;i<126;i++){
- out.print("&nbsp;");
- }
- out.println("<input align=\"right\" input id=\"Button\"
class=\"submit_button\" type=\"submit\" name=\"Submit\" value=\"Submit
Changes\" />");
- out.println("</form> ");
- out.println("</div>");
- out.println("</div>");
- out.println("</body>");
- out.println("</html>");
+ out.print(times(126));
+ println("<input align=\"right\" input id=\"Button\"
class=\"submit_button\" type=\"submit\" name=\"Submit\" value=\"Submit
Changes\" />");
+ println("</form> ");
+ println("</div>");
+ println("</div>");
+ println("</body>");
+ println("</html>");
out.close();
-
+ //parse(html,false);
}

+ private static org.jdom.Document parse( String s , boolean aware ) {
+ DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = null;
+ DOMBuilder jbuilder = null;
+
+ factory.setNamespaceAware(aware);
+ try {
+ builder = factory.newDocumentBuilder();
+ jbuilder = new DOMBuilder();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+
+ try
+ {
+ return jbuilder.build(builder.parse( new
java.io.StringBufferInputStream(s)));
+ }
+ catch (SAXParseException e)
+ { // well-formedness error
+ System.out.println(" ----- WEB-ADMIN : INTERNAL BUG -
HTMLGEN");
+ System.out.println(e.getMessage()
+ + " at line " + e.getLineNumber()
+ + ", column " + e.getColumnNumber());
+ return null;
+ }
+ catch( Throwable t)
+ {
+ System.out.println(" ----- WEB-ADMIN : INTERNAL BUG -
HTMLGEN");
+ t.printStackTrace();
+ return null;
+ }
+}
+
//
-----------------------------------------------------------------------
// private methods

@@ -374,20 +625,20 @@
* @throws IOException
*/
private void preempt(String cssFile) throws IOException {
- out.println(doctype);
- out.println("<html>");
- out.println("<head>" + getCSS(cssFile));
- out.println("<title>");
- out.println("perfSONAR services configuration wizard");
- out.println("</title>");
- out.println("<body>");
- out.println("<div align=\"top\" class=\"banner\">");
- out.println("<h1>PerfSONAR");
- out.println("</div>");
- out.println("<div class=\"main\">");
- out.println("<div align=\"left\" class=\"config_option\">");
- out.println("<ul>");
- out.println("<li>Configuration options</li>");
+ println(doctype);
+ println("<html>");
+ println("<head>" + getCSS(cssFile));
+ println("<title>");
+ println("perfSONAR services configuration wizard");
+ println("</title>");
+ println("<body>");
+ println("<div align=\"top\" class=\"banner\">");
+ println("<h1>PerfSONAR");
+ println("</div>");
+ println("<div class=\"main\">");
+ println("<div align=\"left\" class=\"config_option\">");
+ println("<ul>");
+ println("<li>Configuration options</li>");
Iterator it = Groups.iterator();
while (it.hasNext()) {
String group = (String) it.next();
@@ -401,7 +652,7 @@
.println("<li><a
href=\"ConfigurationWizard?function=ls&phase=initial\">LS Registration
Configuration</a></li>");
} else {

- out.println("<li><a
href=\"ConfigurationWizard?function="
+ println("<li><a
href=\"ConfigurationWizard?function="
+ group + "&phase=initial\">"
+ group
+ " Configuration</a></li>");
}
@@ -409,8 +660,8 @@
}
out
.println("<li><a
href=\"ConfigurationWizard?function=finish\">Finish Configuration</a></li>");
- out.println("</ul>");
- out.println("</div>");
+ println("</ul>");
+ println("</div>");
}

/**
@@ -421,15 +672,15 @@
* @throws IOException
*/
private void preemptModified(String cssFile) throws IOException {
- out.println(doctype);
- out.println("<html>");
- out.println("<head>" + getCSS(cssFile));
- out.println("<title>");
- out.println("perfSONAR services configuration wizard");
- out.println("</title>");
- out.println("<body>");
- out.println(getScript());
- out.println("<div class=\"main\">");
+ println(doctype);
+ println("<html>");
+ println("<head>" + getCSS(cssFile));
+ println("<title>");
+ println("perfSONAR services configuration wizard");
+ println("</title>");
+ println("<body>");
+ println(getScript());
+ println("<div class=\"main\">");
}

/**
@@ -463,6 +714,7 @@

/**
* Method called by the shoaAllProperties method
+ * Prints a list of possible values - radio buttons
*
* @param pr
* The wizard property
@@ -477,20 +729,19 @@
fill = "*";
required="required";
}
- out.println("<tr><td>" + pr.getPropertyComment()+"<span
class=\"greenasterisk\" >"+fill+"</span></td><td>");
+ println("<tr><td>" + pr.getPropertyComment()+"<span
class=\"greenasterisk\" >"+fill+"</span></td><td>");
String[] values = pr.getAcceptedValues();
if (values != null) {

for (int i = 0; i < values.length; i++) {
String checked =
values[i].equals(pr.getProposedValue()) ? "checked=\"checked\""
: "";
- out.println("<input type=\"radio\"" + checked
+ " name=\""
- + pr.getKey() + "\" value=\""
+ values[i] + "\"> &nbsp;&nbsp;"
- + values[i] +
"&nbsp;</input>");
+ println("<input type=\"radio\"" + checked + "
name=\""
+ + pr.getKey() + "\" value=\""
+ values[i] + "\">" + nbsp + nbsp
+ + values[i] + nbsp +
"</input>");
}
} else {
String type = "text";
-
String value=pr.getProposedValue();
String valueText="value=\""
+ value+ " \"";
@@ -499,12 +750,12 @@
valueText="value=\"\" ";
value="";
}
- out.println("<input id=\""+required+"\"
class=\"input_style\" onmouseover=\"setTip(null,'"
+ println("<input id=\""+required+"\"
class=\"input_style\" onmouseover=\"setTip(null,'"
+value + "','#D5E9D4')\" type=\"" +
type
+ "\" name=\"" + pr.getKey() + "\"
size=40 "+valueText+" />");

}
- out.println("</td></tr>");
+ println("</td></tr>");

}


Modified:
branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/WizardProperties.java
===================================================================
---
branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/WizardProperties.java
2008-10-22 17:00:00 UTC (rev 4654)
+++
branches/WebAdmin/perfSONARWebAdmin/auxiliary/wizard/WizardProperties.java
2008-10-23 10:41:28 UTC (rev 4655)
@@ -14,6 +14,10 @@
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
+import java.util.SortedSet;
+import java.util.Set;
+import java.util.Hashtable;
+import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -26,6 +30,8 @@
import org.jdom.output.XMLOutputter;
import org.xml.sax.SAXException;

+import perfSONARWebAdmin.auxiliary.OrderedSet;
+
/**
* A dirty little hack, to extend properties functionality. Old
functionalities
* are preserverd but new functionality has been added, regarding xml
properties
@@ -63,6 +69,7 @@
* <!ELEMENT AcceptedValue (#PCDATA) > ]>
*
* @author Michalis Michael, CyNet
+ * @author Prodromos Gerakios, GRNET
*
*/
@SuppressWarnings("serial")
@@ -117,6 +124,8 @@
// key(property name) of the property
private Map<String, String> orderedProperties;

+ private OrderedSet sorted = null;
+
//
-----------------------------------------------------------------------
// class constructors

@@ -142,18 +151,21 @@

}

+ public Set keySet()
+ {
+ return sorted;
+ }
+
//
-----------------------------------------------------------------------
// public methods

/*
* (non-Javadoc)
*
- * @see java.util.Properties#loadFromXML(java.io.InputStream)
*/
- @Override
- public synchronized void loadFromXML(InputStream in) throws
IOException,
- InvalidPropertiesFormatException {
-
+ public synchronized void loadFromXML(String fin) throws Exception
+ {
+ FileInputStream in = new FileInputStream(new File(fin));
DocumentBuilderFactory dbfactory =
DocumentBuilderFactory.newInstance();
dbfactory.setValidating(true);
DocumentBuilder parser = null;
@@ -170,10 +182,10 @@
propertiesDoc = jparser.build(parser.parse(in));
} catch (SAXException e) {
e.printStackTrace();
- throw new InvalidPropertiesFormatException(
+ throw new IOException(
"Error parsing properties file");
}
- populateProperties(propertiesDoc.getRootElement());
+ populateProperties(propertiesDoc.getRootElement(),fin);

}

@@ -276,6 +288,21 @@

}

+ private static String att(Element elt, String attribute, String def )
+ {
+ Attribute attr = elt.getAttribute(attribute);
+ return ((attr!=null)?attr.getValue():def);
+ }
+
+ private static String[] textList( List elts )
+ {
+ int i=elts.size();
+ if( elts == null || i == 0 ) return null;
+ String[] ret = new String[i]; i = 0;
+ for( Object o : elts ) ret[i++] = (
((Element)o).getText().trim() );
+ return ret;
+ }
+
//
-----------------------------------------------------------------------
// private methods

@@ -286,79 +313,82 @@
* The root element of the document read from the xml
properties
* file
*/
- private void populateProperties(Element root) {
+ private void populateProperties(Element root,String file) {

List propertiesList = root.getChildren("property");
- if (!propertiesList.isEmpty()) {
- Iterator it = propertiesList.iterator();
- while (it.hasNext()) {
- Element property = (Element) it.next();
- WizardProperty pr = new WizardProperty();
- Element entry = property.getChild("entry");
+
+ if (propertiesList.isEmpty())
+ {
+ System.out.println("------ WEB-ADMIN WARNING -- EMPTY
wizard.properties ------------");
+ return;
+ }
+
+ DescendantIterator it = new
DescendantIterator(propertiesList,file);
+ Element entry,group,property;
+ WizardProperty pr;
+ sorted = new OrderedSet();
+ while (it.hasNext())
+ {
+ property = (Element) it.next();
+ entry = property.getChild("entry");
+ group = property.getChild("Group");
+
+ pr = new WizardProperty();
pr.setPropertyValue(entry.getText());
- if (entry.getAttribute("password") != null) {
-
pr.setPassword(Boolean.parseBoolean(entry
-
.getAttributeValue("password")));
- } else {
- pr.setPassword(false);
- }
- if (entry.getAttribute("required") != null) {
-
pr.setRequired(Boolean.parseBoolean(entry
-
.getAttributeValue("required")));
- } else {
- pr.setRequired(false);
- }
+
pr.setPassword(Boolean.parseBoolean(att(entry,"password","false")));
+
pr.setRequired(Boolean.parseBoolean(att(entry,"required","false")));

pr.setPropertyKey(entry.getAttributeValue("key").trim());

pr.setPropertyComment(property.getChild("Comment").getText());
- pr
-
.setPropertyValue(property.getChild("entry").getText()
- .trim());
-
pr.setProposedValue(property.getChild("ProposedValue")
- .getText().trim());
-
pr.setGroup(property.getChild("Group").getText().trim());
-
pr.setOrder(property.getChild("Group").getAttributeValue(
- "order").trim());
- Attribute
attr=property.getChild("Group").getAttribute(
- "dependsOn");
- if(attr!=null){
- pr.setDependency(attr.getValue());
- }else{
- pr.setDependency(null);
- }
-
- attr =
property.getChild("Group").getAttribute(
- "check");
- if (attr != null) {
- Boolean b =
Boolean.parseBoolean(attr.getValue().trim());
- pr.setCheck(b.booleanValue());
- } else {
- pr.setCheck(false);
- }
+
pr.setPropertyValue(property.getChild("entry").getText().trim());
+
pr.setProposedValue(property.getChild("ProposedValue").getText().trim());
+ pr.setDependency(att(group,"dependsOn",null));
+
pr.setCheck(Boolean.parseBoolean(att(group,"check","false")));
+ pr.setGroup(group.getText().trim());
+ pr.setOrder(att(group,"order",null));
+
pr.setAcceptedValues(textList(property.getChildren("AcceptedValue")));

- List acceptedList =
property.getChildren("AcceptedValue");
- if (acceptedList.isEmpty()) {
- pr.setAcceptedValues(null);
- } else {
- Iterator acceptIt =
acceptedList.iterator();
- LinkedList<String> acceptedValues =
new LinkedList<String>();
- while (acceptIt.hasNext()) {
-
- acceptedValues.add((String)
((Element) acceptIt.next())
-
.getText().trim());
- }
- pr.setAcceptedValues((String[])
acceptedValues
- .toArray(new
String[acceptedValues.size()]));
- }
-
properties.put(pr.getKey(), pr);
orderedProperties.put(pr.getOrder(),
pr.getKey());
this.put(pr.getKey(), pr.getValue());
+ sorted.add(pr);
+ }
+ }

- }
- } else {
- // To Do
- }
+
+ public Hashtable<String, WizardProperties> prepareProperties()
+ {
+ if(isEmpty()) return null;
+ Hashtable<String, WizardProperties> groupTable = new Hashtable<String,
WizardProperties>();
+ Iterator it = keySet().iterator();
+ WizardProperties other = new WizardProperties();
+ WizardProperties wp = null;
+ WizardProperty property = null;
+ String lastGroup = null;
+ String thisGroup = null;
+ while (it.hasNext())
+ {
+ property = (WizardProperty) it.next();
+ //getWizardProperty((String) it.next());
+ if (property.getGroup() == null)
other.putWizardProperty(property.getKey(),property);
+ else {
+ thisGroup = property.getGroup();
+ if( lastGroup == null ||
!lastGroup.equals(thisGroup) )
+ {
+ if
(!groupTable.containsKey(thisGroup))
+ {
+ wp = new WizardProperties();
+ groupTable.put(thisGroup,wp);
+ lastGroup = thisGroup;
+ }
+ else wp = (WizardProperties)
groupTable.get(thisGroup);
+ }
+
wp.putWizardProperty(property.getKey(), property);
+ //System.out.println("--------------
Placing: " + property.getKey() + " in group " + thisGroup );
+ }

+ }
+ if( other.size() > 0 ) groupTable.put("Other" , new
WizardProperties());
+ return groupTable;
}

/**
@@ -422,11 +452,11 @@
return propertiesDoc;
}

+
/**
* @param args
*/
public static void main(String[] args) {
- // TODO Auto-generated method stub
@SuppressWarnings("unused")
DocumentBuilder parser = null;
try {
@@ -455,10 +485,10 @@

}

- FileOutputStream fs = new FileOutputStream(new File(
- "wizard.properties"));
- properties.storeToXML(fs, "hello");
- fs.close();
+// FileOutputStream fs = new FileOutputStream(new File(
+// "wizard.properties"));
+// properties.storeToXML(fs, "hello");
+// fs.close();

System.out.println("Finish");
} catch (IOException e) {



  • perfsonar: r4655 - in branches/WebAdmin/perfSONARWebAdmin: admin/wizard auxiliary auxiliary/wizard, svnlog, 10/23/2008

Archive powered by MHonArc 2.6.16.

Top of Page