/** * Copyright (C) 2004 Orbeon, Inc. * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU Lesser General Public License as published by the Free Software Foundation; either version * 2.1 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * The full text of the license is available at http://www.gnu.org/copyleft/lesser.html */ import org.orbeon.oxf.processor.SimpleProcessor; import org.orbeon.oxf.processor.ProcessorInputOutputInfo; import org.orbeon.oxf.pipeline.api.PipelineContext; import org.xml.sax.SAXException; import org.xml.sax.ContentHandler; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; import org.orbeon.oxf.xml.dom4j.LocationSAXWriter; import javax.servlet.http.HttpSession; import java.util.Enumeration; import java.util.Properties; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; import org.dom4j.Document; import org.dom4j.XPath; import alexs.common.Utils; import hull.helpdesk.data.QuestionnaireDAO; public class UserInfo extends SimpleProcessor { private static final Attributes NO_ATTRIBUTES = new AttributesImpl(); private static Logger logger = Logger.getLogger(UserInfo.class);; public UserInfo() { addOutputInfo(new ProcessorInputOutputInfo(OUTPUT_DATA)); /* * This is a static const for the string "data" See XPL */ addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); /* * This is where we query the existing database. Primarily for finding * out if the user has answered this questionnaire in the last month. */ } public void generateData(PipelineContext context, ContentHandler contentHandler) throws SAXException { Utils myUtils = new Utils(); DOMConfigurator.configure(myUtils.getLogConfig()); SimpleDateFormat myFormatter = new SimpleDateFormat("MMyy"); Date today = new Date(); String errorStatus = "errorstatus"; String errorValue = "ok"; String errNoUser = "No such user"; String errOk = "ok"; String mmyyStatus="thisMMYY"; /* * This should be the session id from the request packet */ Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); QuestionnaireDAO thisQuestion = new QuestionnaireDAO( "jdbc:mysql://databases.hull.ac.uk:3306/hdq2", "orbeon", "orbeonhd"); /* * Now we need to get hold of the user info associated with this session */ String sessionVal = inputDoc.valueOf("/request/requested-session-id"); String tempUserid = inputDoc.valueOf("request/remote-user"); String useridVal = null; LocationSAXWriter saxWriter= saxWriter = new LocationSAXWriter(); if (tempUserid != null && !tempUserid.equals("")) { if (tempUserid.indexOf("@hull.ac.uk") != -1) { useridVal = useridVal.substring(0, tempUserid .indexOf("@hull.ac.uk")-1); } else { useridVal = tempUserid; } contentHandler.startDocument(); contentHandler.startElement("", "user", "user", NO_ATTRIBUTES); /* * And here we can write the dom4j document ito a content handler */ String alreadyanswered = "alreadyanswered"; String value = "true"; contentHandler.startElement("", alreadyanswered, alreadyanswered, NO_ATTRIBUTES); if (thisQuestion.alreadyAnswered(0, useridVal, myFormatter .format(today)) == true) { contentHandler.characters(value.toCharArray(), 0, value .length()); } else { contentHandler.characters("false".toCharArray(), 0, "false" .length()); } thisQuestion.close(); contentHandler.endElement("", alreadyanswered, alreadyanswered); contentHandler.startElement("", errorStatus, errorStatus, NO_ATTRIBUTES); contentHandler.characters(errOk.toCharArray(), 0, errOk .length()); contentHandler.endElement("", errorStatus, errorStatus); contentHandler.startElement("", mmyyStatus, mmyyStatus, NO_ATTRIBUTES); contentHandler.characters(myFormatter.format(today).toCharArray(), 0, myFormatter.format(today).length()); contentHandler.endElement("", mmyyStatus, mmyyStatus); } else { contentHandler.startElement("", errorStatus, errorStatus, NO_ATTRIBUTES); contentHandler.characters(errNoUser.toCharArray(), 0, errNoUser .length()); contentHandler.endElement("", errorStatus, errorStatus); } /* * Now add the request stuff under the user node */ saxWriter.setContentHandler(contentHandler); saxWriter.write(inputDoc); contentHandler.endElement("", "user", "user"); contentHandler.endDocument(); } }