WebOffice 开发文档--code

public class WebOfficeAction extends AuthenticAction {
		/**
		 * 附件在线编辑
		 */
		protected ActionForward doService(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)
				throws Exception {
			// 获取所在区域ID
			String catalogId = request.getParameter("catalogId");
			// 获取文档ID
			String docId = request.getParameter("docId");
			// 获取附件ID
			String aid = request.getParameter("aid");
			
			// 校验是否有权限编辑 只有文控员和应用管理员有权限
			if (!GenericValidator.isBlankOrNull(catalogId)) {
				boolean permission = UserPermHandler.getInstance().hasPermission(
						request, catalogId, UserPermHandler.INFO_BPA_CONTROLLER);
				if (!permission) {
					return mapping.findForward("applyperm");
				}
			}
	
			if (!GenericValidator.isBlankOrNull(docId)
					&& !GenericValidator.isBlankOrNull(aid)) {
				try {
					DocHandler docHandler = new DocHandler();
					// 获取附件信息
					AttachmentVO attachment = (AttachmentVO) docHandler
							.getAttachment(Integer.parseInt(docId), Integer
									.parseInt(aid));
	
					// 从配置文件读取文件的存放路径
					String dir = DAOService.getPatterConfigValue("file_document",
							"upload_dir");
					String uploadPath = dir + File.separator
							+ attachment.getImageUrl() + File.separator
							+ attachment.getOverview();
	
					// 校验附件是否存在
					File file = new File(uploadPath);
					if (!file.exists() || !file.isFile()) {
						return mapping.findForward("sourceNotFound");
					}
	
					String flag = request.getParameter("flag");
					// 初始化附件编辑页面
					if (!GenericValidator.isBlankOrNull(flag)
							&& DocumentConstants.WEB_OFFICE_PAGE_INIT_FLAG
									.equals(flag)) {
						this.initOnlineEdit(request, response, attachment,
								uploadPath);
						return null;
					}
	
					// 编辑后上传处理
					if (!GenericValidator.isBlankOrNull(flag)
							&& DocumentConstants.WEB_OFFICE_FILE_SAVE_FLAG
									.equals(flag)) {
						int res = this.uploadAttachment(request, response,
								attachment, dir);
						// 返回服务端处理信息
						PrintWriter writer = response.getWriter();
						String msg = null;
						if (res > 0) {
							msg = "succeed";
							// 记录日志
							BPAHandler handler = new BPAHandler();
							String reviewLog = "Edit Attachments:"
									+ this.getLoginUser(request).getName() + "<br>";
							handler.updateDocument(Integer.parseInt(docId),
									reviewLog);
						} else {
							msg = "failed";
						}
						writer.write(msg);
						return null;
					}
	
					// 附件名
					String fileName = attachment.getOverview();
					fileName = fileName.substring(0, fileName.indexOf("."));
	
					request.setAttribute("docId", docId);
					request.setAttribute("aid", aid);
					request.setAttribute("attachmentName", fileName);
					request.setAttribute("attachmentType", attachment.getResType());
				} catch (ApplicationException e) {
					return mapping.findForward("failure");
				} catch (Exception e) {
					return mapping.findForward("failure");
				}
			}
			return mapping.findForward("toDealPage");
		}

你可能感兴趣的:(Web,配置管理,Office)