[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Fri Aug 26 06:27:05 UTC 2005


senger
Fri Aug 26 02:27:05 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data
In directory pub.open-bio.org:/tmp/cvs-serv2547/src/main/org/biomoby/shared/data

Modified Files:
	MobyDataDateTime.java MobyDataXref.java MobyProvisionInfo.java 
Log Message:


moby-live/Java/src/main/org/biomoby/shared/data MobyDataDateTime.java,1.3,1.4 MobyDataXref.java,1.2,1.3 MobyProvisionInfo.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataDateTime.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataDateTime.java	2005/07/22 05:11:54	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataDateTime.java	2005/08/26 06:27:04	1.4
@@ -212,11 +212,22 @@
     }
 
     /** 
-     * Return an ISO 8601 string representing the date/time represented by this Calendar.
-     * ISO 8601 date manipulation in Java 1.2 based on code by Simon Brooke <simon at jasmine.org.uk>
-     * Does not yet deal with fractions of seconds.
+     * Return an ISO 8601 string representing the date/time
+     * represented by this Calendar.
      */
     public String toString(){
+	return getString (value);
+    }
+
+    /**************************************************************************
+     * A utility (static) method converting a GregorianCalendar object
+     * to an ISO 8601 string. ISO 8601 date manipulation in Java 1.2
+     * based on code by Simon Brooke
+     * &lt;simon at jasmine.org.uk&gt;. Does not yet deal with fractions
+     * of seconds.
+     *************************************************************************/
+    public static String getString (GregorianCalendar value) {
+
 	String timef = "'T'hh:mm:ss";
 	String datef = "yyyy-MM-dd";
 	String bothf = "yyyy-MM-dd'T'hh:mm:ss";

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataXref.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataXref.java	2005/05/19 15:57:26	1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataXref.java	2005/08/26 06:27:04	1.3
@@ -100,7 +100,7 @@
 	}
 	else{
 	    throw new IllegalArgumentException("Evidence code to be set (" + 
-					       code + " was not a valid GO code");
+					       code + " is not a valid GO code).");
 	}
     }
 

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyProvisionInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyProvisionInfo.java	2005/05/12 05:17:58	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyProvisionInfo.java	2005/08/26 06:27:04	1.2
@@ -1,8 +1,15 @@
 
 package org.biomoby.shared.data;
 
+import org.biomoby.shared.parser.MobyTags;
+import org.biomoby.shared.parser.MobyPackage;
+
+import org.jdom.Element;
+import org.jdom.output.XMLOutputter;
+import org.jdom.output.Format;
+
 /**
- * Class to hold data corresponginf to the MOBY PIB.
+ * Class to hold data corresponging to the MOBY PIB.
  */
 
 public class MobyProvisionInfo{
@@ -76,46 +83,113 @@
 	return serviceComment;
     }
 
-    /**
-     * For escaping XML meta-characters from attribute strings, 
-     * namely ampersand, double quote, and greater-than
-     */
-    private String escape(String text){
-	if(text == null){
-	    return "";
-	}
-	text = text.replaceAll("&(?!(amp|#x\\d+);)", "&amp;");
-	text = text.replaceAll("<", "&lt;");
-	return text.replaceAll("\"", "&quot;");
-    }
+//     /**
+//      * For escaping XML meta-characters from attribute strings, 
+//      * namely ampersand, double quote, and greater-than
+//      */
+//     private String escape(String text){
+// 	if(text == null){
+// 	    return "";
+// 	}
+// 	text = text.replaceAll("&(?!(amp|#x\\d+);)", "&amp;");
+// 	text = text.replaceAll("<", "&lt;");
+// 	return text.replaceAll("\"", "&quot;");
+//     }
 
     /**
-     * This method formats the available information into an XML format 
-     * suitable for inclusion in a MOBY Object.  If all fields are null, 
-     * an empty string is returned (the MOBY-S API specifies that a ProvisionInformation
-     * block must contain at least one child tag).
+     * This method formats the available information into an XML
+     * format suitable for inclusion in a MOBY Object.
      */
     public String toXML(){
-	StringBuffer xml = new StringBuffer();
-	if(softwareName != null || softwareVersion != null || softwareComment != null){
-	    xml.append("<serviceSoftware software_name=\"" + escape(softwareName) +
-		       "\" software_version=\"" + escape(softwareVersion) +
-		       "\" software_comment=\"" + escape(softwareComment) + "/>\n");
-	}
-	if(dbName != null || dbVersion != null || dbComment != null){
-	    xml.append("<serviceDatabase database_name=\"" + escape(dbName) +
-		       "\" database_version=\"" + escape(dbVersion) +
-		       "\" database_comment=\"" + escape(dbComment) + "/>\n");
-	}
-	if(serviceComment != null){
-	    xml.append("<serviceComment>"+escape(serviceComment)+"</serviceComment>");
-	}
+	XMLOutputter xo = new XMLOutputter();
+ 	xo.setFormat(Format.getPrettyFormat());
+	Element provision = toXMLElement();
+
+	// This is a bad hack - but I do not know how to remove
+	// xmlns=... from this Element properly...
+ 	return xo.outputString (provision).replaceAll
+	    (" xmlns:" + provision.getNamespace().getPrefix() +
+	     "=\"" + provision.getNamespace().getURI() + "\"", "");
+    }
+
+//     /**
+//      * This method formats the available information into an XML format 
+//      * suitable for inclusion in a MOBY Object.  If all fields are null, 
+//      * an empty string is returned (the MOBY-S API specifies that a ProvisionInformation
+//      * block must contain at least one child tag).
+//      */
+
+// 	StringBuffer xml = new StringBuffer();
+// 	if(softwareName != null || softwareVersion != null || softwareComment != null){
+// 	    xml.append("<serviceSoftware software_name=\"" + escape(softwareName) +
+// 		       "\" software_version=\"" + escape(softwareVersion) +
+// 		       "\" software_comment=\"" + escape(softwareComment) + "/>\n");
+// 	}
+// 	if(dbName != null || dbVersion != null || dbComment != null){
+// 	    xml.append("<serviceDatabase database_name=\"" + escape(dbName) +
+// 		       "\" database_version=\"" + escape(dbVersion) +
+// 		       "\" database_comment=\"" + escape(dbComment) + "/>\n");
+// 	}
+// 	if(serviceComment != null){
+// 	    xml.append("<serviceComment>"+escape(serviceComment)+"</serviceComment>");
+// 	}
 	
-	if(xml.length() == 0){
-	    // Empty info, return empty string
-	    return "";
+// 	if(xml.length() == 0){
+// 	    // Empty info, return empty string
+// 	    return "";
+// 	}
+
+// 	return "<ProvisionInformation>\n"+xml.toString()+"</ProvisionInformation>\n";
+
+    /**************************************************************************
+     *
+     *************************************************************************/
+    public Element toXMLElement() {
+	Element provision = MobyPackage.getXMLElement (MobyTags.PROVISIONINFORMATION);
+
+	Element software = MobyPackage.getXMLElement (MobyTags.SERVICESOFTWARE);
+	MobyPackage.setXMLAttribute (software, MobyTags.SOFTWARENAME, softwareName);
+	MobyPackage.setXMLAttribute (software, MobyTags.SOFTWAREVERSION, softwareVersion);
+	MobyPackage.setXMLAttribute (software, MobyTags.SOFTWARECOMMENT, softwareComment);
+	provision.addContent (software);
+
+	Element db = MobyPackage.getXMLElement (MobyTags.SERVICEDATABASE);
+	MobyPackage.setXMLAttribute (db, MobyTags.DATABASENAME, dbName);
+	MobyPackage.setXMLAttribute (db, MobyTags.DATABASEVERSION, dbVersion);
+	MobyPackage.setXMLAttribute (db, MobyTags.DATABASECOMMENT, dbComment);
+	provision.addContent (db);
+
+	if (serviceComment != null) {
+	    Element comment = MobyPackage.getXMLElement (MobyTags.SERVICECOMMENT);
+	    comment.setText (serviceComment);
+	    provision.addContent (comment);
 	}
 
-	return "<ProvisionInformation>\n"+xml.toString()+"</ProvisionInformation>\n";
+	return provision;
+    }
+
+    /**************************************************************************
+     *
+     *************************************************************************/
+    public String toString() {
+	StringBuffer buf = new StringBuffer();
+	buf.append ("Provision information:\n");
+	if (softwareName    != null) buf.append ("   Software name: " + softwareName + "\n");
+	if (softwareVersion != null) buf.append ("   Software version: " + softwareVersion + "\n");
+	if (softwareComment != null) buf.append ("   Software comment: " + softwareComment + "\n");
+	if (dbName    != null) buf.append ("   Database name: " + dbName + "\n");
+	if (dbVersion != null) buf.append ("   Database version: " + dbVersion + "\n");
+	if (dbComment != null) buf.append ("   Database comment: " + dbComment + "\n");
+	if (serviceComment != null) buf.append ("   Service comment: " + serviceComment + "\n");
+	return new String (buf);
+    }
+
+    /**************************************************************************
+     *
+     *************************************************************************/
+    public String format (int indent) {
+	return org.biomoby.shared.Utils.format (this, indent);
     }
+
+
 }




More information about the MOBY-guts mailing list