From b543ebb6021da227a54d64d99ed2c6353e6d1902 Mon Sep 17 00:00:00 2001 From: Michael Wechner Date: Mon, 2 Apr 2012 10:20:41 +0200 Subject: [PATCH] DOM documented refactored such that it can be overwritten --- .../UserRegistrationResource.java | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java b/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java index 083ddc222..c62715111 100644 --- a/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java +++ b/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java @@ -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"; @@ -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()); } @@ -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; + } } /**