[Rapforums-developer] src/source/edu/fullcoll/uportal/channels/rap/forum/commands AdminModeCommand.j
Status: Beta
Brought to you by:
brippe
From: Brad R. <br...@us...> - 2005-02-04 00:56:46
|
Update of /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17601 Modified Files: AdminModeCommand.java ForumModeCommand.java IForumCommand.java MainModeCommand.java PostModeCommand.java SearchModeCommand.java ThreadModeCommand.java UnAuthorizedModeCommand.java Log Message: no message Index: ThreadModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/ThreadModeCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ThreadModeCommand.java 21 Jul 2004 17:15:04 -0000 1.4 --- ThreadModeCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 23,27 **** package edu.fullcoll.uportal.channels.rap.forum.commands; - import org.jasig.portal.ChannelRuntimeData; import org.jasig.portal.utils.XSLT; import org.xml.sax.ContentHandler; --- 23,26 ---- *************** *** 32,36 **** import edu.fullcoll.uportal.channels.rap.forum.filter.IFilterManager; import edu.fullcoll.uportal.channels.rap.forum.filter.RAPFilterManager; - import edu.fullcoll.uportal.channels.rap.forum.database.RAPDB; import edu.fullcoll.uportal.channels.rap.forum.xml.ViewXMLFactory; import edu.fullcoll.uportal.channels.rap.forum.xml.RAPViewXML; --- 31,34 ---- *************** *** 50,54 **** * * @author Chris Pereda (cp...@fu...) ! * @version 0.8.3 $Revision %G% */ public class ThreadModeCommand implements IForumCommand { --- 48,52 ---- * * @author Chris Pereda (cp...@fu...) ! * @version 0.9.0 $Revision %G% */ public class ThreadModeCommand implements IForumCommand { *************** *** 96,100 **** forumsRootElement.getChild("rapforum").getChild("rapcomments").getChildren().iterator(); ! //get and filter the suject and body tags Element e = null; String subject = null; --- 94,98 ---- forumsRootElement.getChild("rapforum").getChild("rapcomments").getChildren().iterator(); ! //get and filter the subject and body tags Element e = null; String subject = null; *************** *** 113,117 **** Element nameElement = new Element("username"); ! nameElement.setText((session.staticData).getPerson().getAttribute("displayName") + ""); forumsRootElement.addContent(nameElement); --- 111,119 ---- Element nameElement = new Element("username"); ! String username = (String) (session.staticData).getPerson().getAttribute("displayName"); ! if(username == null) ! username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); ! ! nameElement.setText(username); forumsRootElement.addContent(nameElement); *************** *** 129,133 **** xml += writer.toString(); //System.out.println("ThreadMode "+xml); //DEBUG ! // Transform xml XSLT xslt = new XSLT(forum); --- 131,135 ---- xml += writer.toString(); //System.out.println("ThreadMode "+xml); //DEBUG ! // Transform xml XSLT xslt = new XSLT(forum); *************** *** 135,138 **** --- 137,142 ---- xslt.setXSL("CForum.ssl", stylesheet, (session.runtimeData).getBrowserInfo()); xslt.setStylesheetParameter("baseActionURL", (session.runtimeData).getBaseActionURL()); + // I'm sure there is a better way than this to get the base url + xslt.setStylesheetParameter("serverInfo", forum.getUportalBaseURL()); xslt.setTarget(out); xslt.transform(); Index: AdminModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/AdminModeCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AdminModeCommand.java 21 Jul 2004 17:14:45 -0000 1.4 --- AdminModeCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 24,34 **** import org.jasig.portal.utils.XSLT; import org.xml.sax.ContentHandler; import org.jasig.portal.PortalException; import org.jasig.portal.groups.IGroupMember; - import org.jasig.portal.security.IAuthorizationPrincipal; - import org.jasig.portal.security.IPermission; import org.jasig.portal.services.GroupService; import org.jasig.portal.services.LogService; import edu.fullcoll.uportal.channels.rap.forum.CForum; --- 24,36 ---- import org.jasig.portal.utils.XSLT; + import org.w3c.dom.Document; import org.xml.sax.ContentHandler; + import org.xml.sax.InputSource; + import org.xml.sax.SAXException; import org.jasig.portal.PortalException; import org.jasig.portal.groups.IGroupMember; import org.jasig.portal.services.GroupService; import org.jasig.portal.services.LogService; + import org.jasig.portal.ChannelRuntimeData; import edu.fullcoll.uportal.channels.rap.forum.CForum; *************** *** 38,41 **** --- 40,44 ---- import edu.fullcoll.uportal.channels.rap.forum.database.RAPDB; import edu.fullcoll.uportal.channels.rap.forum.IDManager; + import edu.fullcoll.uportal.channels.rap.forum.permissions.RapPermissionsManager; import edu.fullcoll.uportal.channels.rap.forum.xml.RAPViewXML; import edu.fullcoll.uportal.channels.rap.forum.xml.ViewXMLFactory; *************** *** 43,48 **** --- 46,55 ---- import edu.fullcoll.uportal.channels.rap.forum.ForumSessionData; + import org.jdom.Element; import org.jdom.output.XMLOutputter; import java.io.StringWriter; + import java.util.Iterator; + import javax.xml.parsers.DocumentBuilder; + import javax.xml.parsers.DocumentBuilderFactory; *************** *** 51,57 **** * * @author Brad Rippe (br...@fu...) and Chris Pereda (cp...@fu...) ! * @version 0.8.3 $Revision %G% */ public class AdminModeCommand implements IForumCommand { /** * This method provides the administration functionality by rendering --- 58,65 ---- * * @author Brad Rippe (br...@fu...) and Chris Pereda (cp...@fu...) ! * @version 0.9.0 $Revision %G% */ public class AdminModeCommand implements IForumCommand { + /** * This method provides the administration functionality by rendering *************** *** 66,69 **** --- 74,78 ---- String stylesheet = "admin"; StringWriter writer = new StringWriter(INITITAL_BUFFER_SIZE); + boolean authorized = true; try { *************** *** 98,156 **** if (type.equals("createForum")) { ! ! IAuthorizationPrincipal ap = session.staticData.getAuthorizationPrincipal(); ! IPermission[] perms = ap.getAllPermissions(forum.getOwnerToken(), "Create", (session.runtimeData).getParameter("forum") ); ! ! for(int i = 0; i < perms.length; i++) { ! if(perms[i].getType().equals("GRANT")) { ! if (isAdmin || isManager) { ! writer.write("<type>createForum</type>"); ! RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); ! } else { ! writer.write("<type>noAccess</type>"); ! } ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to create new forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! break; ! } ! } } else if (type.equals("prePerm")) { ! IAuthorizationPrincipal ap = session.staticData.getAuthorizationPrincipal(); ! IPermission[] perms = ap.getAllPermissions(forum.getOwnerToken(), "Create", (session.runtimeData).getParameter("forum") ); ! ! for(int i = 0; i < perms.length; i++) { ! if(perms[i].getType().equals("GRANT")) { ! if (isAdmin || isManager) { ! //go to select forum to assign permissions to ! //fix xml here ! //need to get a list of forum names here to add to the xml ! writer.write("<type>prePerm</type>"); ! RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); ! RAPDB dbCon = new RAPDB(); ! outputter.output(viewXML.getForumsXML(1, dbCon.getForumCount()).detachRootElement(), writer); ! } else { ! writer.write("<type>noAccess</type>"); ! } ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to assign permissions to forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! break; ! } ! } } else if (type.equals("adminForum")) { if (isAdmin || isManager) { //display main administration view --- 107,154 ---- if (type.equals("createForum")) { ! ! boolean canCreateForum = RapPermissionsManager.hasPermissionsForForum(session.staticData.getAuthorizationPrincipal(), ! "Create", (String) session.runtimeData.getParameter("forum")); ! // Users must also be part of the Rap Administrator's to create forums ! if ((isAdmin || isManager) && canCreateForum) { ! writer.write("<type>createForum</type>"); ! RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to create new forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! authorized = false; ! } } else if (type.equals("prePerm")) { ! ! // Users must also be part of the Rap Administrators or Rap Managers ! // to assign permissions - currently all administrators can assign permissions ! if (isAdmin || isManager) { ! //go to select forum to assign permissions to ! //fix xml here ! //need to get a list of forum names here to add to the xml ! writer.write("<type>prePerm</type>"); ! RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); ! RAPDB dbCon = new RAPDB(); ! outputter.output(viewXML.getForumsXML(1, dbCon.getForumCount(), null).detachRootElement(), writer); ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to assign permissions to forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! authorized = false; ! } } else if (type.equals("adminForum")) { + // Main Administration View for Forum Administators if (isAdmin || isManager) { //display main administration view *************** *** 164,169 **** } else if (type.equals("doForum")) { ! ! if (isAdmin || isManager) { //create the forum String name = (session.runtimeData).getParameter("name"); --- 162,169 ---- } else if (type.equals("doForum")) { ! boolean canCreateForum = RapPermissionsManager.hasPermissionsForForum(session.staticData.getAuthorizationPrincipal(), ! "Create", (String) session.runtimeData.getParameter("forum")); ! // Users must also be part of the Rap Administrator's to create forums ! if ((isAdmin || isManager) && canCreateForum) { //create the forum String name = (session.runtimeData).getParameter("name"); *************** *** 172,214 **** validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE, session); ! } else { ! writer.write("<type>noAccess</type>"); ! } ! ! } else if (type.equals("deleteForum")) { ! ! IAuthorizationPrincipal ap = session.staticData.getAuthorizationPrincipal(); ! IPermission[] perms = ap.getAllPermissions(forum.getOwnerToken(), "Delete", (session.runtimeData).getParameter("forum") ); ! ! for(int i = 0; i < perms.length; i++) { ! if(perms[i].getType().equals("GRANT")) { ! ! if (isAdmin || isManager) { ! writer.write("<type>deleteForum</type>"); ! //delete forum ! RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(rapViewXML.getCategoryXML().detachRootElement(), writer); ! RAPDB dbCon = new RAPDB(); ! outputter.output(rapViewXML.getForumsXML(1, dbCon.getForumCount()).detachRootElement(), writer); ! String name = (session.runtimeData).getParameter("name"); ! //validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE); ! } else { ! writer.write("<type>noAccess</type>"); ! } ! ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to delete forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! break; ! } } } else if (type.equals("doDeleteForum")) { ! ! if (isAdmin || isManager) { //delete category writer.write("<type>doDeleteForum</type>"); --- 172,213 ---- validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE, session); ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to create new forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! authorized = false; } + } else if (type.equals("deleteForum")) { + boolean canDeleteForum = RapPermissionsManager.hasPermissionsForForum(session.staticData.getAuthorizationPrincipal(), + "Delete", (String) session.runtimeData.getParameter("forum")); + // Users must also be part of the Rap Administrator's to create forums + if ((isAdmin || isManager) && canDeleteForum) { + writer.write("<type>deleteForum</type>"); + //delete forum + RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); + XMLOutputter outputter = new XMLOutputter(); + outputter.output(rapViewXML.getCategoryXML().detachRootElement(), writer); + outputter.output(rapViewXML.getForumNameXML().detachRootElement(), writer); + String name = (session.runtimeData).getParameter("name"); + //validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE); + } else { + // Unauthorized access to delete + UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); + session.unauthorizedMsg = "Sorry, you do not have appropriate permission to delete forums.<br/><br/>"+ + "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; + command.execute(forum, session, out); + authorized = false; + } + } else if (type.equals("doDeleteForum")) { ! ! boolean canDeleteForum = RapPermissionsManager.hasPermissionsForForum(session.staticData.getAuthorizationPrincipal(), ! "Delete", (String) session.runtimeData.getParameter("forum")); ! ! // Users must also be part of the Rap Administrator's to create forums ! if ((isAdmin || isManager) && canDeleteForum) { //delete category writer.write("<type>doDeleteForum</type>"); *************** *** 226,233 **** } ! } else { ! writer.write("<type>noAccess</type>"); ! } } else if (type.equals("createCat")) { --- 225,286 ---- } ! } else { ! // Unauthorized access to delete ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to delete forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! authorized = false; ! } ! ! } else if (type.equals("renameForum")) { ! ! // Users must also be part of the Rap Administrator's to rename forums ! if (isAdmin || isManager) { ! writer.write("<type>renameForum</type>"); ! ! RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(rapViewXML.getCategoryXML().detachRootElement(), writer); ! outputter.output(rapViewXML.getForumNameXML().detachRootElement(), writer); ! String name = (session.runtimeData).getParameter("name"); ! //validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE); ! ! } else { ! // Unauthorized access to rename forums ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to rename forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! authorized = false; ! } ! ! } else if (type.equals("doRenameForum")) { ! ! // Users must also be part of the Rap Administrator's to rename forums ! if (isAdmin || isManager) { ! //rename forum ! writer.write("<type>doRenameForum</type>"); ! String newName = (session.runtimeData).getParameter("newName"); ! String forumID = (session.runtimeData).getParameter("forumid"); ! ! if(forumID != null && newName != null) { ! RAPDB dbCon = new RAPDB(); ! if(dbCon.renameForum(newName, Integer.parseInt(forumID)) == 1) ! writer.write("<forumrename>success</forumrename>"); ! else ! writer.write("<forumrename>failed</forumrename>"); ! } else { ! writer.write("<forumrename>failed</forumrename>"); ! } + } else { + // Unauthorized access to post + UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); + session.unauthorizedMsg = "Sorry, you do not have appropriate permission to rename forums.<br/><br/>"+ + "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; + command.execute(forum, session, out); + authorized = false; + } } else if (type.equals("createCat")) { *************** *** 283,286 **** --- 336,408 ---- writer.write("<type>noAccess</type>"); } + + } else if (type.equals("importCat")) { + + if (isAdmin || isManager) { + writer.write("<type>importCat</type>"); + } else { + writer.write("<type>noAccess</type>"); + } + + } else if (type.equals("doImport")) { + + writer.write("<type>doImport</type>"); + + if (isAdmin || isManager) { + + // upload the file + ChannelRuntimeData crd = (session.runtimeData); + if(crd.getObjectParameter( "localFile" ) != null) { + + try{ + // spawn a thread here + // run in the backgroud + org.jasig.portal.MultipartDataSource mpds = (org.jasig.portal.MultipartDataSource) crd.getObjectParameter( "localFile" ); + + // now we have the imported xml... we need to create the forums and categorgies + // first let's create an xml document + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = docBuilder.parse(new InputSource(mpds.getInputStream())); + + // get categories + // unfortunately I have to switch to jdom because its much nice to work with + // I'll use fully quailfied objects to avoid confusion from w3c and jdom objects + // No error protection yet + org.jdom.input.DOMBuilder jDomBuilder = new org.jdom.input.DOMBuilder(); + org.jdom.Document jDoc = jDomBuilder.build(doc); + org.jdom.Element jRoot = jDoc.getRootElement(); + + Iterator itr = (jRoot.getChildren()).iterator(); // categories + while(itr.hasNext()) { + Element category = (Element)itr.next(); + + int catID = IDManager.getInstance().nextCategoryID(); + RAPDB rapDB = new RAPDB(); + rapDB.insertCategory(catID, category.getAttribute("name").getValue(), + category.getAttribute("description").getValue(), 0, 0); + + Iterator forumsItr = (category.getChildren()).iterator(); // forums + while(forumsItr.hasNext()) { + Element forumEl = (Element)forumsItr.next(); + // add forum to category + IForum newForum = new RAPForumsManager().createForum(forumEl.getAttribute("name").getValue(), + forumEl.getAttribute("description").getValue(), + catID); + } + } + + } catch(SAXException saxe) { + LogService.instance().log(LogService.ERROR, saxe); + saxe.printStackTrace(); + } catch(Exception e) { + LogService.instance().log(LogService.ERROR, e); + e.printStackTrace(); + } + } + + } else { + writer.write("<type>noAccess</type>"); + } + } *************** *** 290,305 **** LogService.instance().log(LogService.ERROR, e); } ! xml += writer.toString(); ! xml += "</rap>"; ! ! //System.out.println("Admin "+xml); ! ! // Transform xml ! XSLT xslt = new XSLT(forum); ! xslt.setXML(xml); ! xslt.setXSL("CForum.ssl", stylesheet, (session.runtimeData).getBrowserInfo()); ! xslt.setStylesheetParameter("baseActionURL", (session.runtimeData).getBaseActionURL()); ! xslt.setTarget(out); ! xslt.transform(); } --- 412,430 ---- LogService.instance().log(LogService.ERROR, e); } ! ! if(authorized) { ! xml += writer.toString(); ! xml += "</rap>"; ! ! //System.out.println("Admin "+xml); ! ! // Transform xml ! XSLT xslt = new XSLT(forum); ! xslt.setXML(xml); ! xslt.setXSL("CForum.ssl", stylesheet, (session.runtimeData).getBrowserInfo()); ! xslt.setStylesheetParameter("baseActionURL", (session.runtimeData).getBaseActionURL()); ! xslt.setTarget(out); ! xslt.transform(); ! } } Index: PostModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/PostModeCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PostModeCommand.java 21 Jul 2004 17:15:04 -0000 1.4 --- PostModeCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 42,45 **** --- 42,46 ---- import java.io.StringWriter; import java.util.GregorianCalendar; + import java.sql.Time; /** *************** *** 48,52 **** * * @author Chris Pereda (cp...@fu...) ! * @version 0.8.3 $Revision %G% */ public class PostModeCommand implements IForumCommand { --- 49,53 ---- * * @author Chris Pereda (cp...@fu...) ! * @version 0.9.0 $Revision %G% */ public class PostModeCommand implements IForumCommand { *************** *** 82,90 **** if (postType.equals("post")) { int forumID = Integer.parseInt((session.runtimeData).getParameter("forum")); Document doc = rapViewXML.getPostXML(forumID); Element rootElement = doc.getRootElement(); Element nameElement = new Element("username"); ! nameElement.setText((session.staticData).getPerson().getAttribute("displayName") + ""); rootElement.addContent(nameElement); Element userIDElement = new Element("userid"); --- 83,97 ---- if (postType.equals("post")) { + String username = (String) (session.staticData).getPerson().getAttribute("displayName"); + /* + Want to post all user's real names to make the forums more personal... + if(username == null) + username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); + */ int forumID = Integer.parseInt((session.runtimeData).getParameter("forum")); Document doc = rapViewXML.getPostXML(forumID); Element rootElement = doc.getRootElement(); Element nameElement = new Element("username"); ! nameElement.setText(username); rootElement.addContent(nameElement); Element userIDElement = new Element("userid"); Index: MainModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/MainModeCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MainModeCommand.java 21 Jul 2004 17:15:04 -0000 1.4 --- MainModeCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 23,33 **** package edu.fullcoll.uportal.channels.rap.forum.commands; - import org.jasig.portal.ChannelRuntimeData; import org.jasig.portal.utils.XSLT; import org.xml.sax.ContentHandler; import org.jasig.portal.PortalException; import org.jasig.portal.services.LogService; import edu.fullcoll.uportal.channels.rap.forum.CForum; import edu.fullcoll.uportal.channels.rap.forum.database.RAPDB; import edu.fullcoll.uportal.channels.rap.forum.xml.ViewXMLFactory; --- 23,35 ---- package edu.fullcoll.uportal.channels.rap.forum.commands; import org.jasig.portal.utils.XSLT; import org.xml.sax.ContentHandler; import org.jasig.portal.PortalException; + import org.jasig.portal.groups.IGroupMember; + import org.jasig.portal.services.GroupService; import org.jasig.portal.services.LogService; import edu.fullcoll.uportal.channels.rap.forum.CForum; + import edu.fullcoll.uportal.channels.rap.forum.RAPForumCategory; import edu.fullcoll.uportal.channels.rap.forum.database.RAPDB; import edu.fullcoll.uportal.channels.rap.forum.xml.ViewXMLFactory; *************** *** 39,42 **** --- 41,55 ---- import org.jdom.output.XMLOutputter; import java.io.StringWriter; + import java.util.Calendar; + import java.util.GregorianCalendar; + import java.util.ArrayList; + import java.util.Hashtable; + import java.util.Iterator; + + import javax.naming.Binding; + import javax.naming.Context; + import javax.naming.InitialContext; + import javax.naming.NamingEnumeration; + import javax.naming.NamingException; /** *************** *** 45,51 **** * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...), Tung Lai Thanh (lt...@ya...) ! * @version 0.8.3 $Revision %G% */ public class MainModeCommand implements IForumCommand { /** --- 58,67 ---- * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...), Tung Lai Thanh (lt...@ya...) ! * @version 0.9.0 $Revision %G% */ public class MainModeCommand implements IForumCommand { + + //public static StringBuffer mainXML = null; + //public static GregorianCalendar cacheDate = null; /** *************** *** 58,65 **** public void execute(CForum forum, ForumSessionData session, ContentHandler out) throws PortalException { final int INITITAL_BUFFER_SIZE = 5000; ! String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; String stylesheet = "main"; ! xml += "<rap>"; int lpg = 0; --- 74,81 ---- public void execute(CForum forum, ForumSessionData session, ContentHandler out) throws PortalException { final int INITITAL_BUFFER_SIZE = 5000; ! StringBuffer xml = new StringBuffer("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); String stylesheet = "main"; ! xml.append("<rap>"); int lpg = 0; *************** *** 74,94 **** try { String username = (String) (session.staticData).getPerson().getAttribute("displayName"); if(username == null) ! username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); writer.write("<username>" + username + "</username>"); writer.write("<currentpage>" + (Math.ceil(lpg / 5) + 1) + "" + "</currentpage>"); ! writer.write("<forumnumber>" + new RAPDB().getForumCount() + "</forumnumber>"); ! ! int startRow = 1; ! if(lpg != 0) ! startRow = lpg+1; ! int endRow = 5; ! if(lpg != 0) ! endRow = lpg + 5; ! ! // Displays only 5 forums at a time RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); ! Document doc = rapViewXML.getForumsXML(startRow, endRow); Element forumsRootElement = doc.getRootElement(); XMLOutputter outputter = new XMLOutputter(" ", true); --- 90,106 ---- try { String username = (String) (session.staticData).getPerson().getAttribute("displayName"); + String loginUsername = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); if(username == null) ! username = loginUsername; + int forumCount = new RAPDB().getForumCount(); writer.write("<username>" + username + "</username>"); writer.write("<currentpage>" + (Math.ceil(lpg / 5) + 1) + "" + "</currentpage>"); ! writer.write("<forumnumber>" + forumCount + "</forumnumber>"); ! writer.write("<sessionnumber>" + countSessions() + "</sessionnumber>"); ! RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); ! ! Document doc = rapViewXML.getForumsXML(1, forumCount, loginUsername); // startRow, endRow Element forumsRootElement = doc.getRootElement(); XMLOutputter outputter = new XMLOutputter(" ", true); *************** *** 99,108 **** LogService.instance().log(LogService.ERROR, e); } ! xml += writer.toString(); ! xml += "</rap>"; // Transform xml XSLT xslt = new XSLT(forum); ! xslt.setXML(xml); xslt.setXSL("CForum.ssl", stylesheet, (session.runtimeData).getBrowserInfo()); xslt.setStylesheetParameter("baseActionURL", (session.runtimeData).getBaseActionURL()); --- 111,125 ---- LogService.instance().log(LogService.ERROR, e); } ! xml.append(writer.toString()); ! xml.append("</rap>"); ! ! //add new category information for display ! xml = addCategoryXML(xml); + //System.out.println(xml.toString()); + // Transform xml XSLT xslt = new XSLT(forum); ! xslt.setXML(xml.toString()); xslt.setXSL("CForum.ssl", stylesheet, (session.runtimeData).getBrowserInfo()); xslt.setStylesheetParameter("baseActionURL", (session.runtimeData).getBaseActionURL()); *************** *** 110,113 **** --- 127,228 ---- xslt.transform(); } + + private int countSessions() throws NamingException { + + Hashtable environment = new Hashtable(5); + // Get the uPortal context + environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jasig.portal.jndi.PortalInitialContextFactory"); + InitialContext ctx = null; + try { + ctx = new InitialContext(environment); + int tcnt = 0; + StringBuffer xml = new StringBuffer(1024); + NamingEnumeration bindings = ctx.listBindings("/"); + while (bindings.hasMore()) { + Binding bd = (Binding)bindings.next(); + String name = bd.getName(); + if (name.equals("sessions")) { + try { + NamingEnumeration bndngs = ((Context)bd.getObject()).listBindings("/"); + while (bndngs.hasMoreElements()) { + Binding bd2 = (Binding)bndngs.next(); + tcnt++; + } // while + } catch (Exception e) { e.printStackTrace(System.out); } + } /*else { + if (bd.getObject() instanceof Context) + countSessions((Context)bd.getObject()); + } // if*/ + } //while + return tcnt; + } catch (NamingException ne) { + LogService.log(LogService.INFO, ne); + return 0; + } + } // countSessions + /** + * Major hack... needs fix... + * @param xml + * @return + */ + private StringBuffer addCategoryXML(StringBuffer xml) { + + if(xml == null || xml.indexOf("<rapforums />") != -1) { + //LogService.instance().log(LogService.INFO, "NO FORUMS*********"); + return xml; + } + + /* + GregorianCalendar now = new GregorianCalendar(); + if(mainXML != null && (cacheDate != null && cacheDate.after(now))) { + System.out.println("Serving cache"); + return mainXML; + } + */ + + // cache expired, get new xml + int catIndx = 1; + int catIndxEnd = 1; + int forumIndx = 0; + int endForumIndx = 0; + boolean contLoop = true; + int emptyCatIndx = 0; + String preCat = ""; + + while(contLoop) { + forumIndx = xml.indexOf("<rapforum>", forumIndx); // find the beginning of the forums + + // end of forums + if(forumIndx == -1) { + endForumIndx = xml.indexOf("</rapforum>", emptyCatIndx)+11; // find the end of the forums + xml.insert(endForumIndx, "</category>"); + break; + } + // search for the category + catIndx = xml.indexOf("<categoryname>", forumIndx)+14; // find the category + catIndxEnd = xml.indexOf("</categoryname>", catIndx); + String cat = xml.substring(catIndx, catIndxEnd); // get the category + emptyCatIndx = forumIndx+cat.length()+23; + // if this is a new category, insert the category information + if(preCat.equals("")) { + xml.insert(forumIndx, "<category><name>"+cat+"</name>"); + } else if(!preCat.equals(cat)){ + xml.insert(forumIndx, "</category><category><name>"+cat+"</name>"); + } + //System.out.println("Category "+catName+" = "+cat); + // forum is in the same category, continue search for a forum + // in a new category + forumIndx=emptyCatIndx+12; + preCat = cat; + } + + //can't cache because the list of forums is different for each user + + //mainXML = xml; // update cached xml + //cacheDate = new GregorianCalendar(); + //cacheDate.add(GregorianCalendar.HOUR, 3); + //LogService.instance().log(LogService.INFO, "XML AFTER**********"+xml.toString()); + return xml; + } } Index: UnAuthorizedModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/UnAuthorizedModeCommand.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UnAuthorizedModeCommand.java 21 Jul 2004 17:15:45 -0000 1.1 --- UnAuthorizedModeCommand.java 4 Feb 2005 00:56:34 -0000 1.2 *************** *** 47,52 **** public void execute(CForum forum, ForumSessionData session, ContentHandler out) throws PortalException { StringBuffer xml = new StringBuffer("<?xml version=\"1.0\" encoding=\"utf-8\"?><rap>"); xml.append("<name>"); ! xml.append((session.staticData).getPerson().getAttribute("displayName")); xml.append("</name><message>"); xml.append(session.unauthorizedMsg); --- 47,57 ---- public void execute(CForum forum, ForumSessionData session, ContentHandler out) throws PortalException { StringBuffer xml = new StringBuffer("<?xml version=\"1.0\" encoding=\"utf-8\"?><rap>"); + + String username = (String) (session.staticData).getPerson().getAttribute("displayName"); + if(username == null) + username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); + xml.append("<name>"); ! xml.append(username); xml.append("</name><message>"); xml.append(session.unauthorizedMsg); Index: IForumCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/IForumCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IForumCommand.java 21 Jul 2004 17:15:04 -0000 1.4 --- IForumCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 36,40 **** * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...) ! * @version 0.8.3 $Revision %G% */ public interface IForumCommand { --- 36,40 ---- * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...) ! * @version 0.9.0 $Revision %G% */ public interface IForumCommand { Index: SearchModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/SearchModeCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SearchModeCommand.java 21 Jul 2004 17:15:04 -0000 1.4 --- SearchModeCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 46,50 **** * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...) ! * @version 0.8.3 $Revision %G% */ public class SearchModeCommand implements IForumCommand { --- 46,50 ---- * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...) ! * @version 0.9.0 $Revision %G% */ public class SearchModeCommand implements IForumCommand { *************** *** 129,133 **** try { ! writer.write("<username>" + (session.staticData).getPerson().getAttribute("displayName") + "</username>"); // Get the xml from the query --- 129,137 ---- try { ! String username = (String) (session.staticData).getPerson().getAttribute("displayName"); ! if(username == null) ! username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); ! ! writer.write("<username>" + username + "</username>"); // Get the xml from the query Index: ForumModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/ForumModeCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ForumModeCommand.java 21 Jul 2004 17:15:04 -0000 1.4 --- ForumModeCommand.java 4 Feb 2005 00:56:34 -0000 1.5 *************** *** 44,48 **** * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...) ! * @version 0.8.3 $Revision %G% */ public class ForumModeCommand implements IForumCommand { --- 44,48 ---- * * @author Brad Rippe (br...@fu...), Chris Pereda (cp...@fu...) ! * @version 0.9.0 $Revision %G% */ public class ForumModeCommand implements IForumCommand { *************** *** 82,86 **** Element nameElement = new Element("username"); ! nameElement.setText((session.staticData).getPerson().getAttribute("displayName") + ""); forumsRootElement.addContent(nameElement); --- 82,90 ---- Element nameElement = new Element("username"); ! String username = (String) (session.staticData).getPerson().getAttribute("displayName"); ! if(username == null) ! username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); ! ! nameElement.setText(username); forumsRootElement.addContent(nameElement); |