📄 xfaform.java
字号:
* @param inverseSearch the data to do a search from the bottom hierarchy */ public void setInverseSearch(HashMap inverseSearch) { this.inverseSearch = inverseSearch; } } /** * Processes the datasets section in the XFA form. */ public static class Xml2SomDatasets extends Xml2Som { /** * Creates a new instance from the datasets node. This expects * not the datasets but the data node that comes below. * @param n the datasets node */ public Xml2SomDatasets(Node n) { order = new ArrayList(); name2Node = new HashMap(); stack = new Stack2(); anform = 0; inverseSearch = new HashMap(); processDatasetsInternal(n); } /** * Inserts a new <CODE>Node</CODE> that will match the short name. * @param n the datasets top <CODE>Node</CODE> * @param shortName the short name * @return the new <CODE>Node</CODE> of the inserted name */ public Node insertNode(Node n, String shortName) { Stack2 stack = splitParts(shortName); org.w3c.dom.Document doc = n.getOwnerDocument(); Node n2 = null; n = n.getFirstChild(); for (int k = 0; k < stack.size(); ++k) { String part = (String)stack.get(k); int idx = part.lastIndexOf('['); String name = part.substring(0, idx); idx = Integer.parseInt(part.substring(idx + 1, part.length() - 1)); int found = -1; for (n2 = n.getFirstChild(); n2 != null; n2 = n2.getNextSibling()) { if (n2.getNodeType() == Node.ELEMENT_NODE) { String s = escapeSom(n2.getLocalName()); if (s.equals(name)) { ++found; if (found == idx) break; } } } for (; found < idx; ++found) { n2 = doc.createElementNS(null, name); n2 = n.appendChild(n2); Node attr = doc.createAttributeNS(XFA_DATA_SCHEMA, "dataNode"); attr.setNodeValue("dataGroup"); n2.getAttributes().setNamedItemNS(attr); } n = n2; } inverseSearchAdd(inverseSearch, stack, shortName); name2Node.put(shortName, n2); order.add(shortName); return n2; } private static boolean hasChildren(Node n) { Node dataNodeN = n.getAttributes().getNamedItemNS(XFA_DATA_SCHEMA, "dataNode"); if (dataNodeN != null) { String dataNode = dataNodeN.getNodeValue(); if ("dataGroup".equals(dataNode)) return true; else if ("dataValue".equals(dataNode)) return false; } if (!n.hasChildNodes()) return false; Node n2 = n.getFirstChild(); while (n2 != null) { if (n2.getNodeType() == Node.ELEMENT_NODE) { return true; } n2 = n2.getNextSibling(); } return false; } private void processDatasetsInternal(Node n) { HashMap ss = new HashMap(); Node n2 = n.getFirstChild(); while (n2 != null) { if (n2.getNodeType() == Node.ELEMENT_NODE) { String s = escapeSom(n2.getLocalName()); Integer i = (Integer)ss.get(s); if (i == null) i = new Integer(0); else i = new Integer(i.intValue() + 1); ss.put(s, i); if (hasChildren(n2)) { stack.push(s + "[" + i.toString() + "]"); processDatasetsInternal(n2); stack.pop(); } else { stack.push(s + "[" + i.toString() + "]"); String unstack = printStack(); order.add(unstack); inverseSearchAdd(unstack); name2Node.put(unstack, n2); stack.pop(); } } n2 = n2.getNextSibling(); } } } /** * A class to process "classic" fields. */ public static class AcroFieldsSearch extends Xml2Som { private HashMap acroShort2LongName; /** * Creates a new instance from a Collection with the full names. * @param items the Collection */ public AcroFieldsSearch(Collection items) { inverseSearch = new HashMap(); acroShort2LongName = new HashMap(); for (Iterator it = items.iterator(); it.hasNext();) { String itemName = (String)it.next(); String itemShort = getShortName(itemName); acroShort2LongName.put(itemShort, itemName); inverseSearchAdd(inverseSearch, splitParts(itemShort), itemName); } } /** * Gets the mapping from short names to long names. A long * name may contain the #subform name part. * @return the mapping from short names to long names */ public HashMap getAcroShort2LongName() { return acroShort2LongName; } /** * Sets the mapping from short names to long names. A long * name may contain the #subform name part. * @param acroShort2LongName the mapping from short names to long names */ public void setAcroShort2LongName(HashMap acroShort2LongName) { this.acroShort2LongName = acroShort2LongName; } } /** * Processes the template section in the XFA form. */ public static class Xml2SomTemplate extends Xml2Som { private boolean dynamicForm; private int templateLevel; /** * Creates a new instance from the datasets node. * @param n the template node */ public Xml2SomTemplate(Node n) { order = new ArrayList(); name2Node = new HashMap(); stack = new Stack2(); anform = 0; templateLevel = 0; inverseSearch = new HashMap(); processTemplate(n, null); } /** * Gets the field type as described in the <CODE>template</CODE> section of the XFA. * @param s the exact template name * @return the field type or <CODE>null</CODE> if not found */ public String getFieldType(String s) { Node n = (Node)name2Node.get(s); if (n == null) return null; if (n.getLocalName().equals("exclGroup")) return "exclGroup"; Node ui = n.getFirstChild(); while (ui != null) { if (ui.getNodeType() == Node.ELEMENT_NODE && ui.getLocalName().equals("ui")) { break; } ui = ui.getNextSibling(); } if (ui == null) return null; Node type = ui.getFirstChild(); while (type != null) { if (type.getNodeType() == Node.ELEMENT_NODE && !(type.getLocalName().equals("extras") && type.getLocalName().equals("picture"))) { return type.getLocalName(); } type = type.getNextSibling(); } return null; } private void processTemplate(Node n, HashMap ff) { if (ff == null) ff = new HashMap(); HashMap ss = new HashMap(); Node n2 = n.getFirstChild(); while (n2 != null) { if (n2.getNodeType() == Node.ELEMENT_NODE) { String s = n2.getLocalName(); if (s.equals("subform")) { Node name = n2.getAttributes().getNamedItem("name"); String nn = "#subform"; boolean annon = true; if (name != null) { nn = escapeSom(name.getNodeValue()); annon = false; } Integer i; if (annon) { i = new Integer(anform); ++anform; } else { i = (Integer)ss.get(nn); if (i == null) i = new Integer(0); else i = new Integer(i.intValue() + 1); ss.put(nn, i); } stack.push(nn + "[" + i.toString() + "]"); ++templateLevel; if (annon) processTemplate(n2, ff); else processTemplate(n2, null); --templateLevel; stack.pop(); } else if (s.equals("field") || s.equals("exclGroup")) { Node name = n2.getAttributes().getNamedItem("name"); if (name != null) { String nn = escapeSom(name.getNodeValue()); Integer i = (Integer)ff.get(nn); if (i == null) i = new Integer(0); else i = new Integer(i.intValue() + 1); ff.put(nn, i); stack.push(nn + "[" + i.toString() + "]"); String unstack = printStack(); order.add(unstack); inverseSearchAdd(unstack); name2Node.put(unstack, n2); stack.pop(); } } else if (!dynamicForm && templateLevel > 0 && s.equals("occur")) { int initial = 1; int min = 1; int max = 1; Node a = n2.getAttributes().getNamedItem("initial"); if (a != null) try{initial = Integer.parseInt(a.getNodeValue().trim());}catch(Exception e){} a = n2.getAttributes().getNamedItem("min"); if (a != null) try{min = Integer.parseInt(a.getNodeValue().trim());}catch(Exception e){} a = n2.getAttributes().getNamedItem("max"); if (a != null) try{max = Integer.parseInt(a.getNodeValue().trim());}catch(Exception e){} if (initial != min || min != max) dynamicForm = true; } } n2 = n2.getNextSibling(); } } /** * <CODE>true</CODE> if it's a dynamic form; <CODE>false</CODE> * if it's a static form. * @return <CODE>true</CODE> if it's a dynamic form; <CODE>false</CODE> * if it's a static form */ public boolean isDynamicForm() { return dynamicForm; } /** * Sets the dynamic form flag. It doesn't change the template. * @param dynamicForm the dynamic form flag */ public void setDynamicForm(boolean dynamicForm) { this.dynamicForm = dynamicForm; } } /** * Gets the class that contains the template processing section of the XFA. * @return the class that contains the template processing section of the XFA */ public Xml2SomTemplate getTemplateSom() { return templateSom; } /** * Sets the class that contains the template processing section of the XFA * @param templateSom the class that contains the template processing section of the XFA */ public void setTemplateSom(Xml2SomTemplate templateSom) { this.templateSom = templateSom; } /** * Gets the class that contains the datasets processing section of the XFA. * @return the class that contains the datasets processing section of the XFA */ public Xml2SomDatasets getDatasetsSom() { return datasetsSom; } /** * Sets the class that contains the datasets processing section of the XFA. * @param datasetsSom the class that contains the datasets processing section of the XFA */ public void setDatasetsSom(Xml2SomDatasets datasetsSom) { this.datasetsSom = datasetsSom; } /** * Gets the class that contains the "classic" fields processing. * @return the class that contains the "classic" fields processing */ public AcroFieldsSearch getAcroFieldsSom() { return acroFieldsSom; } /** * Sets the class that contains the "classic" fields processing. * @param acroFieldsSom the class that contains the "classic" fields processing */ public void setAcroFieldsSom(AcroFieldsSearch acroFieldsSom) { this.acroFieldsSom = acroFieldsSom; } /** * Gets the <CODE>Node</CODE> that corresponds to the datasets part. * @return the <CODE>Node</CODE> that corresponds to the datasets part */ public Node getDatasetsNode() { return datasetsNode; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -