0001: /*
0002: * Copyright 2007 Pentaho Corporation. All rights reserved.
0003: * This software was developed by Pentaho Corporation and is provided under the terms
0004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
0005: * this file except in compliance with the license. If you need a copy of the license,
0006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
0007: * BI Platform. The Initial Developer is Pentaho Corporation.
0008: *
0009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
0010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
0011: * the license for the specific language governing your rights and limitations.
0012: */
0013: /*
0014: * Copyright 2006 Pentaho Corporation. All rights reserved.
0015: * This software was developed by Pentaho Corporation and is provided under the terms
0016: * of the Pentaho Commercial License, Version 1.0, or any later version. You may not use
0017: * this file except in compliance with the license. If you need a copy of the license,
0018: * please e-mail sales@pentaho.org. The Original Code is the Pentaho
0019: * BI Suite Professional Edition. The Initial Developer is Pentaho Corporation.
0020: *
0021: * Software distributed under the Pentaho Commercial License is distributed on an "AS IS"
0022: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
0023: * the license for the specific language governing your rights and limitations.
0024: *
0025: * Created April 2006
0026: * @author Doug Moran
0027: */
0028:
0029: package org.pentaho.ui.component;
0030:
0031: import java.util.Arrays;
0032: import java.util.Collection;
0033: import java.util.Date;
0034: import java.util.HashSet;
0035: import java.util.Iterator;
0036: import java.util.List;
0037: import java.util.Map;
0038: import java.util.Set;
0039:
0040: import javax.servlet.http.HttpServletRequest;
0041:
0042: import org.apache.commons.fileupload.DiskFileUpload;
0043: import org.apache.commons.fileupload.FileItem;
0044: import org.apache.commons.logging.Log;
0045: import org.apache.commons.logging.LogFactory;
0046: import org.dom4j.Document;
0047: import org.dom4j.DocumentHelper;
0048: import org.dom4j.Element;
0049: import org.dom4j.Node;
0050: import org.pentaho.core.repository.ISolutionRepository;
0051: import org.pentaho.core.solution.HttpRequestParameterProvider;
0052: import org.pentaho.core.solution.IParameterProvider;
0053: import org.pentaho.core.solution.SolutionCompare;
0054: import org.pentaho.core.subscribe.IScheduledJob;
0055: import org.pentaho.core.subscribe.ISubscriptionScheduler;
0056: import org.pentaho.core.system.PentahoSystem;
0057: import org.pentaho.core.ui.IPentahoUrlFactory;
0058: import org.pentaho.core.util.CleanXmlHelper;
0059: import org.pentaho.ui.XmlComponent;
0060:
0061: import org.pentaho.messages.Messages;
0062: import com.pentaho.repository.subscribe.ISubscriptionRepository;
0063: import com.pentaho.repository.subscribe.Schedule;
0064: import com.pentaho.repository.subscribe.SubscribeContent;
0065: import com.pentaho.repository.subscribe.Subscription;
0066:
0067: /**
0068: * @author wseyler
0069: *
0070: * TODO To change the template for this generated type comment go to Window -
0071: * Preferences - Java - Code Style - Code Templates
0072: */
0073: public class SubscriptionAdminUIComponent extends XmlComponent {
0074:
0075: private static final long serialVersionUID = 2963902264708970014L;
0076:
0077: public static final String SCHEDULER_ACTION = "schedulerAction"; //$NON-NLS-1$
0078:
0079: public static final String NODE_SUBSCRIPTION_ADMIN = "subscriptionAdmin"; //$NON-NLS-1$
0080:
0081: public static final String NODE_CMD_RESULT = "commandResult"; //$NON-NLS-1$
0082:
0083: public static final String NODE_EXCEPTION = "exception"; //$NON-NLS-1$
0084:
0085: public static final String NODE_PARAM_ERRORS = "paramErrors"; //$NON-NLS-1$
0086:
0087: public static final String NODE_PARAM_MISSING = "paramMissing"; //$NON-NLS-1$
0088:
0089: public static final String NODE_CONTENT = "content"; //$NON-NLS-1$
0090:
0091: public static final String NODE_SCHEDULER_STATUS = "schedulerStatus"; //$NON-NLS-1$
0092:
0093: public static final String NODE_RESULT_MSG = "message"; //$NON-NLS-1$
0094:
0095: public static final String NODE_RESULT_TYPE = "result"; //$NON-NLS-1$
0096:
0097: public static final String NODE_RETURN_URL = "returnURL"; //$NON-NLS-1$
0098:
0099: public static final String NODE_RETURN_PARAM = "returnParam"; //$NON-NLS-1$
0100:
0101: public static final String NODE_STATUS_OK = "OK"; //$NON-NLS-1$
0102:
0103: public static final String NODE_STATUS_ERROR = "ERROR"; //$NON-NLS-1$
0104:
0105: public static final String NODE_STATUS_WARNING = "WARNING"; //$NON-NLS-1$
0106:
0107: public static final String NODE_STATUS_INFO = "INFO"; //$NON-NLS-1$
0108:
0109: public static final String ACTION_JOB_DO_PAUSE = "doPauseJob"; //$NON-NLS-1$
0110:
0111: public static final String ACTION_JOB_DO_RESUME = "doResumeJob"; //$NON-NLS-1$
0112:
0113: public static final String ACTION_JOB_DO_DELETE = "doDeleteJob"; //$NON-NLS-1$
0114:
0115: public static final String ACTION_JOB_DO_EXECUTE = "doExecuteJob"; //$NON-NLS-1$
0116:
0117: public static final String ACTION_JOB_DO_SCHEDULE = "doScheduleJob"; //$NON-NLS-1$
0118:
0119: public static final String ACTION_SCHEDULER_DO_RESUME = "doResumeScheduler"; //$NON-NLS-1$
0120:
0121: public static final String ACTION_SCHEDULER_DO_SUSPEND = "doSuspendScheduler"; //$NON-NLS-1$
0122:
0123: public static final String ACTION_SCHEDULE_SHOW_DETAILS = "scheduleDetails"; //$NON-NLS-1$
0124:
0125: public static final String ACTION_SCHEDULE_SHOW_ADD = "addSchedule"; //$NON-NLS-1$
0126:
0127: public static final String ACTION_SCHEDULE_DO_ADD = "doAddSchedule"; //$NON-NLS-1$
0128:
0129: public static final String ACTION_SCHEDULE_DO_ADD_CONTENT = "doAddContentForSchedule"; //$NON-NLS-1$
0130:
0131: public static final String ACTION_SCHEDULE_SHOW_ADD_CONTENT = "addContentForSchedule"; //$NON-NLS-1$
0132:
0133: public static final String ACTION_SCHEDULE_SHOW_EDIT = "editSchedule"; //$NON-NLS-1$
0134:
0135: public static final String ACTION_SCHEDULE_DO_EDIT = "doEditSchedule"; //$NON-NLS-1$
0136:
0137: public static final String ACTION_SCHEDULE_DO_DELETE = "doDeleteSchedule"; //$NON-NLS-1$
0138:
0139: public static final String ACTION_SCHEDULE_DO_DELETE_CONTENT = "doDeleteContentForSchedule"; //$NON-NLS-1$
0140:
0141: public static final String ACTION_SCHEDULE_SHOW_LIST = "listSchedules"; //$NON-NLS-1$
0142:
0143: public static final String ACTION_SCHEDULE_ALL_JOBS = "scheduleAll"; //$NON-NLS-1$
0144:
0145: public static final String ACTION_CONTENT_SHOW_LIST = "listContent"; //$NON-NLS-1$
0146:
0147: public static final String ACTION_CONTENT_SHOW_EDIT = "editContent"; //$NON-NLS-1$
0148:
0149: public static final String ACTION_CONTENT_DO_EDIT = "doEditContent"; //$NON-NLS-1$
0150:
0151: public static final String ACTION_CONTENT_SHOW_ADD = "addContent"; //$NON-NLS-1$
0152:
0153: public static final String ACTION_CONTENT_SHOW_ADD_SCHEDULE = "addScheduleForContent"; //$NON-NLS-1$
0154:
0155: public static final String ACTION_CONTENT_DO_ADD_SCHEDULE = "doAddScheduleForContent"; //$NON-NLS-1$
0156:
0157: public static final String ACTION_CONTENT_DO_ADD = "doAddContent"; //$NON-NLS-1$
0158:
0159: public static final String ACTION_CONTENT_DO_DELETE = "doDeleteContent"; //$NON-NLS-1$
0160:
0161: public static final String ACTION_SUBSCRIPTION_SHOW_LIST = "listSubscriptions"; //$NON-NLS-1$
0162:
0163: public static final String ACTION_SUBSCRIPTION_DO_DELETE = "doDeleteSubscription"; //$NON-NLS-1$
0164:
0165: public static final String ACTION_SHOW_IMPORT = "showImport"; //$NON-NLS-1$
0166:
0167: public static final String ACTION_DO_IMPORT = "doImport"; //$NON-NLS-1$
0168:
0169: private ISubscriptionScheduler scheduler = null;
0170:
0171: private ISubscriptionRepository subscriptionRepository = null;
0172:
0173: private static final Log logger = LogFactory
0174: .getLog(SubscriptionAdminUIComponent.class);
0175:
0176: /**
0177: * @param urlFactory
0178: */
0179: public SubscriptionAdminUIComponent(IPentahoUrlFactory urlFactory,
0180: List messages) throws Exception {
0181: super (urlFactory, messages, null);
0182: scheduler = PentahoSystem.getSubscriptionScheduler();
0183:
0184: subscriptionRepository = PentahoSystem
0185: .getSubscriptionRepository(getSession());
0186: if (subscriptionRepository == null) {
0187: error(Messages
0188: .getErrorString("PentahoSystem.ERROR_0003_SUBSCRIPTION_REPOSITORY_NOT_INITIALIZED")); //$NON-NLS-1$
0189: throw (new Exception(
0190: Messages
0191: .getErrorString("PentahoSystem.ERROR_0003_SUBSCRIPTION_REPOSITORY_NOT_INITIALIZED"))); //$NON-NLS-1$
0192: }
0193:
0194: // set the default XSL
0195: setXsl("text/html", "SubscriptionAdmin.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
0196:
0197: }
0198:
0199: /*
0200: * (non-Javadoc)
0201: *
0202: * @see org.pentaho.system.PentahoBase#getLogger()
0203: */
0204: public Log getLogger() {
0205: return logger;
0206: }
0207:
0208: /*
0209: * (non-Javadoc)
0210: *
0211: * @see org.pentaho.ui.component.BaseUIComponent#validate()
0212: */
0213: public boolean validate() {
0214: return true;
0215: }
0216:
0217: /*
0218: * (non-Javadoc)
0219: *
0220: * @see org.pentaho.ui.component.BaseUIComponent#getXmlContent()
0221: */
0222: public Document getXmlContent() {
0223: setXslProperty(
0224: "baseUrl", urlFactory.getDisplayUrlBuilder().getUrl()); //$NON-NLS-1$
0225:
0226: String schedulerActionStr = getParameter(SCHEDULER_ACTION,
0227: ACTION_SCHEDULE_SHOW_LIST);
0228:
0229: // System.out.println("ACTION: " + schedulerActionStr);
0230: // System.out.println("JOB-ID: " + getParameter("jobId", "-"));
0231: // System.out.println("SCHED-ID: " + getParameter("schedId", "-"));
0232:
0233: try {
0234: if (ACTION_SCHEDULE_SHOW_LIST.equals(schedulerActionStr)) {
0235: return (showAdminPageUI(null));
0236: }
0237:
0238: if (ACTION_SCHEDULE_SHOW_EDIT.equals(schedulerActionStr)) {
0239: return (showEditScheduleUI(null));
0240: }
0241:
0242: if (ACTION_SCHEDULE_DO_EDIT.equals(schedulerActionStr)) {
0243: if (getParameter("editDelete", null) != null) { //$NON-NLS-1$
0244: return (doDeleteSchedule());
0245: }
0246:
0247: if (getParameter("editAdd", null) != null) { //$NON-NLS-1$
0248: return (doAddSchedule());
0249: }
0250:
0251: return (doEditSchedule());
0252: }
0253:
0254: if (ACTION_SCHEDULE_DO_DELETE.equals(schedulerActionStr)) {
0255: return (doDeleteSchedule());
0256: }
0257:
0258: if (ACTION_SCHEDULE_SHOW_ADD.equals(schedulerActionStr)) {
0259: return (showAddScheduleUI(null));
0260: }
0261:
0262: if (ACTION_SCHEDULE_DO_ADD.equals(schedulerActionStr)) {
0263: return (doAddSchedule());
0264: }
0265:
0266: if (ACTION_SCHEDULE_SHOW_ADD_CONTENT
0267: .equals(schedulerActionStr)) {
0268: return (showAddContentForScheduleUI());
0269: }
0270:
0271: if (ACTION_SCHEDULE_DO_DELETE_CONTENT
0272: .equals(schedulerActionStr)) {
0273: return (doDeleteContentForSchedule());
0274: }
0275:
0276: if (ACTION_SCHEDULE_DO_ADD_CONTENT
0277: .equals(schedulerActionStr)) {
0278: return (doAddContentForSchedule());
0279: }
0280:
0281: if (ACTION_SCHEDULE_SHOW_DETAILS.equals(schedulerActionStr)) {
0282: return (showCommandResultUI(
0283: getInfoMessage("TODO: Implement " + ACTION_SCHEDULE_SHOW_DETAILS), NODE_STATUS_INFO)); //$NON-NLS-1$
0284: }
0285:
0286: if (ACTION_JOB_DO_SCHEDULE.equals(schedulerActionStr)) {
0287: return (doScheduleJob());
0288: }
0289:
0290: if (ACTION_SCHEDULE_ALL_JOBS.equals(schedulerActionStr)) {
0291: return (doScheduleAllJobs());
0292: }
0293:
0294: if (ACTION_CONTENT_SHOW_EDIT.equals(schedulerActionStr)) {
0295: return (showEditContentUI(null));
0296: }
0297:
0298: if (ACTION_CONTENT_DO_EDIT.equals(schedulerActionStr)) {
0299: if (getParameter("editDelete", null) != null) { //$NON-NLS-1$
0300: return (doDeleteContent());
0301: }
0302:
0303: if (getParameter("editAdd", null) != null) { //$NON-NLS-1$
0304: return (doAddContent());
0305: }
0306:
0307: return (doEditContent());
0308: }
0309:
0310: if (ACTION_CONTENT_DO_DELETE.equals(schedulerActionStr)) {
0311: return (doDeleteContent());
0312: }
0313:
0314: if (ACTION_CONTENT_DO_ADD.equals(schedulerActionStr)) {
0315: return (doAddContent());
0316: }
0317:
0318: if (ACTION_CONTENT_SHOW_ADD.equals(schedulerActionStr)) {
0319: return (showAddContentUI(null));
0320: }
0321:
0322: if (ACTION_CONTENT_SHOW_ADD_SCHEDULE
0323: .equals(schedulerActionStr)) {
0324: return (showAddScheduleForContentUI());
0325: }
0326:
0327: if (ACTION_CONTENT_DO_ADD_SCHEDULE
0328: .equals(schedulerActionStr)) {
0329: return (doAddScheduleForContent());
0330: }
0331:
0332: if (ACTION_JOB_DO_EXECUTE.equals(schedulerActionStr)) {
0333: return (doJobAction(ACTION_JOB_DO_EXECUTE));
0334: }
0335:
0336: if (ACTION_JOB_DO_DELETE.equals(schedulerActionStr)) {
0337: return (doJobAction(ACTION_JOB_DO_DELETE));
0338: }
0339:
0340: if (ACTION_JOB_DO_PAUSE.equals(schedulerActionStr)) {
0341: return (doJobAction(ACTION_JOB_DO_PAUSE));
0342: }
0343:
0344: if (ACTION_JOB_DO_RESUME.equals(schedulerActionStr)) {
0345: return (doJobAction(ACTION_JOB_DO_RESUME));
0346: }
0347:
0348: if (ACTION_SCHEDULER_DO_RESUME.equals(schedulerActionStr)) {
0349: return (doResumeScheduler());
0350: }
0351:
0352: if (ACTION_SCHEDULER_DO_SUSPEND.equals(schedulerActionStr)) {
0353: return (doPauseScheduler());
0354: }
0355:
0356: if (ACTION_SUBSCRIPTION_SHOW_LIST
0357: .equals(schedulerActionStr)) {
0358: return (showSubscriptionsPageUI(null));
0359: }
0360:
0361: if (ACTION_SUBSCRIPTION_DO_DELETE
0362: .equals(schedulerActionStr)) {
0363: return (doDeleteSubscription());
0364: }
0365:
0366: if (ACTION_SHOW_IMPORT.equals(schedulerActionStr)) {
0367: return (showImportUI());
0368: }
0369:
0370: if (ACTION_DO_IMPORT.equals(schedulerActionStr)) {
0371: return (doImport());
0372: }
0373:
0374: } catch (Throwable t) {
0375: return (showCommandResultUI(
0376: getErrorMessage(Messages
0377: .getString(
0378: "SubscriptionAdminUIComponent.UNABLE_TO_COMPLETE_REQUEST", t.getLocalizedMessage())), NODE_STATUS_ERROR)); //$NON-NLS-1$
0379: }
0380:
0381: Document document = showCommandResultUI(
0382: getInfoMessage(Messages
0383: .getString(
0384: "SubscriptionAdminUIComponent.INVALID_COMMAND", schedulerActionStr)), NODE_STATUS_ERROR); //$NON-NLS-1$
0385: document.getRootElement().add(getReturnParams());
0386: return (document);
0387: }
0388:
0389: /**
0390: * @return
0391: * @throws Exception
0392: */
0393: private void doListSchedules(Element root) throws Exception {
0394: root = root.addElement(ACTION_SCHEDULE_SHOW_LIST);
0395: ISubscriptionScheduler subScheduler = PentahoSystem
0396: .getSubscriptionScheduler();
0397:
0398: List schedList = subscriptionRepository.getSchedules();
0399: Map jobMap = subScheduler.getScheduledJobMap();
0400:
0401: Element scheduledJobs = root.addElement("scheduledJobs"); //$NON-NLS-1$
0402: Element unScheduledJobs = root.addElement("unScheduledJobs"); //$NON-NLS-1$
0403: Element extraScheduledJobs = root
0404: .addElement("extraScheduledJobs"); //$NON-NLS-1$
0405:
0406: int pauseCounter = 0;
0407: int errorCounter = 0;
0408:
0409: for (int i = 0; i < schedList.size(); ++i) {
0410: Schedule sched = (Schedule) schedList.get(i);
0411: IScheduledJob schedJob = (IScheduledJob) jobMap
0412: .remove(sched.getScheduleReference());
0413: if (schedJob != null) {
0414: int jobState = schedJob.getExecutionState();
0415: if (jobState == IScheduledJob.STATE_PAUSED) {
0416: ++pauseCounter;
0417: } else if (jobState != IScheduledJob.STATE_NORMAL) {
0418: ++errorCounter;
0419: }
0420: }
0421:
0422: Element job = (schedJob == null) ? unScheduledJobs
0423: .addElement("job") : scheduledJobs.addElement("job"); //$NON-NLS-1$ //$NON-NLS-2$
0424: getJob(sched, schedJob, job);
0425: }
0426:
0427: for (Iterator it = jobMap.entrySet().iterator(); it.hasNext();) {
0428: Map.Entry entry = (Map.Entry) it.next();
0429: IScheduledJob schedJob = (IScheduledJob) entry.getValue();
0430: Element job = extraScheduledJobs.addElement("job"); //$NON-NLS-1$
0431:
0432: job
0433: .addElement("schedRef").addText(entry.getKey().toString()); //$NON-NLS-1$
0434: job.addElement("desc").addText(schedJob.getDescription()); //$NON-NLS-1$
0435:
0436: if (schedJob != null) {
0437: job
0438: .addAttribute(
0439: "triggerState", Integer.toString(schedJob.getExecutionState())); //$NON-NLS-1$
0440: Date date = schedJob.getNextTriggerTime();
0441: job
0442: .addElement("nextFireTime").addText((date == null) ? Messages.getString("SubscriptionAdminUIComponent.USER_NEVER") : date.toString()); //$NON-NLS-1$ //$NON-NLS-2$
0443: date = schedJob.getLastTriggerTime();
0444: job
0445: .addElement("prevFireTime").addText((date == null) ? Messages.getString("SubscriptionAdminUIComponent.USER_NEVER") : date.toString()); //$NON-NLS-1$ //$NON-NLS-2$
0446: job.addElement("jobId").addText(schedJob.getUniqueId()); //$NON-NLS-1$
0447: String errorMsg = schedJob.getErrorMessage();
0448: if (errorMsg != null) {
0449: job.addElement("errorMsg").addText(errorMsg); //$NON-NLS-1$
0450: }
0451: } else {
0452: job
0453: .addAttribute(
0454: "triggerState", Integer.toString(IScheduledJob.STATE_NONE)); //$NON-NLS-1$1$
0455: }
0456: }
0457:
0458: if (schedList.size() == 0) {
0459: root
0460: .add(getInfoMessage(Messages
0461: .getString("SubscriptionAdminUIComponent.USER_NO_SUBSCRIPTIONS_DEFINED"))); //$NON-NLS-1$
0462: } else if (scheduledJobs.elements().size() == 0) {
0463: root.remove(scheduledJobs);
0464: }
0465:
0466: if (errorCounter > 0) {
0467: root
0468: .add(getErrorMessage(errorCounter
0469: + Messages
0470: .getString("SubscriptionAdminUIComponent.USER_SCHEDULED_JOBS_ARE_IN_ERROR_STATE"))); //$NON-NLS-1$
0471: }
0472:
0473: if (pauseCounter > 0) {
0474: root
0475: .add(getWarningMessage(pauseCounter
0476: + Messages
0477: .getString("SubscriptionAdminUIComponent.USER_SCHEDULED_JOBS_ARE_PAUSED"))); //$NON-NLS-1$
0478: }
0479:
0480: if (unScheduledJobs.elements().size() == 0) {
0481: root.remove(unScheduledJobs);
0482: } else {
0483: root
0484: .add(getWarningMessage(Messages
0485: .getString("SubscriptionAdminUIComponent.USER_SUBSCRIPTIONS_NOT_SCHEDULED"))); //$NON-NLS-1$
0486: }
0487:
0488: if (extraScheduledJobs.elements().size() == 0) {
0489: root.remove(extraScheduledJobs);
0490: } else {
0491: root
0492: .add(getWarningMessage(Messages
0493: .getString("SubscriptionAdminUIComponent.SUBSCRIPTION_JOBS_WITHOUT_SUBSCRIPTION"))); //$NON-NLS-1$
0494: }
0495: }
0496:
0497: private Element getSubscriptions(List subList, boolean schedules) {
0498: Element ele = getCollectionElement("subscriptions", subList); //$NON-NLS-1$
0499: if (subList != null) {
0500: for (int i = 0; i < subList.size(); ++i) {
0501: ele.add(getSubscription((Subscription) subList.get(i),
0502: schedules));
0503: }
0504: }
0505: return (ele);
0506: }
0507:
0508: private Element getSubscription(Subscription sub, boolean schedules) {
0509: //@todo Protect the nulls!!!
0510: Element ele = DocumentHelper.createElement("subscription"); //$NON-NLS-1$
0511: ele.addAttribute("subscriptionId", sub.getId()); //$NON-NLS-1$
0512: ele
0513: .addElement("actionRef").addText(sub.getContent().getActionReference()); //$NON-NLS-1$
0514: ele.addElement("title").addText(sub.getTitle()); //$NON-NLS-1$
0515: ele.addElement("user").addText(sub.getUser()); //$NON-NLS-1$
0516:
0517: if (schedules) {
0518: ele.add(getSchedules(sub.getSchedules()));
0519: }
0520: return (ele);
0521: }
0522:
0523: private void getJob(Schedule sched, IScheduledJob schedJob,
0524: Element job) {
0525: job.addElement("schedId").addText(sched.getId()); //$NON-NLS-1$
0526: job
0527: .addElement("schedRef").addText(sched.getScheduleReference()); //$NON-NLS-1$
0528: job.addElement("title").addText(sched.getTitle()); //$NON-NLS-1$
0529: job.addElement("desc").addText(sched.getDescription()); //$NON-NLS-1$
0530: job.addElement("group").addText(sched.getGroup()); //$NON-NLS-1$
0531: job.addElement("cron").addText(sched.getCronString()); //$NON-NLS-1$
0532: job
0533: .addAttribute(
0534: "subscriberCount", Integer.toString(subscriptionRepository.getSubscriptionsForSchedule(sched).size())); //$NON-NLS-1$
0535:
0536: if (schedJob != null) {
0537: int jobState = schedJob.getExecutionState();
0538: job
0539: .addAttribute(
0540: "triggerState", Integer.toString(jobState)); //$NON-NLS-1$1$
0541: Date date = schedJob.getNextTriggerTime();
0542: job
0543: .addElement("nextFireTime").addText((date == null) ? Messages.getString("SubscriptionAdminUIComponent.USER_NEVER") : date.toString()); //$NON-NLS-1$ //$NON-NLS-2$
0544: date = sched.getLastTrigger();
0545: job
0546: .addElement("prevFireTime").addText(((date == null) || (date.getTime() == 0)) ? Messages.getString("SubscriptionAdminUIComponent.USER_NEVER") : date.toString()); //$NON-NLS-1$ //$NON-NLS-2$
0547: job
0548: .addElement("jobId").addText(sched.getScheduleReference()); //$NON-NLS-1$
0549: String errorMsg = schedJob.getErrorMessage();
0550: if (errorMsg != null) {
0551: job.addElement("errorMsg").addText(errorMsg); //$NON-NLS-1$
0552: }
0553: } else {
0554: job
0555: .addAttribute(
0556: "triggerState", Integer.toString(IScheduledJob.STATE_NONE)); //$NON-NLS-1$1$
0557: }
0558: }
0559:
0560: private void doListContent(Element ele) {
0561: List contentList = subscriptionRepository.getAllContent();
0562: if (contentList.size() == 0) {
0563: ele
0564: .add(getInfoMessage(Messages
0565: .getString("SubscriptionAdminUIComponent.USER_NO_SUBSCRIPTION_CONTENT"))); //$NON-NLS-1$
0566: } else {
0567: ele = ele.addElement(ACTION_CONTENT_SHOW_LIST);
0568: ele.addAttribute(
0569: "count", String.valueOf(contentList.size())); //$NON-NLS-1$
0570: for (int i = 0; i < contentList.size(); ++i) {
0571: getSubscriptionContent((SubscribeContent) contentList
0572: .get(i), ele.addElement(NODE_CONTENT));
0573: }
0574: }
0575: }
0576:
0577: private void getSubscriptionContent(SubscribeContent content,
0578: Element ele) {
0579: ele
0580: .addElement("actionRef").addText(content.getActionReference()); //$NON-NLS-1$
0581: ele.addAttribute("contentId", content.getId()); //$NON-NLS-1$
0582: ele.addElement("type").addText(content.getType()); //$NON-NLS-1$
0583: }
0584:
0585: /**
0586: * @return
0587: */
0588: private void doGetSchedulerStatus(Element root) {
0589: root = root.addElement(NODE_SCHEDULER_STATUS);
0590: ISubscriptionScheduler subScheduler = PentahoSystem
0591: .getSubscriptionScheduler();
0592: int schedulerState = IScheduledJob.STATE_ERROR;
0593: try {
0594: schedulerState = subScheduler.getSchedulerState();
0595: } catch (Throwable t) {
0596: root
0597: .add(getErrorMessage(Messages
0598: .getString("SubscriptionAdminUIComponent.ERROR_GETTING_SCHEDULER_STATUS") + t.getLocalizedMessage())); //$NON-NLS-1$
0599: }
0600: root.addAttribute("state", String.valueOf(schedulerState)); //$NON-NLS-1$
0601: }
0602:
0603: /** ********** subscription util methods ******************* */
0604:
0605: /**
0606: * Has the scheduler check the validity of the CRON expression. Returns Error XML
0607: * if invalid or null if ok.
0608: */
0609: Element validateCronExpression(String cronExpr) {
0610: if ((cronExpr == null) || (cronExpr.length() == 0)) {
0611: return (getErrorMessage(Messages
0612: .getString("SubscriptionAdminUIComponent.CRON_EXPRESSION_EMPTY"))); //$NON-NLS-1$
0613: }
0614: try {
0615: scheduler.getCronSummary(cronExpr); // Should throw execption for bad
0616: // string
0617: } catch (Throwable t) {
0618: return (getException(
0619: Messages
0620: .getString("SubscriptionAdminUIComponent.INVALID_CRON_EXPRESSION") + cronExpr, t)); //$NON-NLS-1$
0621: }
0622:
0623: return (null);
0624: }
0625:
0626: /************ Worker Methods ********************/
0627:
0628: /**
0629: * Creates XML Document for the Main Admin Scheduler Page - The Big Ass List
0630: */
0631: Document showAdminPageUI(Element ele) {
0632: Document document = getDocument(NODE_SUBSCRIPTION_ADMIN, ele);
0633: Element root = document.getRootElement();
0634: try {
0635: doListSchedules(root);
0636: doListContent(root);
0637: doGetSchedulerStatus(root);
0638: root.add(getReturnURL());
0639: } catch (Throwable t) {
0640: root
0641: .add(getException(
0642: Messages
0643: .getString("SubscriptionAdminUIComponent.EXCEPTION_BUILDING_ADMIN_PAGE"), t)); //$NON-NLS-1$
0644: }
0645: return (document);
0646: }
0647:
0648: /**
0649: * Creates XML Document for the Edit Schedules Page - Edit, Delete or New Copy of
0650: * an existing an schedule
0651: */
0652: Document showEditScheduleUI(Element ele) throws Exception {
0653: Element errorEle = validateParameters(
0654: new String[] { "schedId" }, true, null); //$NON-NLS-1$
0655: if (errorEle != null) {
0656: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
0657: }
0658:
0659: String schedId = getParameter("schedId", null); //$NON-NLS-1$
0660: Schedule sched = subscriptionRepository.getSchedule(schedId);
0661: if (sched == null) {
0662: return (showCommandResultUI(
0663: getErrorMessage(Messages
0664: .getString(
0665: "SubscriptionAdminUIComponent.SCHEDULE_NOT_FOUND", getParameter("schedRef", schedId))), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
0666: }
0667:
0668: Document document = getDocument(ACTION_SCHEDULE_SHOW_EDIT, ele);
0669: Element root = document.getRootElement();
0670: root.add(getReturnURL());
0671:
0672: ISubscriptionScheduler subScheduler = PentahoSystem
0673: .getSubscriptionScheduler();
0674: IScheduledJob schedJob = subScheduler.getScheduledJob(sched
0675: .getScheduleReference());
0676:
0677: getJob(sched, schedJob, root);
0678:
0679: List subList = subscriptionRepository
0680: .getSubscriptionsForSchedule(sched);
0681: root.add(getSubscriptions(subList, true));
0682:
0683: List contentList = subscriptionRepository
0684: .getContentBySchedule(sched);
0685: root = root.addElement(ACTION_CONTENT_SHOW_LIST);
0686: root.addAttribute("count", String.valueOf(contentList.size())); //$NON-NLS-1$
0687: for (int i = 0; i < contentList.size(); ++i) {
0688: Element tmpEle = root.addElement(NODE_CONTENT);
0689: tmpEle.addElement("schedId").addText(sched.getId()); //$NON-NLS-1$
0690: tmpEle
0691: .addElement("schedRef").addText(sched.getScheduleReference()); //$NON-NLS-1$
0692: getSubscriptionContent((SubscribeContent) contentList
0693: .get(i), tmpEle);
0694: }
0695:
0696: return (document);
0697: }
0698:
0699: /**
0700: * Performs the Edit Schedule function
0701: */
0702: Document doEditSchedule() throws Exception {
0703: Element errorEle = validateParameters(
0704: new String[] { "schedId" }, true, null); //$NON-NLS-1$
0705: if (errorEle != null) {
0706: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
0707: }
0708: String schedId = getParameter("schedId", null); //$NON-NLS-1$
0709: String cronExpr = getParameter("cron", null); //$NON-NLS-1$
0710: String paramNames[] = new String[] {
0711: "title", "schedRef", "desc", "cron", "group" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
0712:
0713: if (cronExpr != null && false) {
0714: errorEle = validateCronExpression(cronExpr);
0715: if (errorEle != null) {
0716: Document document = showEditScheduleUI(errorEle);
0717: setParametersAsNodes(document.getRootElement(),
0718: paramNames);
0719: return (document);
0720: }
0721: }
0722:
0723: Schedule sched;
0724: try {
0725: sched = subscriptionRepository
0726: .editSchedule(
0727: schedId,
0728: getParameter("title", null), getParameter("schedRef", null), getParameter("desc", null), cronExpr, getParameter("group", null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
0729: } catch (Throwable t) {
0730: Document document = showEditScheduleUI(getException(
0731: Messages
0732: .getString(
0733: "SubscriptionAdminUIComponent.ERROR_EDITING_SCHEDULE", getParameter("schedRef", schedId)), t)); //$NON-NLS-1$ //$NON-NLS-2$
0734: setParametersAsNodes(document.getRootElement(), paramNames);
0735: return (document);
0736: }
0737:
0738: // TODO maybe success should return to details page
0739: return (showCommandResultUI(
0740: getOkMessage(Messages
0741: .getString(
0742: "SubscriptionAdminUIComponent.USER_MODIFIED_SCHEDULE", sched.getScheduleReference())), NODE_STATUS_OK)); //$NON-NLS-1$
0743: }
0744:
0745: /**
0746: * Creates XML Document for the Add Schedules Page - Add a new schedule
0747: */
0748: Document showAddScheduleUI(Element ele) {
0749: Document document = getDocument(ACTION_SCHEDULE_SHOW_ADD, ele);
0750: document.getRootElement().add(getReturnURL());
0751: return (document);
0752: }
0753:
0754: /**
0755: * Performs the Add Schedule function
0756: */
0757: Document doAddSchedule() {
0758: String paramNames[] = new String[] {
0759: "title", "schedRef", "desc", "cron", "group" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
0760: Element errorEle = validateParameters(paramNames, true, null);
0761: if (errorEle != null) {
0762: Document document = showAddScheduleUI(errorEle);
0763: setParametersAsNodes(document.getRootElement(), paramNames);
0764: return (document);
0765: }
0766:
0767: String cronExpr = getParameter("cron", null); //$NON-NLS-1$
0768: errorEle = validateCronExpression(cronExpr);
0769: if (errorEle != null) {
0770: Document document = showAddScheduleUI(errorEle);
0771: setParametersAsNodes(document.getRootElement(), paramNames);
0772: return (document);
0773: }
0774:
0775: String schedRef = getParameter("schedRef", null); //$NON-NLS-1$
0776: try {
0777: subscriptionRepository
0778: .addSchedule(
0779: getParameter("title", null), schedRef, getParameter("desc", null), cronExpr, getParameter("group", null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0780: } catch (Throwable t) {
0781: Document document = showAddScheduleUI(getException(
0782: Messages
0783: .getString(
0784: "SubscriptionAdminUIComponent.ERROR_ADDING_SCHEDULE", schedRef), t)); //$NON-NLS-1$
0785: setParametersAsNodes(document.getRootElement(), paramNames);
0786: return (document);
0787: }
0788:
0789: return (showCommandResultUI(
0790: getOkMessage(Messages
0791: .getString(
0792: "SubscriptionAdminUIComponent.USER_ADDED_SCHEDULE", schedRef)), NODE_STATUS_OK)); //$NON-NLS-1$
0793: }
0794:
0795: /**
0796: * Performs the Add Schedule function
0797: */
0798: Document showAddContentForScheduleUI() {
0799: Element errorEle = validateParameters(
0800: new String[] { "schedId" }, true, null); //$NON-NLS-1$
0801: if (errorEle != null) {
0802: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
0803: }
0804:
0805: String schedId = getParameter("schedId", null); //$NON-NLS-1$
0806: Schedule sched = subscriptionRepository.getSchedule(schedId);
0807: if (sched == null) {
0808: return (showCommandResultUI(
0809: getErrorMessage(Messages
0810: .getString(
0811: "SubscriptionAdminUIComponent.ERROR_SCHEDULE_NOT_FOUND", getParameter("schedRef", schedId))), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
0812: }
0813:
0814: List contentList = subscriptionRepository
0815: .getContentBySchedule(sched);
0816: Set currentContent = new HashSet();
0817: for (int i = 0; i < contentList.size(); ++i) {
0818: currentContent.add(((SubscribeContent) contentList.get(i))
0819: .getActionReference());
0820: }
0821:
0822: Document document = getDocument(
0823: ACTION_SCHEDULE_SHOW_ADD_CONTENT, null);
0824: Element root = document.getRootElement();
0825: root.add(getReturnURL());
0826:
0827: root.add(createTextElement("schedId", schedId)); //$NON-NLS-1$
0828: root.add(createTextElement(
0829: "schedRef", sched.getScheduleReference())); //$NON-NLS-1$
0830:
0831: List allContentList = subscriptionRepository.getAllContent();
0832: Element ele = getCollectionElement(ACTION_CONTENT_SHOW_LIST,
0833: allContentList);
0834: for (int i = 0; i < allContentList.size(); ++i) {
0835: Element tmpEle = ele.addElement(NODE_CONTENT);
0836: SubscribeContent subContent = (SubscribeContent) allContentList
0837: .get(i);
0838: getSubscriptionContent(subContent, tmpEle);
0839: tmpEle
0840: .addAttribute(
0841: "selected", currentContent.contains(subContent.getActionReference()) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0842: }
0843:
0844: root.add(ele);
0845:
0846: return (document);
0847: }
0848:
0849: /**
0850: * Performs the Add Schedule function
0851: */
0852: Document doAddContentForSchedule() {
0853: Element errorEle = validateParameters(
0854: new String[] { "schedId" }, true, null); //$NON-NLS-1$
0855: if (errorEle != null) {
0856: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
0857: }
0858:
0859: String schedId = getParameter("schedId", null); //$NON-NLS-1$
0860: Schedule sched = subscriptionRepository.getSchedule(schedId);
0861: if (sched == null) {
0862: return (showCommandResultUI(
0863: getErrorMessage(Messages
0864: .getString(
0865: "SubscriptionAdminUIComponent.ERROR_SCHEDULE_NOT_FOUND", getParameter("schedRef", schedId))), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
0866: }
0867:
0868: String contentArray[] = getParameterAsArray("contentId"); //$NON-NLS-1$
0869:
0870: try {
0871: subscriptionRepository.setContentForSchedule(contentArray,
0872: schedId);
0873: } catch (Throwable t) {
0874: return (showCommandResultUI(
0875: getException(
0876: Messages
0877: .getString(
0878: "SubscriptionAdminUIComponent.ERROR_SETTING_CONTENT_FOR_SCHEDULE", getParameter("schedRef", schedId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
0879: }
0880:
0881: return (showCommandResultUI(
0882: getOkMessage(Messages
0883: .getString(
0884: "SubscriptionAdminUIComponent.USER_SET_CONTENT_FOR_SCHEDULE", getParameter("schedRef", schedId))), NODE_STATUS_OK)); //$NON-NLS-1$ //$NON-NLS-2$
0885: }
0886:
0887: /**
0888: * Performs the Delete Schedule function
0889: */
0890: Document doDeleteSchedule() {
0891: Element errorEle = validateParameters(
0892: new String[] { "schedId" }, true, null); //$NON-NLS-1$
0893: if (errorEle != null) {
0894: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
0895: }
0896:
0897: String schedId = getParameter("schedId", null); //$NON-NLS-1$
0898: try {
0899: subscriptionRepository.deleteScheduleById(schedId);
0900: } catch (Throwable t) {
0901: return (showCommandResultUI(
0902: getException(
0903: Messages
0904: .getString(
0905: "SubscriptionAdminUIComponent.ERROR_DELETING_SCHEDULE", getParameter("schedRef", schedId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
0906: }
0907:
0908: return (showCommandResultUI(
0909: getOkMessage(Messages
0910: .getString(
0911: "SubscriptionAdminUIComponent.USER_DELETED_SCHEDULE", getParameter("schedRef", schedId))), NODE_STATUS_OK)); //$NON-NLS-1$ //$NON-NLS-2$
0912: }
0913:
0914: /**
0915: * Syncronizes the schedule with the Scheduler's trigger for that subscription
0916: */
0917: Document doScheduleJob() {
0918: Element errorEle = validateParameters(
0919: new String[] { "schedId" }, true, null); //$NON-NLS-1$
0920: if (errorEle != null) {
0921: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
0922: }
0923:
0924: String schedId = getParameter("schedId", null); //$NON-NLS-1$
0925: try {
0926: Schedule sched = subscriptionRepository
0927: .getSchedule(schedId);
0928: if (sched == null) {
0929: return (showCommandResultUI(
0930: getErrorMessage(Messages
0931: .getString(
0932: "SubscriptionAdminUIComponent.ERROR_SCHEDULE_NOT_FOUND", schedId)), NODE_STATUS_ERROR)); //$NON-NLS-1$
0933: } else {
0934: errorEle = validateCronExpression(sched.getCronString());
0935: if (errorEle != null) {
0936: Document document = showCommandResultUI(errorEle,
0937: NODE_STATUS_ERROR);
0938: document
0939: .getRootElement()
0940: .add(
0941: getErrorMessage(Messages
0942: .getString("SubscriptionAdminUIComponent.ERROR_CANNOT_START_SCHEDULE"))); //$NON-NLS-1$
0943: return (document);
0944: }
0945:
0946: if (scheduler.syncSchedule(null, sched) == null) {
0947: return (showCommandResultUI(
0948: getErrorMessage(Messages
0949: .getString(
0950: "SubscriptionAdminUIComponent.ERROR_UNABLE_TO_SCHEDULE_JOB", sched.getScheduleReference())), NODE_STATUS_ERROR)); //$NON-NLS-1$
0951: }
0952: }
0953: } catch (Throwable t) {
0954: return (showCommandResultUI(
0955: getException(
0956: Messages
0957: .getString(
0958: "SubscriptionAdminUIComponent.ERROR_SCHEDULING", getParameter("schedRef", schedId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
0959: }
0960:
0961: return (showCommandResultUI(
0962: getOkMessage(Messages
0963: .getString(
0964: "SubscriptionAdminUIComponent.USER_SCHEDULED", getParameter("schedRef", schedId))), NODE_STATUS_OK)); //$NON-NLS-1$ //$NON-NLS-2$
0965: }
0966:
0967: /**
0968: * Syncronizes all schedules with the Scheduler's triggers
0969: */
0970: Document doScheduleAllJobs() {
0971: try {
0972: List errorMessages = subscriptionRepository.syncSchedules();
0973: if (errorMessages.size() > 0) {
0974: Document document = showCommandResultUI(
0975: getWarningMessage(Messages
0976: .getString("SubscriptionAdminUIComponent.WARNING_NOT_ALL_SCHEDULES_STARTED")), NODE_STATUS_WARNING); //$NON-NLS-1$
0977: Element root = document.getRootElement();
0978: for (int i = 0; i < errorMessages.size(); ++i) {
0979: root.add(getWarningMessage(errorMessages.get(i)
0980: .toString()));
0981: }
0982: return (document);
0983: }
0984: } catch (Throwable t) {
0985: return (showCommandResultUI(
0986: getException(
0987: Messages
0988: .getString("SubscriptionAdminUIComponent.ERROR_SYNCHRONIZING_SCHEDULES"), t), NODE_STATUS_ERROR)); //$NON-NLS-1$
0989: }
0990:
0991: return (showAdminPageUI(getOkMessage(Messages
0992: .getString("SubscriptionAdminUIComponent.USER_SYNCHRONIZE_COMPLETE")))); //$NON-NLS-1$
0993: }
0994:
0995: /**
0996: * Execute a schedule now
0997: */
0998: Document doJobAction(String command) {
0999: Element errorEle = validateParameters(
1000: new String[] { "jobId" }, true, null); //$NON-NLS-1$
1001: if (errorEle != null) {
1002: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1003: }
1004: String jobId = getParameter("jobId", null); //$NON-NLS-1$
1005: String okMessage = ""; //$NON-NLS-1$
1006: try {
1007: if (ACTION_JOB_DO_PAUSE.equals(command)) {
1008: scheduler.pauseJob(jobId);
1009: okMessage = Messages
1010: .getString("SubscriptionAdminUIComponent.USER_PAUSED_JOB"); //$NON-NLS-1$
1011: } else if (ACTION_JOB_DO_RESUME.equals(command)) {
1012: scheduler.resumeJob(jobId);
1013: okMessage = Messages
1014: .getString("SubscriptionAdminUIComponent.USER_RESUMED_JOB"); //$NON-NLS-1$
1015: } else if (ACTION_JOB_DO_DELETE.equals(command)) {
1016: scheduler.deleteJob(jobId);
1017: okMessage = Messages
1018: .getString("SubscriptionAdminUIComponent.USER_DELETED_JOB"); //$NON-NLS-1$
1019: } else if (ACTION_JOB_DO_EXECUTE.equals(command)) {
1020: scheduler.executeJob(jobId);
1021: okMessage = Messages
1022: .getString("SubscriptionAdminUIComponent.USER_SUBMITTED_JOB"); //$NON-NLS-1$
1023: }
1024: } catch (Throwable t) {
1025: return (showCommandResultUI(
1026: getException("", t), NODE_STATUS_ERROR)); //$NON-NLS-1$
1027: }
1028:
1029: return (showCommandResultUI(getOkMessage(okMessage
1030: + getParameter("schedRef", jobId)), NODE_STATUS_OK)); //$NON-NLS-1$
1031: }
1032:
1033: Document doResumeScheduler() {
1034: try {
1035: scheduler.resumeScheduler();
1036: } catch (Throwable t) {
1037: return (showCommandResultUI(
1038: getException(
1039: Messages
1040: .getString("SubscriptionAdminUIComponent.ERROR_RESUMING_SCHEDULER"), t), NODE_STATUS_ERROR)); //$NON-NLS-1$
1041: }
1042: return (showCommandResultUI(
1043: getOkMessage(Messages
1044: .getString("SubscriptionAdminUIComponent.USER_SCHEDULER_RESUMED")), NODE_STATUS_OK)); //$NON-NLS-1$
1045: }
1046:
1047: Document doPauseScheduler() {
1048: try {
1049: scheduler.pauseScheduler();
1050: } catch (Throwable t) {
1051: return (showCommandResultUI(
1052: getException(
1053: Messages
1054: .getString("SubscriptionAdminUIComponent.ERROR_PAUSING_SCHEDULER"), t), NODE_STATUS_ERROR)); //$NON-NLS-1$
1055: }
1056: return (showCommandResultUI(
1057: getOkMessage(Messages
1058: .getString("SubscriptionAdminUIComponent.USER_PAUSED_SCHEDULER")), NODE_STATUS_OK)); //$NON-NLS-1$
1059: }
1060:
1061: /**
1062: * Creates XML Document for the Edit Content Page - Edit, Delete or New Copy of
1063: * an existing an content item
1064: */
1065: Document showEditContentUI(Element ele) throws Exception {
1066: Element errorEle = validateParameters(
1067: new String[] { "contentId" }, true, null); //$NON-NLS-1$
1068: if (errorEle != null) {
1069: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1070: }
1071:
1072: String contentId = getParameter("contentId", null); //$NON-NLS-1$
1073: SubscribeContent subContent = subscriptionRepository
1074: .getContentById(contentId);
1075: if (subContent == null) {
1076: return (showCommandResultUI(
1077: getErrorMessage(Messages
1078: .getString(
1079: "SubscriptionAdminUIComponent.ERROR_CONTENT_NOT_FOUND", getParameter("actionRef", contentId))), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1080: }
1081:
1082: Document document = getDocument(ACTION_CONTENT_SHOW_EDIT, ele);
1083: Element root = document.getRootElement();
1084: getSubscriptionContent(subContent, root);
1085: root.add(getReturnURL());
1086:
1087: List schedulelist = subContent.getSchedules();
1088: ele = getCollectionElement("schedules", schedulelist); //$NON-NLS-1$
1089: for (int i = 0; i < schedulelist.size(); ++i) {
1090: Element tmpEle = getSchedule((Schedule) schedulelist.get(i));
1091: tmpEle.addElement("contentId").addText(contentId); //$NON-NLS-1$
1092: tmpEle
1093: .addElement("actionRef").addText(getParameter("actionRef", contentId)); //$NON-NLS-1$ //$NON-NLS-2$
1094: ele.add(tmpEle);
1095: }
1096: root.add(ele);
1097:
1098: return (document);
1099: }
1100:
1101: private Element getSchedule(Schedule sched) {
1102: Element ele = DocumentHelper.createElement("schedule"); //$NON-NLS-1$
1103: ele.addElement("schedId").addText(sched.getId()); //$NON-NLS-1$
1104: ele
1105: .addElement("schedRef").addText(sched.getScheduleReference()); //$NON-NLS-1$
1106: ele.addElement("title").addText(sched.getTitle()); //$NON-NLS-1$
1107: ele.addElement("desc").addText(sched.getDescription()); //$NON-NLS-1$
1108: ele.addElement("group").addText(sched.getGroup()); //$NON-NLS-1$
1109: return (ele);
1110: }
1111:
1112: private Element getSchedules(List schedList) {
1113: Element ele = getCollectionElement("schedules", schedList); //$NON-NLS-1$
1114:
1115: int listSize = (schedList == null) ? 0 : schedList.size();
1116: for (int i = 0; i < listSize; ++i) {
1117: ele.add(getSchedule((Schedule) schedList.get(i)));
1118: }
1119:
1120: return (ele);
1121: }
1122:
1123: private Element getCollectionElement(String name, Collection c) {
1124: Element ele = DocumentHelper.createElement(name);
1125: if (c == null) {
1126: ele.addAttribute("count", "0"); //$NON-NLS-1$ //$NON-NLS-2$
1127: } else {
1128: ele.addAttribute("count", String.valueOf(c.size())); //$NON-NLS-1$
1129: }
1130: return (ele);
1131: }
1132:
1133: /**
1134: * Performs the Edit Content function
1135: */
1136: Document doEditContent() throws Exception {
1137: Element errorEle = validateParameters(
1138: new String[] { "contentId" }, true, null); //$NON-NLS-1$
1139: if (errorEle != null) {
1140: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1141: }
1142: String contentId = getParameter("contentId", null); //$NON-NLS-1$
1143: String paramNames[] = new String[] { "actionRef", "type" }; //$NON-NLS-1$ //$NON-NLS-2$
1144:
1145: SubscribeContent subContent;
1146: try {
1147: subContent = subscriptionRepository
1148: .editContent(
1149: contentId,
1150: getParameter("actionRef", null), getParameter("type", null)); //$NON-NLS-1$ //$NON-NLS-2$
1151: } catch (Throwable t) {
1152: Document document = showEditContentUI(getException(
1153: Messages
1154: .getString(
1155: "SubscriptionAdminUIComponent.ERROR_EDITING_CONTENT", getParameter("actionRef", contentId)), t)); //$NON-NLS-1$ //$NON-NLS-2$
1156: setParametersAsNodes(document.getRootElement(), paramNames);
1157: return (document);
1158: }
1159:
1160: // TODO maybe success should return to details page
1161: return (showCommandResultUI(
1162: getOkMessage(Messages
1163: .getString(
1164: "SubscriptionAdminUIComponent.USER_MODIFIED_CONTENT", subContent.getActionReference())), NODE_STATUS_OK)); //$NON-NLS-1$
1165: }
1166:
1167: /**
1168: * Creates XML Document for the Add Content Page - Add a new content
1169: */
1170: Document showAddContentUI(Element ele) {
1171: Document document = getDocument(ACTION_CONTENT_SHOW_ADD, ele);
1172: document.getRootElement().add(getReturnURL());
1173:
1174: List contentList = subscriptionRepository.getAllContent();
1175: Set currentContent = new HashSet();
1176: for (int i = 0; i < contentList.size(); ++i) {
1177: currentContent.add(((SubscribeContent) contentList.get(i))
1178: .getActionReference());
1179: }
1180:
1181: ISolutionRepository repository = PentahoSystem
1182: .getSolutionRepository(getSession());
1183: String actionSequences[] = repository.getAllActionSequences();
1184: Arrays.sort(actionSequences, new SolutionCompare()); // Put these babies in order
1185: ele = DocumentHelper.createElement("listContent"); //$NON-NLS-1$
1186: ele.addAttribute(
1187: "count", String.valueOf(actionSequences.length)); //$NON-NLS-1$
1188: for (int i = 0; i < actionSequences.length; ++i) {
1189: String s = actionSequences[i];
1190: Element tmpEle = DocumentHelper
1191: .createElement("content").addText(s); //$NON-NLS-1$
1192: tmpEle
1193: .addAttribute(
1194: "selected", currentContent.contains(s) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1195: ele.add(tmpEle);
1196: }
1197:
1198: document.getRootElement().add(ele);
1199: return (document);
1200: }
1201:
1202: /**
1203: * Performs the Add Content function
1204: */
1205: Document doAddContent() {
1206: String paramNames[] = new String[] { "actionRef" }; //$NON-NLS-1$
1207: Element errorEle = validateParameters(paramNames, true, null);
1208: if (errorEle != null) {
1209: Document document = showAddContentUI(errorEle);
1210: setParametersAsNodes(document.getRootElement(), paramNames);
1211: return (document);
1212: }
1213:
1214: String actionRef[] = getParameterAsArray("actionRef"); //$NON-NLS-1$
1215: try {
1216: subscriptionRepository.setContent(actionRef);
1217: } catch (Throwable t) {
1218: Document document = showAddContentUI(getException(
1219: Messages
1220: .getString("SubscriptionAdminUIComponent.ERROR_SETTING_CONTENT"), t)); //$NON-NLS-1$
1221: setParametersAsNodes(document.getRootElement(), paramNames);
1222: return (document);
1223: }
1224:
1225: return (showCommandResultUI(
1226: getOkMessage(Messages
1227: .getString("SubscriptionAdminUIComponent.USER_SET_SUBSCRIPTION_CONTENT")), NODE_STATUS_OK)); //$NON-NLS-1$
1228: }
1229:
1230: /**
1231: * Performs the Delete Content function
1232: */
1233: Document doDeleteContent() {
1234: Element errorEle = validateParameters(
1235: new String[] { "contentId" }, true, null); //$NON-NLS-1$
1236: if (errorEle != null) {
1237: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1238: }
1239:
1240: String contentId = getParameter("contentId", null); //$NON-NLS-1$
1241: try {
1242: subscriptionRepository
1243: .deleteSubscribeContentById(contentId);
1244: } catch (Throwable t) {
1245: return (showCommandResultUI(
1246: getException(
1247: Messages
1248: .getString(
1249: "SubscriptionAdminUIComponent.ERROR_DELETING_CONTENT", getParameter("actionRef", contentId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1250: }
1251:
1252: return (showCommandResultUI(
1253: getOkMessage(Messages
1254: .getString(
1255: "SubscriptionAdminUIComponent.USER_DELETED_CONTENT", getParameter("actionRef", contentId))), NODE_STATUS_OK)); //$NON-NLS-1$ //$NON-NLS-2$
1256: }
1257:
1258: /**
1259: * Performs the Delete Content function
1260: */
1261: Document doDeleteContentForSchedule() throws Exception {
1262: Element errorEle = validateParameters(new String[] {
1263: "contentId", "schedId" }, true, null); //$NON-NLS-1$ //$NON-NLS-2$
1264: if (errorEle != null) {
1265: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1266: }
1267:
1268: String contentId = getParameter("contentId", null); //$NON-NLS-1$
1269: String schedId = getParameter("schedId", null); //$NON-NLS-1$
1270: try {
1271: subscriptionRepository.deleteContentForSchedule(contentId,
1272: schedId);
1273: } catch (Throwable t) {
1274: return (showCommandResultUI(
1275: getException(
1276: Messages
1277: .getString(
1278: "SubscriptionAdminUIComponent.ERROR_DELETING_CONTENT_FOR_SCHEDULE", getParameter("actionRef", contentId), getParameter("schedRef", schedId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1279: }
1280:
1281: return (showEditContentUI(getOkMessage(Messages
1282: .getString(
1283: "SubscriptionAdminUIComponent.USER_DELETED_CONTENT_FOR_SCHEDULE", getParameter("actionRef", contentId), getParameter("schedRef", schedId))))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1284: }
1285:
1286: /**
1287: * Performs the Add Schedule function
1288: */
1289: Document showAddScheduleForContentUI() {
1290: Element errorEle = validateParameters(
1291: new String[] { "contentId" }, true, null); //$NON-NLS-1$
1292: if (errorEle != null) {
1293: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1294: }
1295:
1296: String contentId = getParameter("contentId", null); //$NON-NLS-1$
1297: SubscribeContent content = subscriptionRepository
1298: .getContentById(contentId);
1299: if (content == null) {
1300: return (showCommandResultUI(
1301: getErrorMessage(Messages
1302: .getString(
1303: "SubscriptionAdminUIComponent.ERROR_CONTENT_NOT_FOUND", getParameter("actionRef", contentId))), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1304: }
1305:
1306: List scheduleList = content.getSchedules();
1307: Set currentSchedules = new HashSet();
1308: for (int i = 0; i < scheduleList.size(); ++i) {
1309: currentSchedules.add(((Schedule) scheduleList.get(i))
1310: .getId());
1311: }
1312:
1313: Document document = getDocument(
1314: ACTION_CONTENT_SHOW_ADD_SCHEDULE, null);
1315: Element root = document.getRootElement();
1316: root.add(getReturnURL());
1317:
1318: root.add(createTextElement("contentId", contentId)); //$NON-NLS-1$
1319: root.add(createTextElement(
1320: "actionRef", content.getActionReference())); //$NON-NLS-1$
1321:
1322: List allScheduleList = subscriptionRepository.getSchedules();
1323: Element ele = getCollectionElement(ACTION_SCHEDULE_SHOW_LIST,
1324: allScheduleList);
1325: for (int i = 0; i < allScheduleList.size(); ++i) {
1326: Schedule sched = (Schedule) allScheduleList.get(i);
1327: Element tmpEle = getSchedule(sched);
1328: tmpEle
1329: .addAttribute(
1330: "selected", currentSchedules.contains(sched.getId()) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1331: ele.add(tmpEle);
1332: }
1333:
1334: root.add(ele);
1335:
1336: return (document);
1337: }
1338:
1339: /**
1340: * Performs the Add Schedule function
1341: */
1342: Document doAddScheduleForContent() {
1343: Element errorEle = validateParameters(
1344: new String[] { "contentId" }, true, null); //$NON-NLS-1$
1345: if (errorEle != null) {
1346: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1347: }
1348:
1349: String contentId = getParameter("contentId", null); //$NON-NLS-1$
1350: SubscribeContent content = subscriptionRepository
1351: .getContentById(contentId);
1352: if (content == null) {
1353: return (showCommandResultUI(
1354: getErrorMessage(Messages
1355: .getString(
1356: "SubscriptionAdminUIComponent.ERROR_CONTENT_NOT_FOUND", getParameter("actionRef", contentId))), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1357: }
1358:
1359: String scheduleArray[] = getParameterAsArray("schedId"); //$NON-NLS-1$
1360:
1361: try {
1362: subscriptionRepository.setSchedulesForContent(
1363: scheduleArray, contentId);
1364: } catch (Throwable t) {
1365: return (showCommandResultUI(
1366: getException(
1367: Messages
1368: .getString(
1369: "SubscriptionAdminUIComponent.ERROR_SETTING_SCHEDULES_FOR_CONTENT", getParameter("actionRef", contentId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1370: }
1371:
1372: return (showCommandResultUI(
1373: getOkMessage(Messages
1374: .getString(
1375: "SubscriptionAdminUIComponent.USER_SET_SCHEDULES_FOR_CONTENT", getParameter("actionRef", contentId))), NODE_STATUS_OK)); //$NON-NLS-1$ //$NON-NLS-2$
1376: }
1377:
1378: Document showImportUI() {
1379: Document document = getDocument(ACTION_SHOW_IMPORT, null);
1380: document.getRootElement().add(getReturnURL());
1381: return (document);
1382: }
1383:
1384: public Document doImport() {
1385:
1386: HttpServletRequest request = ((HttpRequestParameterProvider) getParameterProviders()
1387: .get(HttpRequestParameterProvider.SCOPE_REQUEST))
1388: .getRequest();
1389: String contentType = request.getContentType();
1390: if ((contentType == null)
1391: || (contentType.indexOf("multipart/form-data") < 0 && contentType.indexOf("multipart/mixed stream") < 0)) { //$NON-NLS-1$ //$NON-NLS-2$
1392: return (showCommandResultUI(
1393: getErrorMessage(Messages
1394: .getString("SubscriptionAdminUIComponent.ERROR_IMPORT_FILE_NOT_UPLOADED")), NODE_STATUS_ERROR)); //$NON-NLS-1$
1395: }
1396:
1397: Document importDoc = null;
1398: try {
1399: DiskFileUpload uploader = new DiskFileUpload();
1400:
1401: List fileList = uploader.parseRequest(request);
1402: Iterator iter = fileList.iterator();
1403: while (iter.hasNext()) {
1404: FileItem fi = (FileItem) iter.next();
1405: // Check if not form field so as to only handle the file inputs
1406: if (!fi.isFormField()) {
1407: importDoc = CleanXmlHelper.getDocFromStream(fi
1408: .getInputStream());
1409: break; // Should only be one so stop after finding it
1410: }
1411: }
1412: } catch (Throwable t) {
1413: return (showCommandResultUI(
1414: getException(
1415: Messages
1416: .getString("SubscriptionAdminUIComponent.ERROR_UNABLE_TO_PARSE_FILE"), t), NODE_STATUS_ERROR)); //$NON-NLS-1$
1417: }
1418:
1419: if (importDoc == null) {
1420: return (showCommandResultUI(
1421: getErrorMessage(Messages
1422: .getString("SubscriptionAdminUIComponent.ERROR_IMPORT_FILE_NOT_UPLOADED")), NODE_STATUS_ERROR)); //$NON-NLS-1$
1423: }
1424:
1425: Document document = getDocument(ACTION_SHOW_IMPORT, null);
1426: try {
1427: document.getRootElement().add(
1428: subscriptionRepository.importSchedules(importDoc));
1429: } catch (Throwable t) {
1430: return (showCommandResultUI(
1431: getException(
1432: Messages
1433: .getString("SubscriptionAdminUIComponent.ERROR_IMPORTING_SCHEDULES"), t), NODE_STATUS_ERROR)); //$NON-NLS-1$
1434: }
1435:
1436: try {
1437: document.getRootElement().add(
1438: subscriptionRepository.importContent(importDoc));
1439: } catch (Throwable t) {
1440: return (showCommandResultUI(
1441: getException(
1442: Messages
1443: .getString("SubscriptionAdminUIComponent.ERROR_IMPORTING_CONTENT"), t), NODE_STATUS_ERROR)); //$NON-NLS-1$
1444: }
1445:
1446: return (document);
1447: }
1448:
1449: Document showSubscriptionsPageUI(Element ele) {
1450: String userName = getParameter("user", null); //$NON-NLS-1$
1451:
1452: Document document = getDocument(ACTION_SUBSCRIPTION_SHOW_LIST,
1453: ele);
1454: Element root = document.getRootElement();
1455: try {
1456: List allSubscriptions;
1457: if (userName == null) {
1458: allSubscriptions = subscriptionRepository
1459: .getAllSubscriptions();
1460: } else {
1461: allSubscriptions = subscriptionRepository
1462: .getUserSubscriptions(userName);
1463: }
1464: root.add(getSubscriptions(allSubscriptions, true));
1465: } catch (Throwable t) {
1466: root
1467: .add(getException(
1468: Messages
1469: .getString("SubscriptionAdminUIComponent.ERROR_BUILDING_SUBSCRIPTION_PAGE"), t)); //$NON-NLS-1$
1470: }
1471: return (document);
1472: }
1473:
1474: /**
1475: * Performs the Delete Content function
1476: */
1477: Document doDeleteSubscription() {
1478: Element errorEle = validateParameters(
1479: new String[] { "subscriptionId" }, true, null); //$NON-NLS-1$
1480: if (errorEle != null) {
1481: return (showCommandResultUI(errorEle, NODE_STATUS_ERROR));
1482: }
1483:
1484: String subscriptionId = getParameter("subscriptionId", null); //$NON-NLS-1$
1485: try {
1486: subscriptionRepository.deleteSubscription(subscriptionId);
1487: } catch (Throwable t) {
1488: return (showCommandResultUI(
1489: getException(
1490: Messages
1491: .getString(
1492: "SubscriptionAdminUIComponent.ERROR_DELETING_SUBSCRIPTION", getParameter("title", subscriptionId)), t), NODE_STATUS_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
1493: }
1494:
1495: return (showCommandResultUI(
1496: getOkMessage(Messages
1497: .getString(
1498: "SubscriptionAdminUIComponent.USER_DELETED_SUBSCRIPTION", getParameter("title", subscriptionId))), NODE_STATUS_OK)); //$NON-NLS-1$ //$NON-NLS-2$
1499: }
1500:
1501: // >>>>>>>>>>>>>>>>>
1502:
1503: /** *** Generic Utility Methods ******* */
1504:
1505: /**
1506: * Creates XML Document for the Command Results Page - Displays success or failure
1507: * messages
1508: */
1509: Document showCommandResultUI(Element ele, String result) {
1510: Document document = getDocument(NODE_CMD_RESULT, ele);
1511: Element root = document.getRootElement();
1512: root.addAttribute("result", result); //$NON-NLS-1$
1513: return (document);
1514: }
1515:
1516: Element getReturnParams() {
1517: Element ele = DocumentHelper.createElement(NODE_RETURN_PARAM);
1518: IParameterProvider parameterProvider = (IParameterProvider) getParameterProviders()
1519: .get(HttpRequestParameterProvider.SCOPE_REQUEST);
1520: for (Iterator nameItr = parameterProvider.getParameterNames(); nameItr
1521: .hasNext();) {
1522: String name = (String) nameItr.next();
1523: String value = parameterProvider.getStringParameter(name,
1524: null);
1525: if (value != null) {
1526: ele.addElement(name).addText(value);
1527: }
1528: }
1529: return (ele);
1530: }
1531:
1532: Element getReturnURL() {
1533: Element ele = DocumentHelper.createElement(NODE_RETURN_URL);
1534: IParameterProvider parameterProvider = (IParameterProvider) getParameterProviders()
1535: .get(HttpRequestParameterProvider.SCOPE_REQUEST);
1536: String str = ""; //$NON-NLS-1$
1537: for (Iterator nameItr = parameterProvider.getParameterNames(); nameItr
1538: .hasNext();) {
1539: String name = (String) nameItr.next();
1540: String value = parameterProvider.getStringParameter(name,
1541: null);
1542: if (value != null) {
1543: str += "&" + name + "=" + value; //$NON-NLS-1$ //$NON-NLS-2$
1544: }
1545: }
1546: ele.addText(str);
1547: return (ele);
1548: }
1549:
1550: Element getErrorMessage(String message) {
1551: return (getMessage(NODE_STATUS_ERROR, message));
1552: }
1553:
1554: Element getWarningMessage(String message) {
1555: return (getMessage(NODE_STATUS_WARNING, message));
1556: }
1557:
1558: Element getOkMessage(String message) {
1559: return (getMessage(NODE_STATUS_OK, message));
1560: }
1561:
1562: Element getInfoMessage(String message) {
1563: return (getMessage(NODE_STATUS_INFO, message));
1564: }
1565:
1566: Element getMessage(String type, String message) {
1567: return (DocumentHelper.createElement(NODE_RESULT_MSG)
1568: .addAttribute("result", type).addText(message)); //$NON-NLS-1$
1569: }
1570:
1571: Element getException(String message, Throwable t) {
1572: Element root = DocumentHelper.createElement(NODE_EXCEPTION);
1573: if (message != null) {
1574: root.addElement("message").addText(message); //$NON-NLS-1$
1575: }
1576:
1577: // Some exceptions may have null messages, look for one in the chain.
1578: String exMsg = null;
1579: Throwable tmpT = t;
1580: while ((tmpT != null) && (exMsg == null)) {
1581: exMsg = tmpT.getLocalizedMessage();
1582: tmpT = tmpT.getCause();
1583: }
1584:
1585: root
1586: .addElement("exceptionMessage").addText((exMsg != null) ? exMsg : Messages.getString("SubscriptionAdminUIComponent.ERROR_CAUSE_UNKNOWN", t.getClass().getName())); //$NON-NLS-1$ //$NON-NLS-2$
1587: return (root);
1588: }
1589:
1590: Element createTextElement(String elementName, String text) {
1591: return (DocumentHelper.createElement(elementName).addText(text));
1592: }
1593:
1594: /**
1595: * Verify that the passed in parameterNames exist in the HTTP request. Missing
1596: * parameters are added to ele as new parameter error nodes (see
1597: * NODE_PARAM_ERRORS, and NODE_PARAM_MISSING) If 'ele' is null, a new Element is
1598: * created to contain the error messages. The Element 'ele' is returned to the
1599: * caller unchanged if all the parameters pass verification.
1600: *
1601: * @param ele
1602: * The element that the new parameter error Elements will be added to.
1603: * If null, a new one will be created
1604: * @param paramNames
1605: * The names of the parameters to verify in the request.
1606: * @param notEmpty
1607: * if true, the parameter must exist and can not be the empty string ""
1608: */
1609:
1610: Element validateParameters(String params[], boolean notEmpty,
1611: Element ele) {
1612: String param;
1613: for (int i = 0; i < params.length; ++i) {
1614: param = getParameter(params[i], null);
1615: if ((param == null) || (notEmpty && (param.length() == 0))) {
1616: if (ele == null) {
1617: ele = DocumentHelper
1618: .createElement(NODE_PARAM_ERRORS);
1619: }
1620: ele.addElement(NODE_PARAM_MISSING).addText(params[i]);
1621: }
1622: }
1623: return (ele);
1624: }
1625:
1626: /**
1627: * Adds the passed in parameters from the HTTP request to the passed in XML
1628: * document. The Parameters are added as new Elements to the passed in 'parent'
1629: * Element. If 'parent' is null, a new Element is created to be the parent. The
1630: * parent is returned to the caller.
1631: *
1632: * @param parent
1633: * The element that the new Elements will be added to. If null, a new
1634: * one will be created
1635: * @param paramNames
1636: * The names of the parameters to pull out of the request.
1637: */
1638: void setParametersAsNodes(Element parent, String paramNames[]) {
1639: if ((parent == null) || (paramNames == null)) {
1640: return;
1641: }
1642:
1643: for (int i = 0; i < paramNames.length; ++i) {
1644: Node node = parent.selectSingleNode(paramNames[i]);
1645: if (node instanceof Element) {
1646: ((Element) node)
1647: .setText(getParameter(paramNames[i], "")); //$NON-NLS-1$
1648: } else {
1649: parent.addElement(paramNames[i]).addText(
1650: getParameter(paramNames[i], "")); //$NON-NLS-1$
1651: }
1652: }
1653: }
1654:
1655: /**
1656: * Convienence method for creating a new Document with a root of the passed in
1657: * 'rootName'. If 'ele' is not null, it is added to the Document root.
1658: *
1659: * @param rootName
1660: * Name of the root node to create
1661: * @param ele
1662: * element to add to the new root
1663: * @return The new Document
1664: */
1665: Document getDocument(String rootName, Element ele) {
1666: Document document = DocumentHelper.createDocument();
1667: Element root = document.addElement(rootName);
1668: if (ele != null)
1669: root.add(ele);
1670: return (document);
1671: }
1672:
1673: }
|