⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 document.java

📁 OBPM是一个开源
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @return Returns the _params.
	 */
	public ParamsTable get_params() {
		return _params;
	}

	/**
	 * @param _params
	 *            The _params to set.
	 */
	public void set_params(ParamsTable _params) {
		this._params = _params;
	}

	public int getItemValueAsInt(String fieldName) throws Exception {
		Item item = findItem(fieldName);
		if (item.getType() != null
				&& item.getType().equals(Item.VALUE_TYPE_NUMBER)) {
			Double rtn = item.getNumbervalue();
			return (rtn != null) ? rtn.intValue() : 0;

		} else {
			throw new Exception("Item " + fieldName
					+ "'s value is not a legal number!");
		}
	}

	public String getItemValueAsString(String fieldName) throws Exception {
		Item item = findItem(fieldName);
		String value = null;
		if (item != null && item.getType() != null) {
			if (item.getType().equals(Item.VALUE_TYPE_VARCHAR)) {
				value = item.getVarcharvalue();
			} else if (item.getType().equals(Item.VALUE_TYPE_NUMBER)) {
				value = String.valueOf(item.getNumbervalue());
			} else if (item.getType().equals(Item.VALUE_TYPE_DATE)) {
				if (item.getDatevalue() != null) {
					value = DateUtil.getDateStr(item.getDatevalue());
				} else {
					value = "";
				}
			} else if (item.getType().equals(Item.VALUE_TYPE_TEXT)) {
				value = item.getTextvalue();
			} else if (item.getType().equals(Item.VALUE_TYPE_BLOB)) {
				value = getBlobItemValueAsString(fieldName, true);
			}

			return value;
		} else {

			Debug
					.println("Item " + fieldName
							+ "'s value can't get as string!");
			return "";
		}
	}

	public String getImgItemUrlAsString(String fieldName) {
		Item item = findItem(fieldName);
		String value = "";
		if (item != null && item.getType() != null) {
			if (item.getType().equals(Item.VALUE_TYPE_VARCHAR)) {
				value = item.getVarcharvalue();
				if (value.indexOf("_") != -1) {
					value = value.substring(0, value.indexOf("_"));
				}
			}
		}
		return value;
	}

	public float getItemValueAsFloat(String fieldName) throws Exception {
		Item item = findItem(fieldName);
		if (item.getType() != null
				&& item.getType().equals(Item.VALUE_TYPE_NUMBER)) {
			Double rtn = item.getNumbervalue();
			return (rtn != null) ? rtn.floatValue() : 0;

		} else {
			throw new Exception("Item " + fieldName
					+ "'s value is not a legal number!");
		}
	}

	public double getItemValueAsDouble(String fieldName) throws Exception {
		Item item = findItem(fieldName);
		if (item != null && item.getType() != null) {
			if (item.getType().equals(Item.VALUE_TYPE_NUMBER)) {
				Double rtn = item.getNumbervalue();
				return (rtn != null) ? rtn.doubleValue() : 0;
			} else if (item.getType().equals(Item.VALUE_TYPE_VARCHAR)) {
				try {
					return Double.parseDouble(item.getVarcharvalue());
				} catch (Exception e) {
				}
			}
		}
		return 0.0;
	}

	public long getItemValueAsLong(String fieldName) throws Exception {
		Item item = findItem(fieldName);
		if (item.getType() != null
				&& item.getType().equals(Item.VALUE_TYPE_NUMBER)) {
			Double rtn = item.getNumbervalue();
			return (rtn != null) ? rtn.longValue() : 0;

		} else {
			throw new Exception("Item " + fieldName
					+ "'s value is not a legal number!");
		}
	}

	public Date getItemValueAsDate(String fieldName) throws Exception {
		Item item = findItem(fieldName);
		if (item == null) {
			return null;
		}
		if (item.getType() != null
				&& item.getType().equals(Item.VALUE_TYPE_DATE)) {
			Date rtn = item.getDatevalue();
			return rtn;

		} else {
			throw new Exception("Item " + fieldName
					+ "'s value is not a legal date!");
		}
	}

	private String getBlobItemValueAsString(String fieldName, boolean pagediv) {
		String _fieldname = fieldName;
		String currpage = "";

		if (_params != null)
			currpage = (String) _params.getParameter("_curpage");
		if (pagediv && currpage != null && currpage.length() > 0)
			_fieldname = formatFieldNameByPageDiv(fieldName, currpage);

		Item item = findItem(_fieldname);

		if (item != null && item.getBlobvalue() != null) {
			String BlobExtense = item.getBlobvalue().getExtense();

			if (BlobExtense != null) {
				if (BlobExtense.toLowerCase().equals(".htm")
						|| BlobExtense.toLowerCase().equals(".html"))
					return getHTMLItemValueAsString(item);

				String downloadUrl = "/dynaform/document/downloadattachfile.do?id="
						+ item.getId()
						+ "&filename="
						+ item.getBlobvalue().getFilename();
				return downloadUrl;
			}
		}
		return "";
	}

	/**
	 * 以String形式来获取item的value
	 */
	private String getHTMLItemValueAsString(Item item) {
		String itemvalue = "";
		if (item != null && item.getBlobvalue() != null) {
			try {
				itemvalue = new String(item.getBlobvalue().getContent());
			} catch (Exception e) {
				e.printStackTrace();
				itemvalue = "";
			}
		}
		return itemvalue;
	}

	private String formatFieldNameByPageDiv(String fieldname, String page) {
		String _fieldname = fieldname;

		int tagpos = _fieldname.indexOf("$");
		if (tagpos > 0) {
			String prefix = _fieldname.substring(0, tagpos);
			_fieldname = prefix + "$" + page;
		}

		return _fieldname;
	}

	// 根据前缀获取所有域的名称
	public Collection getAllFieldNameByPrefix(String prefix) {
		Collection fields = new ArrayList();
		Iterator fieldnames = _items_name.values().iterator();

		int tagpos = prefix.indexOf("$");
		String _prefix = (tagpos > 0) ? prefix.substring(0, tagpos) : prefix;

		try {
			while (fieldnames.hasNext()) {

				Item item = (Item) fieldnames.next();
				if (item != null && item.getName().length() > 0)
					if (item.getName().startsWith(_prefix + "$")) {
						String itemvalue = "";
						if (item.getType().equals(Item.VALUE_TYPE_BLOB))
							itemvalue = getBlobItemValueAsString(
									item.getName(), false);
						else if (item.getType().equals(Item.VALUE_TYPE_TEXT))
							itemvalue = item.getTextvalue();
						else
							itemvalue = getItemValueAsString(item.getName());

						if (itemvalue != null && itemvalue.length() > 0) {
							fields.add(item.getName());
						}

					}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return fields;
	}

	/**
	 * @hibernate.property column="ISSUBDOC"
	 * @return
	 */
	public boolean get_issubdoc() {
		return _issubdoc;
	}

	public void set_issubdoc(boolean _issubdoc) {
		this._issubdoc = _issubdoc;
	}

	/**
	 * @hibernate.property column="FORMID"
	 * @return
	 */
	public String getFormid() {
		return formid;
	}

	public void setFormid(String formid) {
		this.formid = formid;
	}

	/**
	 * @hibernate.many-to-one column="AUTHOR" cascade = "none"
	 *                        class="cn.myapps.core.user.ejb.UserVO"
	 * 
	 */
	public UserVO getAuthor() {
		return author;
	}

	public void setAuthor(UserVO author) {
		this.author = author;
	}

	/**
	 * @hibernate.many-to-one column="STATE" cascade = "none"
	 *                        class="cn.myapps.core.workflow.storage.runtime.ejb.FlowStateRT"
	 *                        outer-join="auto"
	 */
	public FlowStateRT getState() {
		return state;
	}

	public void setState(FlowStateRT state) {
		this.state = state;
	}

	public void addStringItem(String itemName, String itemValue)
			throws Exception {
		Item item = new Item();
		item.setType(Item.VALUE_TYPE_VARCHAR);
		item.setName(itemName);
		item.setValue(itemValue);
		item.setLastModified(new Date(System.currentTimeMillis()));
		item.setDocument(this);
		item.setFormname(this.getFormname());
		item.setId(Sequence.getSequence());
		this.addItem(item);
	}

	public void addDateItem(String itemName, Date itemValue) throws Exception {
		Item item = new Item();
		item.setType(Item.VALUE_TYPE_DATE);
		item.setName(itemName);
		item.setValue(itemValue);
		item.setLastModified(new Date(System.currentTimeMillis()));
		item.setDocument(this);
		item.setFormname(this.getFormname());
		item.setId(Sequence.getSequence());
		this.addItem(item);
	}

	public void addDoubleItem(String itemName, double itemValue)
			throws Exception {
		Item item = new Item();
		item.setType(Item.VALUE_TYPE_NUMBER);
		item.setName(itemName);
		item.setValue(new Double(itemValue));
		item.setLastModified(new Date(System.currentTimeMillis()));
		item.setDocument(this);
		item.setFormname(this.getFormname());
		item.setId(Sequence.getSequence());
		this.addItem(item);
	}

	public void addLongItem(String itemName, long itemValue) throws Exception {
		addDoubleItem(itemName, (double) itemValue);
	}

	public void addIntItem(String itemName, int itemValue) throws Exception {
		addDoubleItem(itemName, (double) itemValue);
	}

	public void addFloatItem(String itemName, float itemValue) throws Exception {
		addDoubleItem(itemName, (double) itemValue);
	}

	/**
	 * 获取所有当前节点名称(以名称作为流程状态显示)
	 * 
	 * @return
	 */
	public String getStateStr() {
		FlowStateRT flowStateRT = getState();
		StringBuffer stateStr = new StringBuffer();
		if (flowStateRT != null) {
			Collection noderts = flowStateRT.getNoderts();
			if (noderts != null && !noderts.isEmpty()) {
				for (Iterator iter = noderts.iterator(); iter.hasNext();) {
					NodeRT nodert = (NodeRT) iter.next();
					stateStr.append(nodert.getName() + ",");
				}
				stateStr.deleteCharAt(stateStr.length() - 1);
			}
		}
		return stateStr.toString();
	}

	public Collection getFirstNodeList(WebUser user) throws Exception {
		return StateMachine.getFirstNodeList(getId(), getFlowid(), user);
	}

	/**
	 * @hibernate.property column="ISTMP"
	 * @return
	 */
	public boolean getIstmp() {
		return istmp;
	}

	public void setIstmp(boolean istmp) {
		this.istmp = istmp;
	}

	public Object clone() throws CloneNotSupportedException {
		try {
			DocumentProcess dp = (DocumentProcess) ProcessFactory
					.createProcess(DocumentProcess.class);

			Document newdoc = new Document();
			dp.doCreate(newdoc);
			// newdoc.setId(Sequence.getSequence());
			/**
			 * 默认表单id
			 */
			newdoc.setFormname(getFormname());// 表单模板

			newdoc.setFormid(getFormid()); // 表单模板 id值

			newdoc.setFieldPermList(getFieldPermList());// 流程节点对应formfield权限

			// 流程状态(从t_docflow表中获取)
			if (getState() != null) {
				FlowStateRTProcess process = (FlowStateRTProcess) ProcessFactory
						.createProcess(FlowStateRTProcess.class);
				FlowStateRT state = (FlowStateRT) process.doView(getState()
						.getId());
				newdoc.setState(state);
			}

			newdoc.set_issubdoc(get_issubdoc());

			// Author
			if (getAuthor() != null) {
				UserProcess process = (UserProcess) ProcessFactory
						.createProcess(UserProcess.class);
				UserVO author = (UserVO) process.doView(getAuthor().getId());
				newdoc.setAuthor(author);
			}

			newdoc.setCreated(getCreated());

			newdoc.setLastmodified(getLastmodified());

			newdoc.set_params(get_params());

			newdoc.setAuditdate(getAuditdate());// 最后审核时间

			newdoc.setAudituser(getAudituser());// 最后审核人姓名

			newdoc.setAuditusers(getAuditusers());// 所有已审核人ID(以分号隔开)

			// 子表单
			if (getChilds() != null && getChilds().size() > 0) {
				HashSet childs = new HashSet();
				for (Iterator iter = getChilds().iterator(); iter.hasNext();) {
					Document child = (Document) iter.next();
					Document newChild = (Document) child.clone();
					childs.add(newChild);
					newChild.setParent(newdoc);
					dp.doUpdate(newChild);
				}
				newdoc.setChilds(childs);
			}

			// Item
			if (getItems() != null && getItems().size() > 0) {
				for (Iterator iter = getItems().iterator(); iter.hasNext();) {
					Item item = (Item) iter.next();

					Item newItem = new Item();
					PropertyUtils.copyProperties(newItem, item);
					newItem.setId(Sequence.getSequence());
					newItem.setDocument(newdoc);
					newdoc.addItem(newItem);
				}
			}

			// newdoc.setParent(getParent()); // 父表单

			// newdoc.setExportlog(getExportlog());

			// if(getIstmp()!=null)
			newdoc.setIstmp(getIstmp());

			dp.doUpdate(newdoc);

			return newdoc;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CloneNotSupportedException("Can't clone the Document["
					+ this.getId() + "]");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -