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

📄 dcinputsreader.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    					{    						Node nfld = flds.item(k);    						if ( nfld.getNodeName().equals("field") )    						{    							// process each field definition    							HashMap field = new HashMap();    							page.add(field);    							processPageParts(formName, pgNum, nfld, field);    							String error = checkForDups(formName, field, pages);    							if (error != null)    							{    								throw new SAXException(error);    							}    						}    					}    				} // ignore any child that is not a 'page'    			}    			// sanity check number of pages    			if (pages.size() < 1)    			{    				throw new ServletException("Form " + formName + " has no pages");    			}    			int maxPages = SubmitServlet.EDIT_METADATA_2 - SubmitServlet.EDIT_METADATA_1 + 1;    			if ( pages.size() > maxPages)    			{    				throw new ServletException("Form " + formName + " exceeds maximum pages: " + maxPages);			    			}    		}    	}    	if (numForms == 0)    	{    		throw new ServletException("No form definition found");    	}    }    /**     * Process parts of a field     * At the end, make sure that input-types 'qualdrop_value' and     * 'twobox' are marked repeatable. Complain if dc-element, label,     * or input-type are missing.     */    private void processPageParts(String formName, String page, Node n, HashMap field)        throws SAXException    {    	NodeList nl = n.getChildNodes();    	int len = nl.getLength();    	for (int i = 0; i < len; i++)    	{    		Node nd = nl.item(i);    		if ( ! isEmptyTextNode(nd) )    		{    			String tagName = nd.getNodeName();    			String value   = getValue(nd);    			field.put(tagName, value);    			if (tagName.equals("input-type"))    			{    				if (value.equals("dropdown") || value.equals("qualdrop_value"))    				{    					String pairTypeName = getAttribute(nd, PAIR_TYPE_NAME);    					if (pairTypeName == null)    					{    						throw new SAXException("Form " + formName + ", field " +    												field.get("dc-element") +													"." + field.get("dc-qualifier") +    												" has no name attribute");    					}    					else     					{    						field.put(PAIR_TYPE_NAME, pairTypeName);    					}			    				}    			}    		}    	}    	String missing = null;    	if (field.get("dc-element") == null)    	{    		missing = "dc-element";    	}    	if (field.get("label") == null)    	{    		missing = "label";    	}    	if (field.get("input-type") == null)    	{    		missing = "input-type";    	}    	if ( missing != null )    	{    		String msg = "Required field " + missing + " missing on page " + page + " of form " + formName;    		throw new SAXException(msg);        }    	String type = (String)field.get("input-type");    	if (type.equals("twobox") || type.equals("qualdrop_value"))    	{    		String rpt = (String)field.get("repeatable");    		if ((rpt == null) ||     				((!rpt.equalsIgnoreCase("yes")) &&     						(!rpt.equalsIgnoreCase("true"))))    		{    			String msg = "The field \'"+field.get("label")+"\' must be repeatable";    			throw new SAXException(msg);    		}    	}    }    /**     * Check that this is the only field with the name dc-element.dc-qualifier     * If there is a duplicate, return an error message, else return null;     */    private String checkForDups(String formName, HashMap field, Vector pages)    {    	int matches = 0;    	String err = null;    	String elem = (String)field.get("dc-element");    	String qual = (String)field.get("dc-qualifier");    	for (int i = 0; i < pages.size(); i++)    	{		    Vector pg = (Vector)pages.get(i);		    for (int j = 0; j < pg.size(); j++)		    {		    	HashMap fld = (HashMap)pg.get(j);		    	if (((String)fld.get("dc-element")).equals(elem))		    	{		    		String ql = (String)fld.get("dc-qualifier");		    		if (qual != null)		    		{		    			if ((ql != null) && ql.equals(qual))		    			{		    				matches++;		    			}		    		}		    		else if (ql == null)		    		{		    			matches++;		    		}		    	}		    }    	}    	if (matches > 1)    	{    		err = "Duplicate field " + elem + "." + qual + " detected in form " + formName;    	}    	return err;    }    /**     * Process the form-value-pairs section of the XML file.     *  Each element is formed thusly:     *      <value-pairs name="..." dc-term="...">     *          <pair>     *            <display>displayed name-</display>     *            <storage>stored name</storage>     *          </pair>     * For each value-pairs element, create a new vector, and extract all      * the pairs contained within it. Put the display and storage values,     * respectively, in the next slots in the vector. Store the vector     * in the passed in hashmap.     */    private void processValuePairs(Node e) 		throws SAXException    {    	NodeList nl = e.getChildNodes();    	int len = nl.getLength();    	for (int i = 0; i < len; i++)    	{	    	Node nd = nl.item(i);		    String tagName = nd.getNodeName();		    // process each value-pairs set		    if (tagName.equals("value-pairs"))		    {		    	String pairsName = getAttribute(nd, PAIR_TYPE_NAME);		    	String dcTerm = getAttribute(nd, "dc-term");		    	if (pairsName == null)		    	{		    		String errString =		    			"Missing name attribute for value-pairs for DC term " + dcTerm;		    		throw new SAXException(errString);		    	}		    	Vector pairs = new Vector();		    	valuePairs.put(pairsName, pairs);		    	NodeList cl = nd.getChildNodes();		    	int lench = cl.getLength();		    	for (int j = 0; j < lench; j++)		    	{		    		Node nch = cl.item(j);		    		String display = null;		    		String storage = null;		    		if (nch.getNodeName().equals("pair"))		    		{		    			NodeList pl = nch.getChildNodes();		    			int plen = pl.getLength();		    			for (int k = 0; k < plen; k++)		    			{		    				Node vn= pl.item(k);		    				String vName = vn.getNodeName();		    				if (vName.equals("displayed-value"))		    				{		    					display = getValue(vn);		    				}		    				else if (vName.equals("stored-value"))		    				{		    					storage = getValue(vn);		    					if (storage == null)		    					{		    						storage = "";		    					}		    				} // ignore any children that aren't 'display' or 'storage'		    			}		    			pairs.add(display);		    			pairs.add(storage);		    		} // ignore any children that aren't a 'pair'		    	}		    } // ignore any children that aren't a 'value-pair'    	}    }    /**     * Check that all referenced value-pairs are present     * and field is consistent     *     * Throws ServletException if detects a missing value-pair.     */    private void checkValues()		throws ServletException    {    	// Step through every field of every page of every form    	Iterator ki = formDefns.keySet().iterator();    	while (ki.hasNext())    	{    		String idName = (String)ki.next();    		Vector pages = (Vector)formDefns.get(idName);    		for (int i = 0; i < pages.size(); i++)    		{    			Vector page = (Vector)pages.get(i);    			for (int j = 0; j < page.size(); j++)    			{    				HashMap fld = (HashMap)page.get(j);    				// verify reference in certain input types    				String type = (String)fld.get("input-type");    				if (type.equals("dropdown") || type.equals("qualdrop_value"))    				{    					String pairsName = (String)fld.get(PAIR_TYPE_NAME);    					Vector v = (Vector)valuePairs.get(pairsName);    					if (v == null)    					{    						String errString = "Cannot find value pairs for " + pairsName;    						throw new ServletException(errString);    					}    				}    				// if visibility restricted, make sure field is not required    				String visibility = (String)fld.get("visibility");    				if (visibility != null && visibility.length() > 0 )    				{    					String required = (String)fld.get("required");    					if (required != null && required.length() > 0)    					{    						String errString = "Field '" + (String)fld.get("label") +    						                   	"' is required but invisible";    						throw new ServletException(errString);    					}    				}    			}    		}    	}    }        private Node getElement(Node nd)    {        NodeList nl = nd.getChildNodes();        int len = nl.getLength();        for (int i = 0; i < len; i++)        {    	    Node n = nl.item(i);    	    if (n.getNodeType() == Node.ELEMENT_NODE)    	    {    	    	return n;            }        }        return null;     }    private boolean isEmptyTextNode(Node nd)     {    	boolean isEmpty = false;    	if (nd.getNodeType() == Node.TEXT_NODE)    	{    		String text = nd.getNodeValue().trim();    		if (text.length() == 0)    		{    			isEmpty = true;    		}    	}    	return isEmpty;    }    /**     * Returns the value of the node's attribute named <name>     */    private String getAttribute(Node e, String name)     {    	NamedNodeMap attrs = e.getAttributes();    	int len = attrs.getLength();    	if (len > 0)    	{    		int i;    		for (i = 0; i < len; i++)    		{    			Node attr = attrs.item(i);    			if (name.equals(attr.getNodeName()))    			{    				return attr.getNodeValue().trim();    			}    		}    	}    	//no such attribute    	return null;    }    /**     * Returns the value found in the Text node (if any) in the     * node list that's passed in.     */    private String getValue(Node nd)    {    	NodeList nl = nd.getChildNodes();    	int len = nl.getLength();    	for (int i = 0; i < len; i++)    	{    		Node n = nl.item(i);    		short type = n.getNodeType();    		if (type == Node.TEXT_NODE)    		{    			return n.getNodeValue().trim();    		}    	}    	// Didn't find a text node    	return null;    }}

⌨️ 快捷键说明

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