当前位置: 首页>>代码示例>>Java>>正文


Java Element.getType方法代码示例

本文整理汇总了Java中org.kxml2.kdom.Element.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getType方法的具体用法?Java Element.getType怎么用?Java Element.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kxml2.kdom.Element的用法示例。


在下文中一共展示了Element.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recurseForOutput

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void recurseForOutput(Element e){
	if(e.getChildCount() == 0) return;

	for(int i=0;i<e.getChildCount();i++){
		int kidType = e.getType(i);
		if(kidType == Node.TEXT) { continue; }
		if(e.getChild(i) instanceof String) { continue; }
		Element kid = (Element)e.getChild(i);

			//is just text
		if(kidType == Node.ELEMENT && XFormUtils.isOutput(kid)){
			String s = "${"+parseOutput(kid)+"}";
			e.removeChild(i);
			e.addChild(i, Node.TEXT, s);

			//has kids? Recurse through them and swap output tag for parsed version
		}else if(kid.getChildCount() !=0){
			recurseForOutput(kid);
			//is something else
		}else{
			continue;
		}
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:25,代码来源:XFormParser.java

示例2: getVagueElementPrintout

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
public static String getVagueElementPrintout(Element e, int maxDepth) {
	String elementString = "<" + e.getName();
	for(int i = 0; i <  e.getAttributeCount() ; ++i) {
		elementString += " " + e.getAttributeName(i) + "=\"";
		elementString += e.getAttributeValue(i) + "\"";
	}
	if(e.getChildCount() > 0) {
		elementString += ">";
		if(e.getType(0) ==Element.ELEMENT) {
			if(maxDepth > 0) {
				elementString += getVagueElementPrintout((Element)e.getChild(0),maxDepth -1);
			} else {
				elementString += "...";
			}
		}
	} else {
		elementString += "/>";
	}
	return elementString;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:21,代码来源:XFormParser.java

示例3: parseUnregisteredSpecExtension

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
 * Handle parsing and warning logic for a tag that doesn't have attached
 * logic already, but has been registered as a spec extension.
 *
 * @param namespace String that is usually a url i.e. "http://opendatakit.org/xforms"
 * @param name      String representing tag name i.e. "extra" for an element like <extra ...>
 * @param e         is the current element we are parsing
 * @param parent    is the parent to the element we are parsing
 * @param handlers  maps tags to IElementHandlers, used to perform parsing of that tag
 */
public void parseUnregisteredSpecExtension(String namespace, String name, Element e, Object parent, Hashtable<String, IElementHandler> handlers) {
    if (!XFormParser.suppressSpecExtensionWarnings.contains(namespace)) {
        // raise a warning about not knowing how to parse
        reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP,
                "Unrecognized element [" + name + "] from namespace " + namespace + ".",
                getVagueLocation(e));
    }

    if (XFormParser.parseSpecExtensionsInnerElements.contains(namespace)) {
        // parse inner elements using default parsing logic.
        for (int i = 0; i < e.getChildCount(); i++) {
            if (e.getType(i) == Element.ELEMENT) {
                parseElement(e.getElement(i), parent, handlers);
            }
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:28,代码来源:XFormParser.java

示例4: parseControlChildren

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseControlChildren(Element e, QuestionDef question, IFormElement parent,
                                  boolean isSelect) {
    for (int i = 0; i < e.getChildCount(); i++) {
        int type = e.getType(i);
        Element child = (type == Node.ELEMENT ? e.getElement(i) : null);
        if (child == null) {
            continue;
        }
        String childName = child.getName();

        if (LABEL_ELEMENT.equals(childName) || HINT_ELEMENT.equals(childName)
                || HELP_ELEMENT.equals(childName) || CONSTRAINT_ELEMENT.equals(childName)) {
            parseHelperText(question, child);
        } else if (isSelect && "item".equals(childName)) {
            parseItem(question, child);
        } else if (isSelect && "itemset".equals(childName)) {
            parseItemset(question, child);
        } else if (actionHandlers.containsKey(childName)) {
            actionHandlers.get(childName).handle(this, child, question);
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:23,代码来源:XFormParser.java

示例5: getVagueElementPrintout

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
public static String getVagueElementPrintout(Element e, int maxDepth) {
    String elementString = "<" + e.getName();
    for (int i = 0; i < e.getAttributeCount(); ++i) {
        elementString += " " + e.getAttributeName(i) + "=\"";
        elementString += e.getAttributeValue(i) + "\"";
    }
    if (e.getChildCount() > 0) {
        elementString += ">";
        if (e.getType(0) == Element.ELEMENT) {
            if (maxDepth > 0) {
                elementString += getVagueElementPrintout((Element)e.getChild(0), maxDepth - 1);
            } else {
                elementString += "...";
            }
        }
    } else {
        elementString += "/>";
    }
    return elementString;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:21,代码来源:XFormParser.java

示例6: getChildElement

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static Element getChildElement(Element parent, String childName) {
    Element e = null;
    int c = parent.getChildCount();
    int i = 0;
    for (i = 0; i < c; i++) {
        if (parent.getType(i) == Node.ELEMENT) {
            if (parent.getElement(i).getName().equalsIgnoreCase(childName)) {
                return parent.getElement(i);
            }
        }
    }
    return e;
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:14,代码来源:FileUtils.java

示例7: parseElement

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseElement (Element e, Object parent, HashMap<String, IElementHandler> handlers) { //,
//			boolean allowUnknownElements, boolean allowText, boolean recurseUnknown) {
		String name = e.getName();

		String[] suppressWarningArr = {
			"html",
			"head",
			"body",
			"xform",
			"chooseCaption",
			"addCaption",
			"addEmptyCaption",
			"delCaption",
			"doneCaption",
			"doneEmptyCaption",
			"mainHeader",
			"entryHeader",
			"delHeader"
		};
      List<String> suppressWarning = new ArrayList<String>(suppressWarningArr.length);
		for (int i = 0; i < suppressWarningArr.length; i++) {
			suppressWarning.add(suppressWarningArr[i]);
		}

		IElementHandler eh = handlers.get(name);
		if (eh != null) {
			eh.handle(this, e, parent);
		} else {
			if (!suppressWarning.contains(name)) {
				reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP,
						"Unrecognized element [" + name	+ "]. Ignoring and processing children...",
						getVagueLocation(e));
			}
			for (int i = 0; i < e.getChildCount(); i++) {
				if (e.getType(i) == Element.ELEMENT) {
					parseElement(e.getElement(i), parent, handlers);
				}
			}
		}
	}
 
开发者ID:medic,项目名称:javarosa,代码行数:41,代码来源:XFormParser.java

示例8: saveInstanceNode

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void saveInstanceNode (Element instance) {
	Element instanceNode = null;
	String instanceId = instance.getAttributeValue("", "id");

	for (int i = 0; i < instance.getChildCount(); i++) {
		if (instance.getType(i) == Node.ELEMENT) {
			if (instanceNode != null) {
				throw new XFormParseException("XForm Parse: <instance> has more than one child element", instance);
			} else {
				instanceNode = instance.getElement(i);
			}
		}
	}

	if(instanceNode == null) {
		//no kids
		instanceNode = instance;
	}

	if (mainInstanceNode == null) {
		mainInstanceNode = instanceNode;
	}

	instanceNodes.add(instanceNode);
	instanceNodeIdStrs.add(instanceId);



}
 
开发者ID:medic,项目名称:javarosa,代码行数:30,代码来源:XFormParser.java

示例9: getLabel

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private String getLabel (Element e){
	if(e.getChildCount() == 0) return null;

	recurseForOutput(e);

	StringBuilder sb = new StringBuilder();
	for(int i = 0; i<e.getChildCount();i++){
		if(e.getType(i)!=Node.TEXT && !(e.getChild(i) instanceof String)){
			Object b = e.getChild(i);
			Element child = (Element)b;

			//If the child is in the HTML namespace, retain it.
			if(NAMESPACE_HTML.equals(child.getNamespace())) {
				sb.append(XFormSerializer.elementToString(child));
			} else {
				//Otherwise, ignore it.
				System.out.println("Unrecognized tag inside of text: <"  + child.getName() + ">. " +
						"Did you intend to use HTML markup? If so, ensure that the element is defined in " +
						"the HTML namespace.");
			}
		}else{
			sb.append(e.getText(i));
		}
	}

	String s = sb.toString().trim();

	return s;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:30,代码来源:XFormParser.java

示例10: loadInstanceData

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static void loadInstanceData (Element node, TreeElement cur, FormDef f) {
	int numChildren = node.getChildCount();
	boolean hasElements = false;
	for (int i = 0; i < numChildren; i++) {
		if (node.getType(i) == Node.ELEMENT) {
			hasElements = true;
			break;
		}
	}

	if (hasElements) {
		HashMap<String, Integer> multiplicities = new HashMap<String, Integer>(); //stores max multiplicity seen for a given node name thus far
		for (int i = 0; i < numChildren; i++) {
			if (node.getType(i) == Node.ELEMENT) {
				Element child = node.getElement(i);

				String name = child.getName();
				int index;
				boolean isTemplate = (child.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null);

				if (isTemplate) {
					index = TreeReference.INDEX_TEMPLATE;
				} else {
					//update multiplicity counter
					Integer mult = multiplicities.get(name);
					index = (mult == null ? 0 : mult.intValue() + 1);
					multiplicities.put(name, Integer.valueOf(index));
				}

				loadInstanceData(child, cur.getChild(name, index), f);
			}
		}
	} else {
		String text = getXMLText(node, true);
		if (text != null && text.trim().length() > 0) { //ignore text that is only whitespace
			//TODO: custom data types? modelPrototypes?
			cur.setValue(XFormAnswerDataParser.getAnswerData(text, cur.getDataType(), ghettoGetQuestionDef(cur.getDataType(), f, cur.getRef())));
		}
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:41,代码来源:XFormParser.java

示例11: saveInstanceNode

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void saveInstanceNode(Element instance) {
    Element instanceNode = null;
    String instanceId = instance.getAttributeValue("", "id");

    for (int i = 0; i < instance.getChildCount(); i++) {
        if (instance.getType(i) == Node.ELEMENT) {
            if (instanceNode != null) {
                throw new XFormParseException("XForm Parse: <instance> has more than one child element", instance);
            } else {
                instanceNode = instance.getElement(i);
            }
        }
    }

    if (instanceNode == null) {
        //no kids
        instanceNode = instance;
    }

    if (mainInstanceNode == null) {
        mainInstanceNode = instanceNode;
    } else if (instanceId == null) {
        throw new XFormParseException("XForm Parse: Non-main <instance> element requires an id attribute", instance);
    }

    instanceNodes.addElement(instanceNode);
    instanceNodeIdStrs.addElement(instanceId);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:29,代码来源:XFormParser.java

示例12: getLabel

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private String getLabel(Element e) {
    if (e.getChildCount() == 0) return null;

    recurseForOutput(e);

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < e.getChildCount(); i++) {
        if (e.getType(i) != Node.TEXT && !(e.getChild(i) instanceof String)) {
            Object b = e.getChild(i);
            Element child = (Element)b;

            //If the child is in the HTML namespace, retain it. 
            if (NAMESPACE_HTML.equals(child.getNamespace())) {
                sb.append(XFormSerializer.elementToString(child));
            } else {
                //Otherwise, ignore it.
                System.out.println("Unrecognized tag inside of text: <" + child.getName() + ">. " +
                        "Did you intend to use HTML markup? If so, ensure that the element is defined in " +
                        "the HTML namespace.");
            }
        } else {
            sb.append(e.getText(i));
        }
    }

    return sb.toString().trim();
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:28,代码来源:XFormParser.java

示例13: recurseForOutput

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void recurseForOutput(Element e) {
    if (e.getChildCount() == 0) return;

    for (int i = 0; i < e.getChildCount(); i++) {
        int kidType = e.getType(i);
        if (kidType == Node.TEXT) {
            continue;
        }
        if (e.getChild(i) instanceof String) {
            continue;
        }
        Element kid = (Element)e.getChild(i);

        //is just text
        if (kidType == Node.ELEMENT && XFormUtils.isOutput(kid)) {
            String s = "${" + parseOutput(kid) + "}";
            e.removeChild(i);
            e.addChild(i, Node.TEXT, s);

            //has kids? Recurse through them and swap output tag for parsed version
        } else if (kid.getChildCount() != 0) {
            recurseForOutput(kid);
            //is something else
        } else {
            continue;
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:29,代码来源:XFormParser.java

示例14: parseElement

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
 * @param e        is the current element we are parsing
 * @param parent   is the parent to the element we are parsing
 * @param handlers maps tags to IElementHandlers, used to perform parsing of that tag
 */
private void parseElement(Element e, Object parent, Hashtable<String, IElementHandler> handlers) {
    String name = e.getName();
    String namespace = e.getNamespace();

    String[] suppressWarningArr = {
            "html",
            "head",
            "body",
            "xform",
            "chooseCaption",
            "addCaption",
            "addEmptyCaption",
            "delCaption",
            "doneCaption",
            "doneEmptyCaption",
            "mainHeader",
            "entryHeader",
            "delHeader"
    };
    Vector<String> suppressWarning = new Vector<String>();
    for (int i = 0; i < suppressWarningArr.length; i++) {
        suppressWarning.addElement(suppressWarningArr[i]);
    }

    // if there is a registered parser, invoke it
    IElementHandler eh = handlers.get(name);
    if (eh != null) {
        eh.handle(this, e, parent);
    } else {
        if (inSpecExtension(namespace, name)) {
            parseUnregisteredSpecExtension(namespace, name, e, parent, handlers);
        } else {
            if (!suppressWarning.contains(name)) {
                reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP,
                        "Unrecognized element [" + name + "]. Ignoring and processing children...",
                        getVagueLocation(e));
            }
            // parse children
            for (int i = 0; i < e.getChildCount(); i++) {
                if (e.getType(i) == Element.ELEMENT) {
                    parseElement(e.getElement(i), parent, handlers);
                }
            }
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:52,代码来源:XFormParser.java

示例15: loadInstanceData

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
 * Traverse the node, copying data from it into the TreeElement argument.
 *
 * @param node Parsed XML for a form instance
 * @param cur  Valueless structure of the form instance, which will have
 *             values copied in by this method
 */
private static void loadInstanceData(Element node, TreeElement cur) {
    // TODO: hook here for turning sub-trees into complex IAnswerData
    // objects (like for immunizations)
    // FIXME: the 'ref' and FormDef parameters (along with the helper
    // function above that initializes them) are only needed so that we can
    // fetch QuestionDefs bound to the given node, as the QuestionDef
    // reference is needed to properly represent answers to select
    // questions. obviously, we want to fix this.
    int numChildren = node.getChildCount();
    boolean hasElements = false;
    for (int i = 0; i < numChildren; i++) {
        if (node.getType(i) == Node.ELEMENT) {
            hasElements = true;
            break;
        }
    }

    if (hasElements) {
        // recur on child nodes
        // stores max multiplicity seen for a given node name thus far
        Hashtable<String, Integer> multiplicities = new Hashtable<String, Integer>();
        for (int i = 0; i < numChildren; i++) {
            if (node.getType(i) == Node.ELEMENT) {
                Element child = node.getElement(i);

                String name = child.getName();
                int index;
                boolean isTemplate = (child.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null);

                if (isTemplate) {
                    index = TreeReference.INDEX_TEMPLATE;
                } else {
                    //update multiplicity counter
                    Integer mult = multiplicities.get(name);
                    index = (mult == null ? 0 : mult.intValue() + 1);
                    multiplicities.put(name, DataUtil.integer(index));
                }

                loadInstanceData(child, cur.getChild(name, index));
            }
        }
    } else {
        // copy values from node into current tree element
        String text = getXMLText(node, true);
        if (text != null && text.trim().length() > 0) {
            // ignore text that is only whitespace
            // TODO: custom data types? modelPrototypes?
            cur.setValue(AnswerDataFactory.templateByDataType(cur.getDataType()).cast(new UncastData(text.trim())));
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:59,代码来源:XFormParser.java


注:本文中的org.kxml2.kdom.Element.getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。