All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.xfa.form.FormField Maven / Gradle / Ivy

The newest version!
/*
 * ADOBE CONFIDENTIAL
 *
 * Copyright 2005 Adobe Systems Incorporated All Rights Reserved.
 *
 * NOTICE: All information contained herein is, and remains the property of
 * Adobe Systems Incorporated and its suppliers, if any. The intellectual and
 * technical concepts contained herein are proprietary to Adobe Systems
 * Incorporated and its suppliers and may be covered by U.S. and Foreign
 * Patents, patents in process, and are protected by trade secret or copyright
 * law. Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained from
 * Adobe Systems Incorporated.
 */

package com.adobe.xfa.form;

import com.adobe.xfa.AppModel;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Delta;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.NodeList;
import com.adobe.xfa.ProtoableNode;
import com.adobe.xfa.StringAttr;
import com.adobe.xfa.STRS;
import com.adobe.xfa.TextNode;
import com.adobe.xfa.XFA;
import com.adobe.xfa.XFAList;
import com.adobe.xfa.content.Content;
import com.adobe.xfa.content.ExDataValue;
import com.adobe.xfa.data.DataModel;
import com.adobe.xfa.data.DataNode;
import com.adobe.xfa.template.containers.Container;
import com.adobe.xfa.template.containers.Field;
import com.adobe.xfa.template.Items;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.MsgFormatPos;
import com.adobe.xfa.ut.Peer;
import com.adobe.xfa.ut.ResId;
import com.adobe.xfa.ut.StringUtils;
import com.adobe.xfa.LogMessage;

import java.util.ArrayList;
import java.util.List;


/**
 * @exclude from public api.
 */
public class FormField extends Field {

	private FormDataListener mDataListener;

    private Object mCPDField;

	private FormItemsDataListener mItemsDataListener;

	private List mListenerTable; // list of listeners

	private boolean mbValidateRegistered;
	
	private boolean mbCalculateRegistered;

	public FormField(Element parent, Node prevSibling) {
		super(parent, prevSibling);
	}

	public void remove() {
		if (getModel() instanceof FormModel) {
			((FormModel) getModel()).removeReferences(this);
		}

		super.remove();
	}

	void setDataNode(
			DataNode dataNode, 
			boolean bUpdateData /* = false */, 
			boolean bPeerNode /* = true */,
			String sConnectPicture /* = "" */,
			boolean bDefault /*=true*/ /*CL#708930 */) {
		
		// remove old listener
		if (mDataListener != null && bPeerNode) {
			mDataListener.dispose();
			mDataListener = null;
		}

		// Type and null check
		if (dataNode == null || dataNode.getClassTag() != XFA.DATAVALUETAG)
			return;

		// Establish a peer relationship with the data node
		if (bPeerNode)
			setFormDataListener(new FormDataListener(this, dataNode));

		// Apply data picture format that the field may have specified
		String sDataPictureFormat = "";
		if (bPeerNode) {
			Element bind = getElement(XFA.BINDTAG, true, 0, false, false);
			if (bind != null) {
				Element picture = bind.getElement(XFA.PICTURETAG, true, 0, false, false);
				if (picture != null) {
					TextNode textNode = (TextNode) picture.locateChildByClass(XFA.TEXTNODETAG, 0);
					if (textNode != null) {
						sDataPictureFormat = textNode.getValue();
					}
				}
			}
		} else {
			// connect picture was predetermined and passed in
			sDataPictureFormat = sConnectPicture;
		}

		if (!StringUtils.isEmpty(sDataPictureFormat)) {
			boolean bIsTextNode = false;
			Element value = getElement(XFA.VALUETAG, true, 0, false, false);
			if (value != null) {
				Node content = value.getOneOfChild(true, true);
				if (content != null && content.isSameClass(XFA.TEXTTAG))
					bIsTextNode = true;
			}

			String sLocale;
			ProtoableNode proto = getProto();
			if (proto != null)
				sLocale = proto.getInstalledLocale();
			else
				sLocale = getInstalledLocale();

			if (bPeerNode)
				getDataNode().setPictureFormat(sDataPictureFormat, sLocale, bIsTextNode);
			else
				dataNode.setPictureFormat(sDataPictureFormat, sLocale, bIsTextNode);
		}

		if (bPeerNode && getFormDataListener() != null)
			getFormDataListener().deafen();
		
		if (bUpdateData)
			setData(dataNode);
		else
			setFromData(dataNode, bDefault);
		
		if (bPeerNode && getFormDataListener() != null)
			getFormDataListener().unDeafen();
	}

	void setData(DataNode dataValue) {
		// null check
		if (dataValue == null) {
			dataValue = getDataNode();

			if (dataValue == null)
				return;
		}

		// if this field is null then set the data node to null;
		if (getIsNull(false)) {
			dataValue.setIsNull(true, true);

			return;
		}

		// Create an XFADataValue node

		// Getting a field value involves traversing either of these
		// hierarchies:
		//
		// 
		//   
		//     could also be an integer/decimal or other content
		//   
		// 
		//
		// 
		//   
		//     
		//        ... 
		//     
		//   
		// 

		Element value = getElement(XFA.VALUETAG, false, 0, false, false);
		Node valueContent = value.getOneOfChild();

		// Fix for Bug #39261. We were assuming that all children
		// of value had a textnode. This is not true for arcs, lines
		// and rectangles. Only nodes derived from Content exhibit
		// this behaviour.
		if (valueContent instanceof Content) {
			Content content = (Content)valueContent;
			Node valueContentChild = null;

			// set the content type of the dataValue for images
			if (valueContent.isSameClass(XFA.IMAGETAG)) {
				Attribute contentType = content.getAttribute(XFA.CONTENTTYPETAG);
				dataValue.setContentType(contentType.toString());

				// set the href attribute on the dv element
				if (valueContent.isPropertySpecified(XFA.HREFTAG, true, 0)) {
					Attribute href = content.getAttribute(XFA.HREFTAG);
					
					dataValue.setAttribute("", XFA.HREF, XFA.HREF, href.getAttrValue(), false);
				}
			}

			// A content node is one of , , ,
			// , , 




© 2015 - 2024 Weber Informatics LLC | Privacy Policy