Commits

Yaw Anokwa  committed f5998d3

expose arbitrary attributes on the <submission> tag

  • Participants
  • Parent commits 522ade3

Comments (0)

Files changed (2)

File core/src/org/javarosa/core/model/SubmissionProfile.java

 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.Hashtable;
 
 import org.javarosa.core.util.externalizable.DeserializationException;
 import org.javarosa.core.util.externalizable.ExtUtil;
+import org.javarosa.core.util.externalizable.ExtWrapMap;
 import org.javarosa.core.util.externalizable.ExtWrapTagged;
 import org.javarosa.core.util.externalizable.Externalizable;
 import org.javarosa.core.util.externalizable.PrototypeFactory;
 	String method;
 	String action;
 	String mediaType;
+	Hashtable<String,String> attributeMap;
 	
 	public SubmissionProfile() {
 		
 	}
 	
-	public SubmissionProfile(IDataReference ref, String method, String action, String mediatype) {
+	public SubmissionProfile(IDataReference ref, String method, String action, String mediatype, Hashtable<String,String> attributeMap) {
 		this.method = method;
 		this.ref = ref;
 		this.action = action;
 		this.mediaType = mediatype;
+		this.attributeMap = attributeMap;
 	}
 
 	public IDataReference getRef() {
 	public String getMediaType() {
 		return mediaType;
 	}
-
+	
+	public String getAttribute(String name) {
+	    return attributeMap.get(name);
+	}
+	
+	@SuppressWarnings("unchecked")
 	public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
 		ref = (IDataReference)ExtUtil.read(in, new ExtWrapTagged(IDataReference.class));
 		method = ExtUtil.readString(in);
 		action = ExtUtil.readString(in);
 		mediaType = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
+		attributeMap = (Hashtable<String, String>)ExtUtil.read(in, new ExtWrapMap(String.class, String.class));
 	}
 
 	public void writeExternal(DataOutputStream out) throws IOException {
 		ExtUtil.writeString(out, method);
 		ExtUtil.writeString(out, action);
 		ExtUtil.writeString(out, ExtUtil.emptyIfNull(mediaType));
+		ExtUtil.write(out, new ExtWrapMap(attributeMap));
 	}
 
 	

File core/src/org/javarosa/xform/parse/SubmissionParser.java

 package org.javarosa.xform.parse;
 
 
+import java.util.Hashtable;
+
 import org.javarosa.core.model.IDataReference;
 import org.javarosa.core.model.SubmissionProfile;
 import org.kxml2.kdom.Element;
  */
 public class SubmissionParser {
 	
-	public SubmissionProfile parseSubmission(String method, String action, IDataReference ref, Element element) {
-		String mediatype = element.getAttributeValue(null,"mediatype");
-		
-		return new SubmissionProfile(ref, method, action, mediatype);
-	}
+    public SubmissionProfile parseSubmission(String method, String action, IDataReference ref, Element element) {
+        String mediatype = element.getAttributeValue(null,"mediatype");
+        Hashtable<String,String> attributeMap = new Hashtable<String,String>();
+        int nAttr = element.getAttributeCount();
+        for ( int i = 0 ; i < nAttr ; ++i ) {
+            String name = element.getAttributeName(i);
+            if ( name.equals("ref")) continue;
+            if ( name.equals("bind")) continue;
+            if ( name.equals("method")) continue;
+            if ( name.equals("action")) continue;
+            String value = element.getAttributeValue(i);
+            attributeMap.put(name, value);
+        }
+        return new SubmissionProfile(ref, method, action, mediatype, attributeMap);
+    }
 	
 	public boolean matchesCustomMethod(String method) {
 		 return false;