Skip to content

Commit

Permalink
DOM documented refactored such that it can be overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Apr 2, 2012
1 parent c457b57 commit b543ebb
Showing 1 changed file with 37 additions and 27 deletions.
Expand Up @@ -46,7 +46,7 @@ public class UserRegistrationResource extends BasicXMLResource {

private static Logger log = Logger.getLogger(UserRegistrationResource.class);

private static String NAMESPACE = "http://www.wyona.org/yanel/user-registration/1.0";
static String NAMESPACE = "http://www.wyona.org/yanel/user-registration/1.0";

private static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";

Expand All @@ -63,33 +63,8 @@ protected InputStream getContentXML(String viewId) throws Exception {
log.debug("requested viewId: " + viewId);
}

// INFO: Build response document
Document doc = null;
try {
doc = org.wyona.commons.xml.XMLHelper.createDocument(NAMESPACE, "registration");
} catch (Exception e) {
throw new Exception(e.getMessage(), e);
}

// Root element
Element rootElement = doc.getDocumentElement();

String email = getEnvironment().getRequest().getParameter("email");
String uuid = getEnvironment().getRequest().getParameter("uuid");
if (email != null) {
processRegistrationRequest(doc, email);
} else if (uuid != null) {
if(activateRegistration(uuid, doc)) {
Element activateSuccessfulE = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "activation-successful"));
} else {
Element activationFailedE = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "activation-failed"));
}
} else {
Element invalidE = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "no-input-yet"));
}

java.io.ByteArrayOutputStream baout = new java.io.ByteArrayOutputStream();
org.wyona.commons.xml.XMLHelper.writeDocument(doc, baout);
org.wyona.commons.xml.XMLHelper.writeDocument(generateResponseDocument(), baout);
return new java.io.ByteArrayInputStream(baout.toByteArray());
}

Expand Down Expand Up @@ -639,6 +614,41 @@ private void addUserToGroups(User user) throws Exception {
}
}
}

/**
* Generate document which is used for response
*/
protected Document generateResponseDocument() throws Exception {
Document doc = getEmptyDocument();
Element rootElement = doc.getDocumentElement();
String email = getEnvironment().getRequest().getParameter("email");
String uuid = getEnvironment().getRequest().getParameter("uuid");
if (email != null) {
processRegistrationRequest(doc, email);
} else if (uuid != null) {
if(activateRegistration(uuid, doc)) {
rootElement.appendChild(doc.createElementNS(NAMESPACE, "activation-successful"));
} else {
rootElement.appendChild(doc.createElementNS(NAMESPACE, "activation-failed"));
}
} else {
rootElement.appendChild(doc.createElementNS(NAMESPACE, "no-input-yet"));
}
return doc;
}

/**
* Get empty document to start with
*/
private Document getEmptyDocument() throws Exception {
Document doc = null;
try {
doc = org.wyona.commons.xml.XMLHelper.createDocument(NAMESPACE, "registration");
} catch (Exception e) {
throw new Exception(e.getMessage(), e);
}
return doc;
}
}

/**
Expand Down

0 comments on commit b543ebb

Please sign in to comment.