0001: /**********************************************************************************
0002: * $URL: $
0003: * $Id: $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2006, 2007 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the "License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.sakaiproject.content.tool;
0021:
0022: import java.io.IOException;
0023: import java.io.InputStream;
0024: import java.io.OutputStream;
0025: import java.net.MalformedURLException;
0026: import java.util.ArrayList;
0027: import java.util.Arrays;
0028: import java.util.Iterator;
0029: import java.util.List;
0030: import java.util.Vector;
0031:
0032: import javax.servlet.http.HttpServletRequest;
0033: import javax.servlet.http.HttpServletResponse;
0034:
0035: import org.apache.commons.logging.Log;
0036: import org.apache.commons.logging.LogFactory;
0037: import org.sakaiproject.cheftool.Context;
0038: import org.sakaiproject.cheftool.JetspeedRunData;
0039: import org.sakaiproject.cheftool.RunData;
0040: import org.sakaiproject.cheftool.VelocityPortlet;
0041: import org.sakaiproject.cheftool.VelocityPortletPaneledAction;
0042: import org.sakaiproject.component.cover.ComponentManager;
0043: import org.sakaiproject.component.cover.ServerConfigurationService;
0044: import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
0045: import org.sakaiproject.content.api.ContentCollection;
0046: import org.sakaiproject.content.api.ContentEntity;
0047: import org.sakaiproject.content.api.MultiFileUploadPipe;
0048: import org.sakaiproject.content.api.ResourceToolAction;
0049: import org.sakaiproject.content.api.ResourceToolActionPipe;
0050: import org.sakaiproject.content.api.ResourceType;
0051: import org.sakaiproject.content.api.ResourceTypeRegistry;
0052: import org.sakaiproject.content.cover.ContentHostingService;
0053: import org.sakaiproject.content.api.ContentTypeImageService;
0054: import org.sakaiproject.entity.api.Entity;
0055: import org.sakaiproject.entity.api.ResourceProperties;
0056: import org.sakaiproject.event.api.SessionState;
0057: import org.sakaiproject.exception.IdUnusedException;
0058: import org.sakaiproject.site.api.Site;
0059: import org.sakaiproject.site.cover.SiteService;
0060: import org.sakaiproject.time.api.Time;
0061: import org.sakaiproject.time.cover.TimeService;
0062: import org.sakaiproject.tool.api.Tool;
0063: import org.sakaiproject.tool.api.ToolException;
0064: import org.sakaiproject.tool.api.ToolSession;
0065: import org.sakaiproject.tool.cover.SessionManager;
0066: import org.sakaiproject.tool.cover.ToolManager;
0067: import org.sakaiproject.util.FileItem;
0068: import org.sakaiproject.util.FormattedText;
0069: import org.sakaiproject.util.ParameterParser;
0070: import org.sakaiproject.util.ResourceLoader;
0071: import org.sakaiproject.util.StringUtil;
0072: import org.sakaiproject.util.Validator;
0073:
0074: public class ResourcesHelperAction extends VelocityPortletPaneledAction {
0075: /** the logger for this class */
0076: private static final Log logger = LogFactory
0077: .getLog(ResourcesHelperAction.class);
0078:
0079: /** Resource bundle using current language locale */
0080: private static ResourceLoader rb = new ResourceLoader("types");
0081:
0082: protected static final String ACCESS_HTML_TEMPLATE = "resources/sakai_access_html";
0083:
0084: protected static final String ACCESS_TEXT_TEMPLATE = "resources/sakai_access_text";
0085:
0086: protected static final String ACCESS_UPLOAD_TEMPLATE = "resources/sakai_access_upload";
0087: protected static final String ACCESS_URL_TEMPLATE = "resources/sakai_access_url";
0088:
0089: /** copyright path -- MUST have same value as AccessServlet.COPYRIGHT_PATH */
0090: public static final String COPYRIGHT_PATH = Entity.SEPARATOR
0091: + "copyright";
0092: private static final String COPYRIGHT_ALERT_URL = ServerConfigurationService
0093: .getAccessUrl()
0094: + COPYRIGHT_PATH;
0095:
0096: protected static final String CREATE_FOLDERS_TEMPLATE = "resources/sakai_create_folders";
0097: protected static final String CREATE_HTML_TEMPLATE = "resources/sakai_create_html";
0098: protected static final String CREATE_TEXT_TEMPLATE = "resources/sakai_create_text";
0099: protected static final String CREATE_UPLOAD_TEMPLATE = "resources/sakai_create_upload";
0100: protected static final String CREATE_UPLOADS_TEMPLATE = "resources/sakai_create_uploads";
0101: protected static final String CREATE_URL_TEMPLATE = "resources/sakai_create_url";
0102: protected static final String CREATE_URLS_TEMPLATE = "resources/sakai_create_urls";
0103:
0104: public static final String MODE_MAIN = "main";
0105: protected static final String PREFIX = "ResourceTypeHelper.";
0106:
0107: protected static final String REVISE_HTML_TEMPLATE = "resources/sakai_revise_html";
0108: protected static final String REVISE_TEXT_TEMPLATE = "resources/sakai_revise_text";
0109: protected static final String REVISE_UPLOAD_TEMPLATE = "resources/sakai_revise_upload";
0110: protected static final String REVISE_URL_TEMPLATE = "resources/sakai_revise_url";
0111:
0112: protected static final String REPLACE_CONTENT_TEMPLATE = "resources/sakai_replace_file";
0113:
0114: /** The content type image lookup service in the State. */
0115: private static final String STATE_CONTENT_TYPE_IMAGE_SERVICE = PREFIX
0116: + "content_type_image_service";
0117:
0118: private static final String STATE_COPYRIGHT_FAIRUSE_URL = PREFIX
0119: + "copyright_fairuse_url";
0120:
0121: private static final String STATE_COPYRIGHT_NEW_COPYRIGHT = PREFIX
0122: + "new_copyright";
0123:
0124: /** copyright related info */
0125: private static final String STATE_COPYRIGHT_TYPES = PREFIX
0126: + "copyright_types";
0127:
0128: private static final String STATE_DEFAULT_COPYRIGHT = PREFIX
0129: + "default_copyright";
0130:
0131: private static final String STATE_DEFAULT_COPYRIGHT_ALERT = PREFIX
0132: + "default_copyright_alert";
0133:
0134: /** state attribute for the maximum size for file upload */
0135: static final String STATE_FILE_UPLOAD_MAX_SIZE = PREFIX
0136: + "file_upload_max_size";
0137:
0138: /** The user copyright string */
0139: private static final String STATE_MY_COPYRIGHT = PREFIX
0140: + "mycopyright";
0141:
0142: private static final String STATE_NEW_COPYRIGHT_INPUT = PREFIX
0143: + "new_copyright_input";
0144:
0145: /** state attribute indicating whether users in current site should be denied option of making resources public */
0146: private static final String STATE_PREVENT_PUBLIC_DISPLAY = PREFIX
0147: + "prevent_public_display";
0148:
0149: /** state attribute indicating whether we're using the Creative Commons dialog instead of the "old" copyright dialog */
0150: protected static final String STATE_USING_CREATIVE_COMMONS = PREFIX
0151: + "usingCreativeCommons";
0152:
0153: /** name of state attribute for the default retract time */
0154: protected static final String STATE_DEFAULT_RETRACT_TIME = PREFIX
0155: + "default_retract_time";
0156:
0157: public String buildAccessContext(VelocityPortlet portlet,
0158: Context context, RunData data, SessionState state) {
0159: String template = ACCESS_TEXT_TEMPLATE;
0160: return template;
0161: }
0162:
0163: public String buildCreateContext(VelocityPortlet portlet,
0164: Context context, RunData data, SessionState state) {
0165: String template = CREATE_UPLOAD_TEMPLATE;
0166:
0167: ToolSession toolSession = SessionManager
0168: .getCurrentToolSession();
0169:
0170: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0171: .getAttribute(ResourceToolAction.ACTION_PIPE);
0172:
0173: //Reference reference = (Reference) toolSession.getAttribute(ResourceToolAction.COLLECTION_REFERENCE);
0174: String typeId = pipe.getAction().getTypeId();
0175:
0176: if (ResourceType.TYPE_TEXT.equals(typeId)) {
0177: template = CREATE_TEXT_TEMPLATE;
0178: } else if (ResourceType.TYPE_HTML.equals(typeId)) {
0179: template = CREATE_HTML_TEMPLATE;
0180: } else if (ResourceType.TYPE_URL.equals(typeId)) {
0181: template = CREATE_URL_TEMPLATE;
0182: } else // assume ResourceType.TYPE_UPLOAD
0183: {
0184: template = CREATE_UPLOAD_TEMPLATE;
0185: }
0186:
0187: return template;
0188: }
0189:
0190: public String buildMainPanelContext(VelocityPortlet portlet,
0191: Context context, RunData data, SessionState state) {
0192: // context.put("sysout", System.out);
0193: context.put("tlang", rb);
0194:
0195: context.put("validator", new Validator());
0196: context.put("copyright_alert_url", COPYRIGHT_ALERT_URL);
0197: context.put("DOT", ListItem.DOT);
0198:
0199: if (state.getAttribute(ResourcesAction.STATE_MESSAGE) != null) {
0200: context.put("itemAlertMessage", state
0201: .getAttribute(ResourcesAction.STATE_MESSAGE));
0202: state.removeAttribute(ResourcesAction.STATE_MESSAGE);
0203: }
0204:
0205: ContentTypeImageService contentTypeImageService = (ContentTypeImageService) state
0206: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE);
0207: context.put("contentTypeImageService", contentTypeImageService);
0208:
0209: String mode = (String) state
0210: .getAttribute(ResourceToolAction.STATE_MODE);
0211:
0212: if (mode == null) {
0213: initHelper(portlet, context, data, state);
0214: }
0215:
0216: ToolSession toolSession = SessionManager
0217: .getCurrentToolSession();
0218: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0219: .getAttribute(ResourceToolAction.ACTION_PIPE);
0220: if (pipe.isActionCompleted()) {
0221: return null;
0222: }
0223:
0224: String actionId = pipe.getAction().getId();
0225:
0226: context.put("GROUP_ACCESS", AccessMode.GROUPED);
0227: context.put("SITE_ACCESS", AccessMode.SITE);
0228: context.put("INHERITED_ACCESS", AccessMode.INHERITED);
0229:
0230: context.put("TYPE_FOLDER", ResourceType.TYPE_FOLDER);
0231: context.put("TYPE_HTML", ResourceType.TYPE_HTML);
0232: context.put("TYPE_TEXT", ResourceType.TYPE_TEXT);
0233: context.put("TYPE_UPLOAD", ResourceType.TYPE_UPLOAD);
0234: context.put("TYPE_URL", ResourceType.TYPE_URL);
0235:
0236: String template = "";
0237:
0238: switch (pipe.getAction().getActionType()) {
0239: case CREATE:
0240: template = buildCreateContext(portlet, context, data, state);
0241: break;
0242: case REVISE_CONTENT:
0243: template = buildReviseContext(portlet, context, data, state);
0244: break;
0245: case REPLACE_CONTENT:
0246: template = buildReplaceContext(portlet, context, data,
0247: state);
0248: break;
0249: case NEW_UPLOAD:
0250: template = buildUploadFilesContext(portlet, context, data,
0251: state);
0252: break;
0253: case NEW_FOLDER:
0254: template = buildNewFoldersContext(portlet, context, data,
0255: state);
0256: break;
0257: case NEW_URLS:
0258: template = buildNewUrlsContext(portlet, context, data,
0259: state);
0260: break;
0261: default:
0262: // hmmmm
0263: break;
0264: }
0265:
0266: return template;
0267: }
0268:
0269: protected String buildNewUrlsContext(VelocityPortlet portlet,
0270: Context context, RunData data, SessionState state) {
0271: ToolSession toolSession = SessionManager
0272: .getCurrentToolSession();
0273:
0274: MultiFileUploadPipe pipe = (MultiFileUploadPipe) toolSession
0275: .getAttribute(ResourceToolAction.ACTION_PIPE);
0276:
0277: List<ResourceToolActionPipe> pipes = pipe.getPipes();
0278:
0279: Time defaultRetractDate = (Time) state
0280: .getAttribute(STATE_DEFAULT_RETRACT_TIME);
0281: if (defaultRetractDate == null) {
0282: defaultRetractDate = TimeService.newTime();
0283: state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
0284: defaultRetractDate);
0285: }
0286:
0287: Boolean preventPublicDisplay = (Boolean) state
0288: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0289: if (preventPublicDisplay == null) {
0290: preventPublicDisplay = Boolean.FALSE;
0291: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0292: preventPublicDisplay);
0293: }
0294:
0295: ListItem parent = new ListItem(pipe.getContentEntity());
0296: parent.setPubviewPossible(!preventPublicDisplay);
0297: ListItem model = new ListItem(pipe, parent, defaultRetractDate);
0298: // model.setPubviewPossible(! preventPublicDisplay);
0299:
0300: context.put("model", model);
0301: context.put("type", model.getResourceTypeDef());
0302:
0303: context.put("pipes", pipes);
0304:
0305: if (ContentHostingService.isAvailabilityEnabled()) {
0306: context.put("availability_is_enabled", Boolean.TRUE);
0307: }
0308:
0309: ResourcesAction.copyrightChoicesIntoContext(state, context);
0310: ResourcesAction.publicDisplayChoicesIntoContext(state, context);
0311:
0312: return CREATE_URLS_TEMPLATE;
0313: }
0314:
0315: /**
0316: * @param portlet
0317: * @param context
0318: * @param data
0319: * @param state
0320: * @return
0321: */
0322: private String buildNewFoldersContext(VelocityPortlet portlet,
0323: Context context, RunData data, SessionState state) {
0324: ToolSession toolSession = SessionManager
0325: .getCurrentToolSession();
0326:
0327: MultiFileUploadPipe pipe = (MultiFileUploadPipe) toolSession
0328: .getAttribute(ResourceToolAction.ACTION_PIPE);
0329:
0330: List<ResourceToolActionPipe> pipes = pipe.getPipes();
0331:
0332: Time defaultRetractDate = (Time) state
0333: .getAttribute(STATE_DEFAULT_RETRACT_TIME);
0334: if (defaultRetractDate == null) {
0335: defaultRetractDate = TimeService.newTime();
0336: state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
0337: defaultRetractDate);
0338: }
0339:
0340: Boolean preventPublicDisplay = (Boolean) state
0341: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0342: if (preventPublicDisplay == null) {
0343: preventPublicDisplay = Boolean.FALSE;
0344: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0345: preventPublicDisplay);
0346: }
0347:
0348: ListItem parent = new ListItem(pipe.getContentEntity());
0349: parent.setPubviewPossible(!preventPublicDisplay);
0350: ListItem model = new ListItem(pipe, parent, defaultRetractDate);
0351: // model.setPubviewPossible(! preventPublicDisplay);
0352:
0353: context.put("model", model);
0354: context.put("type", model.getResourceTypeDef());
0355:
0356: context.put("pipes", pipes);
0357:
0358: if (ContentHostingService.isAvailabilityEnabled()) {
0359: context.put("availability_is_enabled", Boolean.TRUE);
0360: }
0361:
0362: ResourcesAction.publicDisplayChoicesIntoContext(state, context);
0363:
0364: return CREATE_FOLDERS_TEMPLATE;
0365: }
0366:
0367: /**
0368: * @param portlet
0369: * @param context
0370: * @param data
0371: * @param state
0372: * @return
0373: */
0374: protected String buildReplaceContext(VelocityPortlet portlet,
0375: Context context, RunData data, SessionState state) {
0376: ToolSession toolSession = SessionManager
0377: .getCurrentToolSession();
0378:
0379: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0380: .getAttribute(ResourceToolAction.ACTION_PIPE);
0381:
0382: Boolean preventPublicDisplay = (Boolean) state
0383: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0384: if (preventPublicDisplay == null) {
0385: preventPublicDisplay = Boolean.FALSE;
0386: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0387: preventPublicDisplay);
0388: }
0389:
0390: ListItem item = new ListItem(pipe.getContentEntity());
0391: item.setPubviewPossible(!preventPublicDisplay);
0392:
0393: context.put("item", item);
0394:
0395: return REPLACE_CONTENT_TEMPLATE;
0396: }
0397:
0398: public String buildReviseContext(VelocityPortlet portlet,
0399: Context context, RunData data, SessionState state) {
0400: String template = REVISE_TEXT_TEMPLATE;
0401: ToolSession toolSession = SessionManager
0402: .getCurrentToolSession();
0403:
0404: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0405: .getAttribute(ResourceToolAction.ACTION_PIPE);
0406:
0407: //Reference reference = (Reference) toolSession.getAttribute(ResourceToolAction.COLLECTION_REFERENCE);
0408: String typeId = pipe.getAction().getTypeId();
0409: String mimetype = pipe.getMimeType();
0410:
0411: context.put("pipe", pipe);
0412:
0413: if (ResourceType.TYPE_TEXT.equals(typeId)) {
0414: template = REVISE_TEXT_TEMPLATE;
0415: } else if (ResourceType.TYPE_HTML.equals(typeId)) {
0416: template = REVISE_HTML_TEMPLATE;
0417: } else if (ResourceType.TYPE_URL.equals(typeId)) {
0418: template = REVISE_URL_TEMPLATE;
0419: } else if (ResourceType.TYPE_UPLOAD.equals(typeId)
0420: && mimetype != null
0421: && ResourceType.MIME_TYPE_HTML.equals(mimetype)) {
0422: template = REVISE_HTML_TEMPLATE;
0423: } else if (ResourceType.TYPE_UPLOAD.equals(typeId)
0424: && mimetype != null
0425: && ResourceType.MIME_TYPE_TEXT.equals(mimetype)) {
0426: template = REVISE_TEXT_TEMPLATE;
0427: } else // assume ResourceType.TYPE_UPLOAD
0428: {
0429: template = REVISE_UPLOAD_TEMPLATE;
0430: }
0431:
0432: return template;
0433: }
0434:
0435: /**
0436: * @param portlet
0437: * @param context
0438: * @param data
0439: * @param state
0440: * @return
0441: */
0442: protected String buildUploadFilesContext(VelocityPortlet portlet,
0443: Context context, RunData data, SessionState state) {
0444: ToolSession toolSession = SessionManager
0445: .getCurrentToolSession();
0446:
0447: String max_file_size_mb = (String) state
0448: .getAttribute(STATE_FILE_UPLOAD_MAX_SIZE);
0449: if (max_file_size_mb == null) {
0450: max_file_size_mb = "20";
0451: }
0452: String upload_limit = rb.getFormattedMessage("upload.limit",
0453: new String[] { max_file_size_mb });
0454: context.put("upload_limit", upload_limit);
0455:
0456: // int max_bytes = 1024 * 1024;
0457: // try
0458: // {
0459: // max_bytes = Integer.parseInt(max_file_size_mb) * 1024 * 1024;
0460: // }
0461: // catch(Exception e)
0462: // {
0463: // // if unable to parse an integer from the value
0464: // // in the properties file, use 1 MB as a default
0465: // max_file_size_mb = "1";
0466: // max_bytes = 1024 * 1024;
0467: // }
0468:
0469: MultiFileUploadPipe pipe = (MultiFileUploadPipe) toolSession
0470: .getAttribute(ResourceToolAction.ACTION_PIPE);
0471:
0472: List<ResourceToolActionPipe> pipes = pipe.getPipes();
0473:
0474: Time defaultRetractDate = (Time) state
0475: .getAttribute(STATE_DEFAULT_RETRACT_TIME);
0476: if (defaultRetractDate == null) {
0477: defaultRetractDate = TimeService.newTime();
0478: state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
0479: defaultRetractDate);
0480: }
0481:
0482: Boolean preventPublicDisplay = (Boolean) state
0483: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0484: if (preventPublicDisplay == null) {
0485: preventPublicDisplay = Boolean.FALSE;
0486: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0487: preventPublicDisplay);
0488: }
0489:
0490: ListItem parent = new ListItem(pipe.getContentEntity());
0491: parent.setPubviewPossible(!preventPublicDisplay);
0492: ListItem model = new ListItem(pipe, parent, defaultRetractDate);
0493: // model.setPubviewPossible(! preventPublicDisplay);
0494:
0495: context.put("model", model);
0496: context.put("type", model.getResourceTypeDef());
0497:
0498: context.put("pipes", pipes);
0499:
0500: if (ContentHostingService.isAvailabilityEnabled()) {
0501: context.put("availability_is_enabled", Boolean.TRUE);
0502: }
0503:
0504: ResourcesAction.copyrightChoicesIntoContext(state, context);
0505: ResourcesAction.publicDisplayChoicesIntoContext(state, context);
0506:
0507: String defaultCopyrightStatus = (String) state
0508: .getAttribute(STATE_DEFAULT_COPYRIGHT);
0509: if (defaultCopyrightStatus == null
0510: || defaultCopyrightStatus.trim().equals("")) {
0511: defaultCopyrightStatus = ServerConfigurationService
0512: .getString("default.copyright");
0513: state.setAttribute(STATE_DEFAULT_COPYRIGHT,
0514: defaultCopyrightStatus);
0515: }
0516:
0517: context.put("defaultCopyrightStatus", defaultCopyrightStatus);
0518:
0519: return CREATE_UPLOADS_TEMPLATE;
0520: }
0521:
0522: public void doCancel(RunData data) {
0523: SessionState state = ((JetspeedRunData) data)
0524: .getPortletSessionState(((JetspeedRunData) data)
0525: .getJs_peid());
0526: ParameterParser params = data.getParameters();
0527: ToolSession toolSession = SessionManager
0528: .getCurrentToolSession();
0529:
0530: //Tool tool = ToolManager.getCurrentTool();
0531: //String url = (String) toolSession.getAttribute(tool.getId() + Tool.HELPER_DONE_URL);
0532: //toolSession.removeAttribute(tool.getId() + Tool.HELPER_DONE_URL);
0533:
0534: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0535: .getAttribute(ResourceToolAction.ACTION_PIPE);
0536: pipe.setActionCanceled(true);
0537: pipe.setErrorEncountered(false);
0538: pipe.setActionCompleted(true);
0539:
0540: toolSession.setAttribute(ResourceToolAction.DONE, Boolean.TRUE);
0541:
0542: }
0543:
0544: public void doContinue(RunData data) {
0545: SessionState state = ((JetspeedRunData) data)
0546: .getPortletSessionState(((JetspeedRunData) data)
0547: .getJs_peid());
0548: ParameterParser params = data.getParameters();
0549:
0550: String content = params.getString("content");
0551: if (content == null) {
0552: addAlert(state, rb.getString("text.notext"));
0553: return;
0554: }
0555: ToolSession toolSession = SessionManager
0556: .getCurrentToolSession();
0557:
0558: // Tool tool = ToolManager.getCurrentTool();
0559: // String url = (String) toolSession.getAttribute(tool.getId() + Tool.HELPER_DONE_URL);
0560: // toolSession.removeAttribute(tool.getId() + Tool.HELPER_DONE_URL);
0561:
0562: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0563: .getAttribute(ResourceToolAction.ACTION_PIPE);
0564:
0565: String resourceType = pipe.getAction().getTypeId();
0566: String mimetype = pipe.getMimeType();
0567:
0568: pipe.setRevisedMimeType(pipe.getMimeType());
0569: if (ResourceType.TYPE_TEXT.equals(resourceType)
0570: || ResourceType.MIME_TYPE_TEXT.equals(mimetype)) {
0571: pipe.setRevisedMimeType(ResourceType.MIME_TYPE_TEXT);
0572: pipe.setRevisedResourceProperty(
0573: ResourceProperties.PROP_CONTENT_ENCODING,
0574: ResourcesAction.UTF_8_ENCODING);
0575:
0576: } else if (ResourceType.TYPE_HTML.equals(resourceType)
0577: || ResourceType.MIME_TYPE_HTML.equals(mimetype)) {
0578: StringBuffer alertMsg = new StringBuffer();
0579: content = FormattedText.processHtmlDocument(content,
0580: alertMsg);
0581: pipe.setRevisedMimeType(ResourceType.MIME_TYPE_HTML);
0582: pipe.setRevisedResourceProperty(
0583: ResourceProperties.PROP_CONTENT_ENCODING,
0584: ResourcesAction.UTF_8_ENCODING);
0585: if (alertMsg.length() > 0) {
0586: addAlert(state, alertMsg.toString());
0587: return;
0588: }
0589: } else if (ResourceType.TYPE_URL.equals(resourceType)) {
0590: pipe.setRevisedMimeType(ResourceType.MIME_TYPE_URL);
0591: } else if (ResourceType.TYPE_FOLDER.equals(resourceType)) {
0592: MultiFileUploadPipe mfp = (MultiFileUploadPipe) pipe;
0593: int count = params.getInt("folderCount");
0594: mfp.setFileCount(count);
0595:
0596: List<ResourceToolActionPipe> pipes = mfp.getPipes();
0597: for (int i = 0; i < pipes.size(); i++) {
0598: ResourceToolActionPipe fp = pipes.get(i);
0599: String folderName = params
0600: .getString("folder" + (i + 1));
0601: fp.setFileName(folderName);
0602: }
0603: }
0604:
0605: pipe.setRevisedContent(content.getBytes());
0606: pipe.setActionCanceled(false);
0607: pipe.setErrorEncountered(false);
0608: pipe.setActionCompleted(true);
0609:
0610: toolSession.setAttribute(ResourceToolAction.DONE, Boolean.TRUE);
0611:
0612: }
0613:
0614: public void doCreateFolders(RunData data) {
0615: SessionState state = ((JetspeedRunData) data)
0616: .getPortletSessionState(((JetspeedRunData) data)
0617: .getJs_peid());
0618: ParameterParser params = data.getParameters();
0619:
0620: ToolSession toolSession = SessionManager
0621: .getCurrentToolSession();
0622:
0623: MultiFileUploadPipe pipe = (MultiFileUploadPipe) toolSession
0624: .getAttribute(ResourceToolAction.ACTION_PIPE);
0625:
0626: String resourceType = pipe.getAction().getTypeId();
0627:
0628: int count = params.getInt("fileCount");
0629: pipe.setFileCount(count);
0630:
0631: int lastIndex = params.getInt("lastIndex");
0632:
0633: ContentEntity entity = pipe.getContentEntity();
0634: ListItem parent = null;
0635: if (entity != null && entity instanceof ContentCollection) {
0636: ContentCollection containingCollection = (ContentCollection) entity;
0637:
0638: Boolean preventPublicDisplay = (Boolean) state
0639: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0640: if (preventPublicDisplay == null) {
0641: preventPublicDisplay = Boolean.FALSE;
0642: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0643: preventPublicDisplay);
0644: }
0645:
0646: parent = new ListItem(entity);
0647: parent.setPubviewPossible(!preventPublicDisplay);
0648: }
0649:
0650: List<ResourceToolActionPipe> pipes = pipe.getPipes();
0651:
0652: for (int i = 1, c = 0; i <= lastIndex && c < count; i++) {
0653: String exists = params.getString("exists" + ListItem.DOT
0654: + i);
0655: if (exists == null || exists.equals("")) {
0656: continue;
0657: }
0658: ResourceToolActionPipe fp = pipes.get(c);
0659: String folderName = params.getString("content"
0660: + ListItem.DOT + i);
0661:
0662: fp.setFileName(folderName);
0663:
0664: ListItem newFolder = (ListItem) fp.getRevisedListItem();
0665: if (newFolder == null) {
0666: if (parent == null) {
0667: newFolder = new ListItem(folderName);
0668: } else {
0669: Time defaultRetractDate = (Time) state
0670: .getAttribute(STATE_DEFAULT_RETRACT_TIME);
0671: if (defaultRetractDate == null) {
0672: defaultRetractDate = TimeService.newTime();
0673: state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
0674: defaultRetractDate);
0675: }
0676:
0677: newFolder = new ListItem(fp, parent,
0678: defaultRetractDate);
0679: newFolder.setName(folderName);
0680: newFolder.setId(folderName);
0681: }
0682: }
0683:
0684: // capture properties
0685: newFolder.captureProperties(params, ListItem.DOT + i);
0686:
0687: fp.setRevisedListItem(newFolder);
0688:
0689: c++;
0690: }
0691:
0692: pipe.setActionCanceled(false);
0693: pipe.setErrorEncountered(false);
0694: pipe.setActionCompleted(true);
0695:
0696: toolSession.setAttribute(ResourceToolAction.DONE, Boolean.TRUE);
0697:
0698: }
0699:
0700: public void doReplace(RunData data) {
0701: SessionState state = ((JetspeedRunData) data)
0702: .getPortletSessionState(((JetspeedRunData) data)
0703: .getJs_peid());
0704: ParameterParser params = data.getParameters();
0705: ToolSession toolSession = SessionManager
0706: .getCurrentToolSession();
0707:
0708: ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
0709: .getAttribute(ResourceToolAction.ACTION_PIPE);
0710:
0711: FileItem fileitem = null;
0712: try {
0713: fileitem = params.getFileItem("content");
0714: } catch (Exception e) {
0715: logger.warn("Exception ", e);
0716: }
0717:
0718: if (fileitem == null) {
0719: String max_file_size_mb = (String) state
0720: .getAttribute(ResourcesAction.STATE_FILE_UPLOAD_MAX_SIZE);
0721: int max_bytes = 1024 * 1024;
0722: try {
0723: max_bytes = Integer.parseInt(max_file_size_mb) * 1024 * 1024;
0724: } catch (Exception e) {
0725: // if unable to parse an integer from the value
0726: // in the properties file, use 1 MB as a default
0727: max_file_size_mb = "1";
0728: max_bytes = 1024 * 1024;
0729: }
0730:
0731: String max_bytes_string = ResourcesAction
0732: .getFileSizeString(max_bytes, rb);
0733: // "The user submitted a file to upload but it was too big!"
0734: addAlert(state, rb.getFormattedMessage("size.exceeded",
0735: new Object[] { max_bytes_string }));
0736: //max_file_size_mb + "MB " + rb.getString("exceeded2"));
0737: } else if (fileitem.getFileName() == null
0738: || fileitem.getFileName().length() == 0) {
0739: addAlert(state, rb.getString("choosefile7"));
0740: } else if (fileitem.getFileName().length() > 0) {
0741: String filename = Validator.getFileName(fileitem
0742: .getFileName());
0743: InputStream stream;
0744: stream = fileitem.getInputStream();
0745: if (stream == null) {
0746: byte[] bytes = fileitem.get();
0747: pipe.setRevisedContent(bytes);
0748: } else {
0749: pipe.setRevisedContentStream(stream);
0750: }
0751: String contentType = fileitem.getContentType();
0752: //pipe.setRevisedContent(bytes);
0753: pipe.setRevisedMimeType(contentType);
0754: pipe.setFileName(filename);
0755:
0756: if (ResourceType.MIME_TYPE_HTML.equals(contentType)
0757: || ResourceType.MIME_TYPE_TEXT.equals(contentType)) {
0758: pipe.setRevisedResourceProperty(
0759: ResourceProperties.PROP_CONTENT_ENCODING,
0760: ResourcesAction.UTF_8_ENCODING);
0761: } else if (pipe
0762: .getPropertyValue(ResourceProperties.PROP_CONTENT_ENCODING) != null) {
0763: pipe
0764: .setRevisedResourceProperty(
0765: ResourceProperties.PROP_CONTENT_ENCODING,
0766: (String) pipe
0767: .getPropertyValue(ResourceProperties.PROP_CONTENT_ENCODING));
0768: }
0769:
0770: ListItem newFile = new ListItem(filename);
0771:
0772: pipe.setRevisedListItem(newFile);
0773:
0774: pipe.setActionCanceled(false);
0775: pipe.setErrorEncountered(false);
0776: pipe.setActionCompleted(true);
0777:
0778: toolSession.setAttribute(ResourceToolAction.DONE,
0779: Boolean.TRUE);
0780: }
0781:
0782: }
0783:
0784: public void doAddUrls(RunData data) {
0785: SessionState state = ((JetspeedRunData) data)
0786: .getPortletSessionState(((JetspeedRunData) data)
0787: .getJs_peid());
0788: ParameterParser params = data.getParameters();
0789: ToolSession toolSession = SessionManager
0790: .getCurrentToolSession();
0791:
0792: MultiFileUploadPipe mfp = (MultiFileUploadPipe) toolSession
0793: .getAttribute(ResourceToolAction.ACTION_PIPE);
0794:
0795: int count = params.getInt("fileCount");
0796: mfp.setFileCount(count);
0797:
0798: int lastIndex = params.getInt("lastIndex");
0799:
0800: ContentEntity entity = mfp.getContentEntity();
0801: ListItem parent = null;
0802: if (entity != null && entity instanceof ContentCollection) {
0803: ContentCollection containingCollection = (ContentCollection) entity;
0804:
0805: Boolean preventPublicDisplay = (Boolean) state
0806: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0807: if (preventPublicDisplay == null) {
0808: preventPublicDisplay = Boolean.FALSE;
0809: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0810: preventPublicDisplay);
0811: }
0812:
0813: parent = new ListItem(entity);
0814: parent.setPubviewPossible(!preventPublicDisplay);
0815: }
0816:
0817: List<String> alerts = new Vector<String>();
0818:
0819: List<ResourceToolActionPipe> pipes = mfp.getPipes();
0820:
0821: int actualCount = 0;
0822: for (int i = 1; i <= lastIndex && actualCount < count; i++) {
0823: String exists = params.getString("exists" + ListItem.DOT
0824: + i);
0825: if (exists == null || exists.equals("")) {
0826: continue;
0827: }
0828:
0829: ResourceToolActionPipe pipe = pipes.get(actualCount);
0830:
0831: String url = params.getString("content" + ListItem.DOT + i);
0832: if (url == null) {
0833: continue;
0834: } else {
0835: try {
0836: url = ResourcesAction.validateURL(url);
0837: } catch (MalformedURLException e) {
0838: addAlert(state, rb.getFormattedMessage(
0839: "url.invalid", new String[] { url }));
0840: continue;
0841: }
0842:
0843: pipe.setRevisedContent(url.getBytes());
0844: }
0845:
0846: pipe.setFileName(Validator.escapeResourceName(url));
0847: pipe.setRevisedMimeType(ResourceType.MIME_TYPE_URL);
0848:
0849: ListItem newFile = (ListItem) pipe.getRevisedListItem();
0850: if (newFile == null) {
0851: if (parent == null) {
0852: newFile = new ListItem(pipe.getFileName());
0853: } else {
0854: Time defaultRetractDate = (Time) state
0855: .getAttribute(STATE_DEFAULT_RETRACT_TIME);
0856: if (defaultRetractDate == null) {
0857: defaultRetractDate = TimeService.newTime();
0858: state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
0859: defaultRetractDate);
0860: }
0861:
0862: newFile = new ListItem(mfp, parent,
0863: defaultRetractDate);
0864: newFile
0865: .setName(new String(pipe
0866: .getRevisedContent()));
0867: newFile.setId(pipe.getFileName());
0868: }
0869: }
0870:
0871: // capture properties
0872: newFile.captureProperties(params, ListItem.DOT + i);
0873:
0874: //alerts.addAll(newFile.checkRequiredProperties());
0875:
0876: pipe.setRevisedListItem(newFile);
0877:
0878: actualCount++;
0879:
0880: }
0881: if (!alerts.isEmpty()) {
0882: for (String alert : alerts) {
0883: addAlert(state, alert);
0884: }
0885: }
0886:
0887: if (actualCount < 1) {
0888: addAlert(state, rb.getString("url.noinput"));
0889: return;
0890: }
0891:
0892: mfp.setActionCanceled(false);
0893: mfp.setErrorEncountered(false);
0894: mfp.setActionCompleted(true);
0895:
0896: toolSession.setAttribute(ResourceToolAction.DONE, Boolean.TRUE);
0897:
0898: }
0899:
0900: public void doUpload(RunData data) {
0901: SessionState state = ((JetspeedRunData) data)
0902: .getPortletSessionState(((JetspeedRunData) data)
0903: .getJs_peid());
0904: ParameterParser params = data.getParameters();
0905: ToolSession toolSession = SessionManager
0906: .getCurrentToolSession();
0907:
0908: MultiFileUploadPipe mfp = (MultiFileUploadPipe) toolSession
0909: .getAttribute(ResourceToolAction.ACTION_PIPE);
0910:
0911: int count = params.getInt("fileCount");
0912: mfp.setFileCount(count);
0913:
0914: int lastIndex = params.getInt("lastIndex");
0915:
0916: List<String> allAlerts = new Vector<String>();
0917:
0918: ContentEntity entity = mfp.getContentEntity();
0919: ListItem parent = null;
0920: if (entity != null && entity instanceof ContentCollection) {
0921: ContentCollection containingCollection = (ContentCollection) entity;
0922:
0923: Boolean preventPublicDisplay = (Boolean) state
0924: .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
0925: if (preventPublicDisplay == null) {
0926: preventPublicDisplay = Boolean.FALSE;
0927: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
0928: preventPublicDisplay);
0929: }
0930:
0931: parent = new ListItem(entity);
0932: parent.setPubviewPossible(!preventPublicDisplay);
0933: }
0934:
0935: List<ResourceToolActionPipe> pipes = mfp.getPipes();
0936:
0937: int uploadCount = 0;
0938:
0939: for (int i = 1, c = 0; i <= lastIndex && c < count; i++) {
0940: String exists = params.getString("exists" + ListItem.DOT
0941: + i);
0942: if (exists == null || exists.equals("")) {
0943: continue;
0944: }
0945:
0946: ResourceToolActionPipe pipe = pipes.get(c);
0947:
0948: FileItem fileitem = null;
0949: try {
0950: fileitem = params.getFileItem("content" + ListItem.DOT
0951: + i);
0952: } catch (Exception e) {
0953: logger.warn("Exception ", e);
0954: }
0955:
0956: if (fileitem == null) {
0957: String max_file_size_mb = (String) state
0958: .getAttribute(ResourcesAction.STATE_FILE_UPLOAD_MAX_SIZE);
0959: int max_bytes = 1024 * 1024;
0960: try {
0961: max_bytes = Integer.parseInt(max_file_size_mb) * 1024 * 1024;
0962: } catch (Exception e) {
0963: // if unable to parse an integer from the value
0964: // in the properties file, use 1 MB as a default
0965: max_file_size_mb = "1";
0966: max_bytes = 1024 * 1024;
0967: }
0968:
0969: String max_bytes_string = ResourcesAction
0970: .getFileSizeString(max_bytes, rb);
0971: // "The user submitted a file to upload but it was too big!"
0972: addAlert(state, rb.getFormattedMessage("size.exceeded",
0973: new Object[] { max_bytes_string }));
0974: //max_file_size_mb + "MB " + rb.getString("exceeded2"));
0975: } else if (fileitem.getFileName() == null
0976: || fileitem.getFileName().length() == 0) {
0977: // no file selected -- skip this one
0978: } else if (fileitem.getFileName().length() > 0) {
0979: String filename = Validator.getFileName(fileitem
0980: .getFileName());
0981: InputStream stream;
0982: stream = fileitem.getInputStream();
0983: if (stream == null) {
0984: byte[] bytes = fileitem.get();
0985: pipe.setRevisedContent(bytes);
0986: } else {
0987: pipe.setRevisedContentStream(stream);
0988: }
0989: String contentType = fileitem.getContentType();
0990: //pipe.setRevisedContent(bytes);
0991: pipe.setRevisedMimeType(contentType);
0992:
0993: // if(ResourceType.MIME_TYPE_HTML.equals(contentType) || ResourceType.MIME_TYPE_TEXT.equals(contentType))
0994: // {
0995: // pipe.setRevisedResourceProperty(ResourceProperties.PROP_CONTENT_ENCODING, ResourcesAction.UTF_8_ENCODING);
0996: // }
0997: // else if(pipe.getPropertyValue(ResourceProperties.PROP_CONTENT_ENCODING) != null)
0998: // {
0999: // pipe.setRevisedResourceProperty(ResourceProperties.PROP_CONTENT_ENCODING, (String) pipe.getPropertyValue(ResourceProperties.PROP_CONTENT_ENCODING));
1000: // }
1001:
1002: pipe.setFileName(filename);
1003:
1004: ListItem newFile = (ListItem) pipe.getRevisedListItem();
1005: if (newFile == null) {
1006: if (parent == null) {
1007: newFile = new ListItem(filename);
1008: } else {
1009: Time defaultRetractDate = (Time) state
1010: .getAttribute(STATE_DEFAULT_RETRACT_TIME);
1011: if (defaultRetractDate == null) {
1012: defaultRetractDate = TimeService.newTime();
1013: state.setAttribute(
1014: STATE_DEFAULT_RETRACT_TIME,
1015: defaultRetractDate);
1016: }
1017:
1018: newFile = new ListItem(pipe, parent,
1019: defaultRetractDate);
1020: newFile.setName(filename);
1021: newFile.setId(filename);
1022: }
1023: }
1024:
1025: // capture properties
1026: newFile.captureProperties(params, ListItem.DOT + i);
1027:
1028: // allAlerts.addAll(newFile.checkRequiredProperties());
1029:
1030: pipe.setRevisedListItem(newFile);
1031:
1032: uploadCount++;
1033:
1034: }
1035: c++;
1036:
1037: }
1038:
1039: if (uploadCount < 1
1040: && state.getAttribute(ResourcesAction.STATE_MESSAGE) == null) {
1041: HttpServletRequest req = data.getRequest();
1042: String status = (String) req.getAttribute("upload.status");
1043: if (status == null) {
1044: logger.warn("No files uploaded; upload.status == null");
1045: } else if (status.equals("ok")) {
1046: logger.warn("No files uploaded; upload.status == ok");
1047: } else if (status.equals("size_limit_exceeded")) {
1048: String max_file_size_mb = (String) state
1049: .getAttribute(ResourcesAction.STATE_FILE_UPLOAD_MAX_SIZE);
1050: int max_bytes = 1024 * 1024;
1051: try {
1052: max_bytes = Integer.parseInt(max_file_size_mb) * 1024 * 1024;
1053: } catch (Exception e) {
1054: // if unable to parse an integer from the value
1055: // in the properties file, use 1 MB as a default
1056: max_file_size_mb = "1";
1057: max_bytes = 1024 * 1024;
1058: }
1059:
1060: String max_bytes_string = ResourcesAction
1061: .getFileSizeString(max_bytes, rb);
1062:
1063: addAlert(state, rb.getFormattedMessage("size.exceeded",
1064: new Object[] { max_bytes_string }));
1065: } else if (status.equals("exception")) {
1066: logger
1067: .warn("No files uploaded; upload.status == exception");
1068: addAlert(state, rb.getString("choosefile7"));
1069: }
1070: }
1071: if (!allAlerts.isEmpty()) {
1072: for (String alert : allAlerts) {
1073: addAlert(state, alert);
1074: }
1075: }
1076:
1077: if (state.getAttribute(ResourcesAction.STATE_MESSAGE) == null) {
1078: mfp.setActionCanceled(false);
1079: mfp.setErrorEncountered(false);
1080: mfp.setActionCompleted(true);
1081:
1082: toolSession.setAttribute(ResourceToolAction.DONE,
1083: Boolean.TRUE);
1084: }
1085:
1086: }
1087:
1088: protected void initHelper(VelocityPortlet portlet, Context context,
1089: RunData rundata, SessionState state) {
1090: ToolSession toolSession = SessionManager
1091: .getCurrentToolSession();
1092: //toolSession.setAttribute(ResourceToolAction.STARTED, Boolean.TRUE);
1093: //state.setAttribute(ResourceToolAction.STATE_MODE, MODE_MAIN);
1094: if (state.getAttribute(STATE_USING_CREATIVE_COMMONS) == null) {
1095: String usingCreativeCommons = ServerConfigurationService
1096: .getString("copyright.use_creative_commons");
1097: if (usingCreativeCommons != null
1098: && usingCreativeCommons
1099: .equalsIgnoreCase(Boolean.TRUE.toString())) {
1100: state.setAttribute(STATE_USING_CREATIVE_COMMONS,
1101: Boolean.TRUE.toString());
1102: } else {
1103: state.setAttribute(STATE_USING_CREATIVE_COMMONS,
1104: Boolean.FALSE.toString());
1105: }
1106: }
1107:
1108: if (state.getAttribute(STATE_COPYRIGHT_TYPES) == null) {
1109: if (ServerConfigurationService.getStrings("copyrighttype") != null) {
1110: state.setAttribute(STATE_COPYRIGHT_TYPES,
1111: new ArrayList(Arrays
1112: .asList(ServerConfigurationService
1113: .getStrings("copyrighttype"))));
1114: }
1115: }
1116:
1117: if (state.getAttribute(STATE_DEFAULT_COPYRIGHT) == null) {
1118: if (ServerConfigurationService
1119: .getString("default.copyright") != null) {
1120: state.setAttribute(STATE_DEFAULT_COPYRIGHT,
1121: ServerConfigurationService
1122: .getString("default.copyright"));
1123: }
1124: }
1125:
1126: if (state.getAttribute(STATE_DEFAULT_COPYRIGHT_ALERT) == null) {
1127: if (ServerConfigurationService
1128: .getString("default.copyright.alert") != null) {
1129: state.setAttribute(STATE_DEFAULT_COPYRIGHT_ALERT,
1130: ServerConfigurationService
1131: .getString("default.copyright.alert"));
1132: }
1133: }
1134:
1135: if (state.getAttribute(STATE_NEW_COPYRIGHT_INPUT) == null) {
1136: if (ServerConfigurationService
1137: .getString("newcopyrightinput") != null) {
1138: state.setAttribute(STATE_NEW_COPYRIGHT_INPUT,
1139: ServerConfigurationService
1140: .getString("newcopyrightinput"));
1141: }
1142: }
1143:
1144: if (state.getAttribute(STATE_COPYRIGHT_FAIRUSE_URL) == null) {
1145: if (ServerConfigurationService.getString("fairuse.url") != null) {
1146: state.setAttribute(STATE_COPYRIGHT_FAIRUSE_URL,
1147: ServerConfigurationService
1148: .getString("fairuse.url"));
1149: }
1150: }
1151:
1152: if (state.getAttribute(STATE_COPYRIGHT_NEW_COPYRIGHT) == null) {
1153: if (ServerConfigurationService
1154: .getString("copyrighttype.new") != null) {
1155: state.setAttribute(STATE_COPYRIGHT_NEW_COPYRIGHT,
1156: ServerConfigurationService
1157: .getString("copyrighttype.new"));
1158: }
1159: }
1160:
1161: if (state.getAttribute(STATE_FILE_UPLOAD_MAX_SIZE) == null) {
1162: state.setAttribute(STATE_FILE_UPLOAD_MAX_SIZE,
1163: ServerConfigurationService.getString(
1164: "content.upload.max", "1"));
1165: }
1166:
1167: state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY, Boolean.FALSE);
1168: String[] siteTypes = ServerConfigurationService
1169: .getStrings("prevent.public.resources");
1170: String siteType = null;
1171: Site site;
1172: try {
1173: site = SiteService.getSite(ToolManager
1174: .getCurrentPlacement().getContext());
1175: siteType = site.getType();
1176: if (siteTypes != null) {
1177: for (int i = 0; i < siteTypes.length; i++) {
1178: if ((StringUtil.trimToNull(siteTypes[i]))
1179: .equals(siteType)) {
1180: state.setAttribute(
1181: STATE_PREVENT_PUBLIC_DISPLAY,
1182: Boolean.TRUE);
1183: break;
1184: }
1185: }
1186: }
1187: } catch (IdUnusedException e) {
1188: // allow public display
1189: } catch (NullPointerException e) {
1190: // allow public display
1191: }
1192:
1193: state.setAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE,
1194: org.sakaiproject.content.cover.ContentTypeImageService
1195: .getInstance());
1196: }
1197:
1198: protected void toolModeDispatch(String methodBase,
1199: String methodExt, HttpServletRequest req,
1200: HttpServletResponse res) throws ToolException {
1201: SessionState sstate = getState(req);
1202: ToolSession toolSession = SessionManager
1203: .getCurrentToolSession();
1204:
1205: //String mode = (String) sstate.getAttribute(ResourceToolAction.STATE_MODE);
1206: //Object started = toolSession.getAttribute(ResourceToolAction.STARTED);
1207: Object done = toolSession.getAttribute(ResourceToolAction.DONE);
1208:
1209: if (done != null) {
1210: toolSession.removeAttribute(ResourceToolAction.STARTED);
1211: Tool tool = ToolManager.getCurrentTool();
1212:
1213: String url = (String) SessionManager
1214: .getCurrentToolSession().getAttribute(
1215: tool.getId() + Tool.HELPER_DONE_URL);
1216:
1217: SessionManager.getCurrentToolSession().removeAttribute(
1218: tool.getId() + Tool.HELPER_DONE_URL);
1219:
1220: try {
1221: res.sendRedirect(url);
1222: } catch (IOException e) {
1223: // Log.warn("chef", this + " : ", e);
1224: }
1225: return;
1226: }
1227:
1228: super.toolModeDispatch(methodBase, methodExt, req, res);
1229: }
1230:
1231: }
|