DDMS Builder

This experimental tool uses the DDMSence library to create a DDMS 5.0 assertion from form input. The assertion is not a complete record on its own, but is intended for insertion into a Trusted Data Object in the IC Trusted Data Format (TDF) specification. It uses the Component Builder framework. To simplify the example source code, the form only asks for a minimal subset of elements and attributes required for a valid resource. Information submitted through this tool is not retained on the server.

Starred fields (*) are required.


person



organization



How This Works

Compilable source code for this tool is not bundled with DDMSence, because it has dependencies on the Spring Framework (v3.2.2). However, all of the pieces you need create a similar web application are shown below. A basic understanding of Spring MVC will be necessary to understand the code.

  1. A Spring controller, BuilderControl, handles incoming requests at the URI, builder.uri.
  2. package buri.urizone.web.control.ddmsence;
    
    import java.io.ByteArrayOutputStream;
    import java.util.Set;
    
    import nu.xom.Document;
    import nu.xom.Serializer;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.SessionAttributes;
    import org.springframework.web.bind.support.SessionStatus;
    
    import buri.ddmsence.ddms.InvalidDDMSException;
    import buri.ddmsence.ddms.Resource;
    import buri.ddmsence.ddms.ValidationMessage;
    import buri.ddmsence.ddms.security.ism.ISMVocabulary;
    import buri.ddmsence.util.DDMSVersion;
    import buri.ddmsence.util.PropertyReader;
    import buri.ddmsence.util.Util;
    import buri.urizone.web.AbstractControl;
    
    /**
     * Controller class for building DDMS Records
     *
     * @author Brian Uri!
     */
    @Controller
    @SessionAttributes({ "resource" })
    public class BuilderControl extends AbstractControl {
    
    	/**
    	 * Entry point for creating a new builder
    	 */
    	@RequestMapping(value = "/builder.uri", method = RequestMethod.GET)
    	public String newForm(Model model) {
    		Resource.Builder builder = new Resource.Builder();
    		model.addAttribute("resource", builder);
    		return ("builder");
    	}
    
    	/**
    	 * Entry point for saving the builder
    	 */
    	@RequestMapping(value = "/builder.uri", method = RequestMethod.POST)
    	public String build(@ModelAttribute("resource") Resource.Builder builder, BindingResult result,
    		SessionStatus status, Model model) {
    		try {
    			DDMSVersion.setCurrentVersion("5.0");
    			PropertyReader.setProperty("output.json.prettyPrint", "true");
    			PropertyReader.setProperty("output.indexLevel", "1");
    			Resource resource = builder.commit();
    			if (resource == null)
    				throw new InvalidDDMSException("No information was entered to create a DDMS Resource.");
    			// Skipping resource.toXML() so I can control formatting.
    			Document document = new Document(resource.getXOMElementCopy());
    			ByteArrayOutputStream os = new ByteArrayOutputStream();
    			Serializer serializer = new Serializer(os, "ISO-8859-1");
    			serializer.setIndent(3);
    			serializer.setMaxLength(120);
    			serializer.write(document);
    			model.addAttribute("xml", os.toString());
    			model.addAttribute("html", resource.toHTML());
    			model.addAttribute("text", resource.toText());
    			model.addAttribute("json", resource.toJSON());
    			model.addAttribute("warnings", resource.getValidationWarnings());
    			return ("builderResult");
    		}
    		catch (InvalidDDMSException e) {
    			ValidationMessage message = ValidationMessage.newError(e.getMessage(), e.getLocator());
    			String location = Util.isEmpty(message.getLocator()) ? "unknown location" : message.getLocator();
    			result.reject(null, null, "<b>" + message.getType() + "</b> at <code>" + location + "</code>: "
    				+ message.getText());
    		}
    		catch (Exception e) {
    			result.reject(e.getMessage());
    		}
    		return ("builder");
    	}
    
    	/**
    	 * Accessor for the allowable ownerProducer values
    	 */
    	@ModelAttribute(value = "ownerProducers")
    	private Set<String> getOwnerProducers() {
    		return (ISMVocabulary.getEnumerationTokens(DDMSVersion.getVersionFor("5.0"), ISMVocabulary.CVE_OWNER_PRODUCERS));
    	}
    }
  3. The BuilderControl starts by creating a new form bean, Resource.Builder, in the newForm() method. This is a Component Builder which supports the form you see on this page. If you wanted your form to edit an existing Resource, you could initialize the builder by passing in a Resource instance.
  4. The initial form view is rendered. This is the page you are currently viewing. The JSP file also contains the JavaScript code used for client-side validation (with jQuery).
  5. Once the form has been filled in and submitted, the build() method of the BuilderControl is called. This method commits the Resource.Builder. It will fail immediately with an InvalidDDMSException if the Resource is invalid.
  6. If the Resource is invalid, the control class returns to the initial form view, displaying the errors and allowing for editing.
  7. If the Builder succeeds, the Resource is proven to be valid, although there may still be warnings. The warnings and the XML output of the Resource are stored in the model, which is then used to render the Builder Results page.

Back to Top
Back to Documentation