本文整理汇总了Java中org.kxml2.kdom.Element.getElement方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getElement方法的具体用法?Java Element.getElement怎么用?Java Element.getElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.kdom.Element
的用法示例。
在下文中一共展示了Element.getElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseIText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseIText (Element itext) {
Localizer l = new Localizer(true, true);
_f.setLocalizer(l);
l.registerLocalizable(_f);
ArrayList<String> usedAtts = new ArrayList<String>(); //used for warning message
for (int i = 0; i < itext.getChildCount(); i++) {
Element trans = itext.getElement(i);
if (trans == null || !trans.getName().equals("translation"))
continue;
parseTranslation(l, trans);
}
if (l.getAvailableLocales().length == 0)
throw new XFormParseException("no <translation>s defined",itext);
if (l.getDefaultLocale() == null)
l.setDefaultLocale(l.getAvailableLocales()[0]);
//print unused attribute warning message for parent element
if(XFormUtils.showUnusedAttributeWarning(itext, usedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
}
}
示例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: parseIText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseIText(Element itext) {
Localizer l = new Localizer(true, true);
_f.setLocalizer(l);
l.registerLocalizable(_f);
Vector<String> usedAtts = new Vector<String>(); //used for warning message
for (int i = 0; i < itext.getChildCount(); i++) {
Element trans = itext.getElement(i);
if (trans == null || !trans.getName().equals("translation"))
continue;
parseTranslation(l, trans);
}
if (l.getAvailableLocales().length == 0)
throw new XFormParseException("no <translation>s defined", itext);
if (l.getDefaultLocale() == null)
l.setDefaultLocale(l.getAvailableLocales()[0]);
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(itext, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
}
}
示例4: parseIText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseIText(Element itext) {
Localizer l = new Localizer(true, true);
_f.setLocalizer(l);
Vector<String> usedAtts = new Vector<>(); //used for warning message
for (int i = 0; i < itext.getChildCount(); i++) {
Element trans = itext.getElement(i);
if (trans == null || !trans.getName().equals("translation"))
continue;
parseTranslation(l, trans);
}
if (l.getAvailableLocales().length == 0)
throw new XFormParseException("no <translation>s defined", itext);
if (l.getDefaultLocale() == null)
l.setDefaultLocale(l.getAvailableLocales()[0]);
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(itext, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
}
}
示例5: 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;
}
示例6: 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);
}
示例7: 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())));
}
}
}
示例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;
} else if (instanceId == null) {
throw new XFormParseException("XForm Parse: Non-main <instance> element requires an id attribute", instance);
}
instanceNodes.addElement(instanceNode);
instanceNodeIdStrs.addElement(instanceId);
}
示例9: parseTranslation
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseTranslation (Localizer l, Element trans) {
/////for warning message
List<String> usedAtts = new ArrayList<String>();
usedAtts.add("lang");
usedAtts.add("default");
/////////////////////////
String lang = trans.getAttributeValue("", "lang");
if (lang == null || lang.length() == 0) {
throw new XFormParseException("no language specified for <translation>",trans);
}
String isDefault = trans.getAttributeValue("", "default");
if (!l.addAvailableLocale(lang)) {
throw new XFormParseException("duplicate <translation> for language '" + lang + "'",trans);
}
if (isDefault != null) {
if (l.getDefaultLocale() != null)
throw new XFormParseException("more than one <translation> set as default",trans);
l.setDefaultLocale(lang);
}
TableLocaleSource source = new TableLocaleSource();
//source.startEditing();
for (int j = 0; j < trans.getChildCount(); j++) {
Element text = trans.getElement(j);
if (text == null || !text.getName().equals("text")) {
continue;
}
parseTextHandle(source, text);
//Clayton Sims - Jun 17, 2009 - This code is used when the stinginess flag
//is set for the build. It dynamically wipes out old model nodes once they're
//used. This is sketchy if anything else plans on touching the nodes.
//This code can be removed once we're pull-parsing
//#if org.javarosa.xform.stingy
trans.removeChild(j);
--j;
//#endif
}
//print unused attribute warning message for parent element
if(XFormUtils.showUnusedAttributeWarning(trans, usedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(trans, usedAtts), getVagueLocation(trans));
}
//source.stopEditing();
l.registerLocaleResource(lang, source);
}
示例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: parseTranslation
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseTranslation(Localizer l, Element trans) {
/////for warning message
Vector<String> usedAtts = new Vector<String>();
usedAtts.addElement("lang");
usedAtts.addElement("default");
/////////////////////////
String lang = trans.getAttributeValue("", "lang");
if (lang == null || lang.length() == 0) {
throw new XFormParseException("no language specified for <translation>", trans);
}
String isDefault = trans.getAttributeValue("", "default");
if (!l.addAvailableLocale(lang)) {
throw new XFormParseException("duplicate <translation> for language '" + lang + "'", trans);
}
if (isDefault != null) {
if (l.getDefaultLocale() != null)
throw new XFormParseException("more than one <translation> set as default", trans);
l.setDefaultLocale(lang);
}
TableLocaleSource source = new TableLocaleSource();
//source.startEditing();
for (int j = 0; j < trans.getChildCount(); j++) {
Element text = trans.getElement(j);
if (text == null || !text.getName().equals("text")) {
continue;
}
parseTextHandle(source, text);
//Clayton Sims - Jun 17, 2009 - This code is used when the stinginess flag
//is set for the build. It dynamically wipes out old model nodes once they're
//used. This is sketchy if anything else plans on touching the nodes.
//This code can be removed once we're pull-parsing
//#if org.javarosa.xform.stingy
trans.removeChild(j);
--j;
//#endif
}
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(trans, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(trans, usedAtts), getVagueLocation(trans));
}
//source.stopEditing();
l.registerLocaleResource(lang, source);
}
示例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: 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));
}
}
示例15: parseTranslation
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseTranslation(Localizer l, Element trans) {
/////for warning message
Vector<String> usedAtts = new Vector<>();
usedAtts.addElement("lang");
usedAtts.addElement("default");
/////////////////////////
String lang = trans.getAttributeValue("", "lang");
if (lang == null || lang.length() == 0) {
throw new XFormParseException("no language specified for <translation>", trans);
}
String isDefault = trans.getAttributeValue("", "default");
if (!l.addAvailableLocale(lang)) {
throw new XFormParseException("duplicate <translation> for language '" + lang + "'", trans);
}
if (isDefault != null) {
if (l.getDefaultLocale() != null)
throw new XFormParseException("more than one <translation> set as default", trans);
l.setDefaultLocale(lang);
}
TableLocaleSource source = new TableLocaleSource();
//source.startEditing();
for (int j = 0; j < trans.getChildCount(); j++) {
Element text = trans.getElement(j);
if (text == null || !text.getName().equals("text")) {
continue;
}
parseTextHandle(source, text);
//Clayton Sims - Jun 17, 2009 - This code is used when the stinginess flag
//is set for the build. It dynamically wipes out old model nodes once they're
//used. This is sketchy if anything else plans on touching the nodes.
//This code can be removed once we're pull-parsing
//#if org.javarosa.xform.stingy
trans.removeChild(j);
--j;
//#endif
}
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(trans, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(trans, usedAtts), getVagueLocation(trans));
}
//source.stopEditing();
l.registerLocaleResource(lang, source);
}