本文整理汇总了Java中org.kxml2.kdom.Element.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getName方法的具体用法?Java Element.getName怎么用?Java Element.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.kdom.Element
的用法示例。
在下文中一共展示了Element.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: 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;
}
示例4: unusedAttWarning
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
* @return String warning about which attributes from 'e' aren't in 'usedAtts'
*/
public static String unusedAttWarning(Element e, Vector<String> usedAtts) {
String warning = "";
Vector<String> unusedAtts = getUnusedAttributes(e, usedAtts);
warning += unusedAtts.size() + " unrecognized attributes found in Element [" +
e.getName() + "] and will be ignored: ";
warning += "[";
for (int i = 0; i < unusedAtts.size(); i++) {
warning += unusedAtts.elementAt(i);
if (i != unusedAtts.size() - 1) {
warning += ",";
}
}
warning += "] ";
return warning;
}
示例5: 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);
}
}
}
}
示例6: 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())));
}
}
}
示例7: unusedAttWarning
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
public static String unusedAttWarning(Element e, List<String> usedAtts){
String warning = "Warning: ";
List<String> ua = getUnusedAttributes(e,usedAtts);
warning+=ua.size()+" Unrecognized attributes found in Element ["+e.getName()+"] and will be ignored: ";
warning+="[";
for(int i=0;i<ua.size();i++){
warning+=ua.get(i);
if(i!=ua.size()-1) warning+=",";
}
warning+="] ";
warning+="Location:\n"+XFormParser.getVagueLocation(e);
return warning;
}
示例8: parseHelperText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
* Handles hint elements (text-only) and help elements (similar, but may include multimedia)
*
* @param q The QuestionDef object to augment with the hint/help
* @param e The Element to parse
*/
private void parseHelperText(QuestionDef q, Element e) {
Vector<String> usedAtts = new Vector<String>();
usedAtts.addElement(REF_ATTR);
String XMLText = getXMLText(e, true);
String innerText = getLabel(e);
String ref = e.getAttributeValue("", REF_ATTR);
String name = e.getName();
QuestionString mQuestionString = new QuestionString(name);
q.putQuestionString(name, mQuestionString);
if (ref != null) {
if (ref.startsWith(ITEXT_OPEN) && ref.endsWith(ITEXT_CLOSE)) {
String textRef = ref.substring(ITEXT_OPEN.length(), ref.indexOf(ITEXT_CLOSE));
verifyTextMappings(textRef, "<" + name + ">", true);
mQuestionString.setTextId(textRef);
} else {
// TODO: shouldn't this raise an XFormParseException?
throw new RuntimeException("malformed ref [" + ref + "] for <" + name + ">");
}
}
mQuestionString.setTextInner(innerText);
mQuestionString.setTextFallback(XMLText);
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}
示例9: parseHelperText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
* Handles hint elements (text-only) and help elements (similar, but may include multimedia)
*
* @param q The QuestionDef object to augment with the hint/help
* @param e The Element to parse
*/
private void parseHelperText(QuestionDef q, Element e) {
Vector<String> usedAtts = new Vector<>();
usedAtts.addElement(REF_ATTR);
String XMLText = getXMLText(e, true);
String innerText = getLabel(e);
String ref = e.getAttributeValue("", REF_ATTR);
String name = e.getName();
QuestionString mQuestionString = new QuestionString(name);
q.putQuestionString(name, mQuestionString);
if (ref != null) {
if (ref.startsWith(ITEXT_OPEN) && ref.endsWith(ITEXT_CLOSE)) {
String textRef = ref.substring(ITEXT_OPEN.length(), ref.indexOf(ITEXT_CLOSE));
verifyTextMappings(textRef, "<" + name + ">", true);
mQuestionString.setTextId(textRef);
} else {
// TODO: shouldn't this raise an XFormParseException?
throw new RuntimeException("malformed ref [" + ref + "] for <" + name + ">");
}
}
mQuestionString.setTextInner(innerText);
mQuestionString.setTextFallback(XMLText);
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}
示例10: parseTextHandle
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseTextHandle (TableLocaleSource l, Element text) {
String id = text.getAttributeValue("", ID_ATTR);
//used for parser warnings...
List<String> usedAtts = new ArrayList<String>();
List<String> childUsedAtts = new ArrayList<String>();
usedAtts.add(ID_ATTR);
usedAtts.add(FORM_ATTR);
childUsedAtts.add(FORM_ATTR);
childUsedAtts.add(ID_ATTR);
//////////
if (id == null || id.length() == 0) {
throw new XFormParseException("no id defined for <text>",text);
}
for (int k = 0; k < text.getChildCount(); k++) {
Element value = text.getElement(k);
if (value == null) continue;
if(!value.getName().equals(VALUE)){
throw new XFormParseException("Unrecognized element ["+value.getName()+"] in Itext->translation->text");
}
String form = value.getAttributeValue("", FORM_ATTR);
if (form != null && form.length() == 0) {
form = null;
}
String data = getLabel(value);
if (data == null) {
data = "";
}
String textID = (form == null ? id : id + ";" + form); //kind of a hack
if (l.hasMapping(textID)) {
throw new XFormParseException("duplicate definition for text ID \"" + id + "\" and form \"" + form + "\""+". Can only have one definition for each text form.",text);
}
l.setLocaleMapping(textID, data);
//print unused attribute warning message for child element
if(XFormUtils.showUnusedAttributeWarning(value, childUsedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(value, childUsedAtts), getVagueLocation(value));
}
}
//print unused attribute warning message for parent element
if(XFormUtils.showUnusedAttributeWarning(text, usedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(text, usedAtts), getVagueLocation(text));
}
}
示例11: 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);
}
}
}
}
}
示例12: parseTextHandle
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseTextHandle(TableLocaleSource l, Element text) {
String id = text.getAttributeValue("", ID_ATTR);
//used for parser warnings...
Vector<String> usedAtts = new Vector<String>();
Vector<String> childUsedAtts = new Vector<String>();
usedAtts.addElement(ID_ATTR);
usedAtts.addElement(FORM_ATTR);
childUsedAtts.addElement(FORM_ATTR);
childUsedAtts.addElement(ID_ATTR);
//////////
if (id == null || id.length() == 0) {
throw new XFormParseException("no id defined for <text>", text);
}
for (int k = 0; k < text.getChildCount(); k++) {
Element value = text.getElement(k);
if (value == null) continue;
if (!value.getName().equals(VALUE)) {
throw new XFormParseException("Unrecognized element [" + value.getName() + "] in Itext->translation->text");
}
String form = value.getAttributeValue("", FORM_ATTR);
if (form != null && form.length() == 0) {
form = null;
}
String data = getLabel(value);
if (data == null) {
data = "";
}
String textID = (form == null ? id : id + ";" + form); //kind of a hack
if (l.hasMapping(textID)) {
throw new XFormParseException("duplicate definition for text ID \"" + id + "\" and form \"" + form + "\"" + ". Can only have one definition for each text form.", text);
}
l.setLocaleMapping(textID, data);
//print unused attribute warning message for child element
if (XFormUtils.showUnusedAttributeWarning(value, childUsedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(value, childUsedAtts), getVagueLocation(value));
}
}
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(text, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(text, usedAtts), getVagueLocation(text));
}
}
示例13: 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())));
}
}
}
示例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<>();
for (String aSuppressWarningArr : suppressWarningArr) {
suppressWarning.addElement(aSuppressWarningArr);
}
// 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);
}
}
}
}
}
示例15: parseItemset
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseItemset(QuestionDef q, Element e) {
ItemsetBinding itemset = new ItemsetBinding();
////////////////USED FOR PARSER WARNING OUTPUT ONLY
//catalogue of used attributes in this method/element
Vector<String> usedAtts = new Vector<>();
Vector<String> labelUA = new Vector<>(); //for child with name 'label'
Vector<String> valueUA = new Vector<>(); //for child with name 'value'
Vector<String> copyUA = new Vector<>(); //for child with name 'copy'
usedAtts.addElement(NODESET_ATTR);
labelUA.addElement(REF_ATTR);
valueUA.addElement(REF_ATTR);
valueUA.addElement(FORM_ATTR);
copyUA.addElement(REF_ATTR);
////////////////////////////////////////////////////
String nodesetStr = e.getAttributeValue("", NODESET_ATTR);
if (nodesetStr == null) {
throw new RuntimeException("No nodeset attribute in element: [" + e.getName() + "]. This is required. (Element Printout:" + XFormSerializer.elementToString(e) + ")");
}
XPathPathExpr path = XPathReference.getPathExpr(nodesetStr);
itemset.nodesetExpr = new XPathConditional(path);
itemset.contextRef = getFormElementRef(q);
itemset.nodesetRef = FormInstance.unpackReference(getAbsRef(new XPathReference(path.getReference()), itemset.contextRef));
for (int i = 0; i < e.getChildCount(); i++) {
int type = e.getType(i);
Element child = (type == Node.ELEMENT ? e.getElement(i) : null);
String childName = (child != null ? child.getName() : null);
if (LABEL_ELEMENT.equals(childName)) {
parseItemsetLabelElement(child, itemset, labelUA);
} else if ("copy".equals(childName)) {
parseItemsetCopyElement(child, itemset, copyUA);
} else if (VALUE.equals(childName)) {
parseItemsetValueElement(child, itemset, valueUA);
} else if (SORT.equals(childName)) {
parseItemsetSortElement(child, itemset);
}
}
if (itemset.labelRef == null) {
throw new XFormParseException("<itemset> requires <label>");
} else if (itemset.copyRef == null && itemset.valueRef == null) {
throw new XFormParseException("<itemset> requires <copy> or <value>");
}
if (itemset.copyRef != null) {
if (itemset.valueRef == null) {
reporter.warning(XFormParserReporter.TYPE_TECHNICAL, "<itemset>s with <copy> are STRONGLY recommended to have <value> as well; pre-selecting, default answers, and display of answers will not work properly otherwise", getVagueLocation(e));
} else if (!itemset.copyRef.isParentOf(itemset.valueRef, false)) {
throw new XFormParseException("<value> is outside <copy>");
}
}
q.setDynamicChoices(itemset);
itemsets.addElement(itemset);
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}