本文整理了Java中org.jdom.Element
类的一些代码示例,展示了Element
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element
类的具体详情如下:
包路径:org.jdom.Element
类名称:Element
[英]An XML element. Methods allow the user to get and manipulate its child elements and content, directly access the element's textual content, manipulate its attributes, and manage namespaces.
[中]XML元素。方法允许用户获取和操作其子元素和内容,直接访问元素的文本内容,操作其属性,以及管理名称空间。
代码示例来源:origin: hsz/idea-gitignore
/**
* Loads {@link UserTemplate} objects from the {@link Element}.
*
* @param element source
* @return {@link UserTemplate} list
*/
@NotNull
public static List<UserTemplate> loadTemplates(@NotNull Element element) {
final String key = KEY.USER_TEMPLATES.toString();
final List<UserTemplate> list = ContainerUtil.newArrayList();
if (!key.equals(element.getName())) {
element = element.getChild(key);
}
for (Element template : element.getChildren()) {
list.add(new UserTemplate(
template.getAttributeValue(KEY.USER_TEMPLATES_NAME.toString()),
template.getText()
));
}
return list;
}
代码示例来源:origin: voldemort/voldemort
public String writeCluster(Cluster cluster) {
Document doc = new Document(new Element(CLUSTER_ELMT));
doc.getRootElement().addContent(new Element(CLUSTER_NAME_ELMT).setText(cluster.getName()));
boolean displayZones = cluster.getZones().size() > 1;
if(displayZones) {
for(Zone n: cluster.getZones())
doc.getRootElement().addContent(mapZone(n));
}
for(Node n: cluster.getNodes())
doc.getRootElement().addContent(mapServer(n, displayZones));
XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
return serializer.outputString(doc.getRootElement());
}
代码示例来源:origin: JetBrains/ideavim
public void saveData(@NotNull Element element) {
if (isKeyRepeat != null) {
final Element editor = new Element("editor");
element.addContent(editor);
final Element keyRepeat = new Element("key-repeat");
keyRepeat.setAttribute("enabled", Boolean.toString(isKeyRepeat));
editor.addContent(keyRepeat);
}
}
代码示例来源:origin: JetBrains/ideavim
public void readData(@NotNull Element element) {
final Element editor = element.getChild("editor");
if (editor != null) {
final Element keyRepeat = editor.getChild("key-repeat");
if (keyRepeat != null) {
final String enabled = keyRepeat.getAttributeValue("enabled");
if (enabled != null) {
isKeyRepeat = Boolean.valueOf(enabled);
}
}
}
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private static boolean isAttachProjectDirToLibraries(Element rootElement) {
Element goProjectSettings = JDomSerializationUtil.findComponent(rootElement, "GoProjectSettings");
if (goProjectSettings != null) {
for (Element option : goProjectSettings.getChildren("option")) {
if ("prependGoPath".equals(option.getAttributeValue("name"))) {
goProjectSettings.detach();
return "true".equalsIgnoreCase(option.getAttributeValue("value"));
}
}
goProjectSettings.detach();
}
return false;
}
代码示例来源:origin: com.ebmwebsourcing.easybpel/easybpel.xpath.exp.impl
public Element visit(final ASTNullLiteral node, final Element data)
throws XPathExpressionException {
final Element res = new Element("value");
res.setAttribute("type", "xsd:string");
res.addNamespaceDeclaration(Namespace.getNamespace("xsd",
Constants.SCHEMA_NAMESPACE));
this.log.finest(this.indentString() + node);
++this.indent;
final Document doc = new Document(res);
this.log.finest(this.indentString() + node);
--this.indent;
return doc.getRootElement();
}
代码示例来源:origin: voldemort/voldemort
public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(input);
if(verifySchema) {
Validator validator = schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if(!root.getName().equals(STORES_ELMT))
throw new MappingException("Invalid root element: "
+ doc.getRootElement().getName());
List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
for(Object store: root.getChildren(STORE_ELMT))
stores.add(readStore((Element) store));
for(Object view: root.getChildren(VIEW_ELMT))
stores.add(readView((Element) view, stores));
return stores;
} catch(JDOMException e) {
throw new MappingException(e);
} catch(SAXException e) {
throw new MappingException(e);
} catch(IOException e) {
throw new MappingException(e);
}
}
代码示例来源:origin: voldemort/voldemort
private static SerializerDefinition parseSerializerDefinition(String serializerInfoXml,
String elementName) {
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(new StringReader(serializerInfoXml));
Element root = doc.getRootElement();
Element serializerElement = root.getChild(elementName);
return StoreDefinitionsMapper.readSerializer(serializerElement);
} catch(JDOMException e) {
throw new MappingException(e);
} catch(IOException e) {
throw new MappingException(e);
}
}
代码示例来源:origin: net.sf.taverna.t2.core/workflowmodel-impl
private void populateBeanElementFromXStream(Object obj, Element bean)
throws JDOMException, IOException {
bean.setAttribute(BEAN_ENCODING, XSTREAM_ENCODING);
XStream xstream = new XStream(new DomDriver());
SAXBuilder builder = new SAXBuilder();
Element configElement = builder.build(
new StringReader(xstream.toXML(obj))).getRootElement();
configElement.getParent().removeContent(configElement);
bean.addContent(configElement);
}
代码示例来源:origin: banq/jdonframework
public static Map loadMapping(String fileName, String nodeName, String keyName,
String valueName) {
Map map = new HashMap();
FileLocator fileLocator = new FileLocator();
try {
String xmlFile = fileLocator.getConfFile(fileName);
Debug.logVerbose("[JdonFramework] mapping file:" + xmlFile, module);
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File(xmlFile));
Debug.logVerbose("[JdonFramework] got mapping file ", module);
// Get the root element
Element root = doc.getRootElement();
List mappings = root.getChildren(nodeName);
Iterator i = mappings.iterator();
while (i.hasNext()) {
Element mapping = (Element) i.next();
String key = mapping.getChild(keyName).getTextTrim();
String value = mapping.getChild(valueName).getTextTrim();
Debug.logVerbose("[JdonFramework] get the " + key + "=" + value, module);
map.put(key, value);
}
Debug.logVerbose("[JdonFramework] read finished", module);
} catch (Exception ex) {
Debug.logError("[JdonFramework] error: " + ex, module);
}
return map;
}
代码示例来源:origin: kiegroup/optaplanner
shiftOnRequestList = Collections.emptyList();
} else {
List<Element> shiftOnElementList = (List<Element>) shiftOnRequestsElement.getChildren();
shiftOnRequestList = new ArrayList<>(shiftOnElementList.size());
long id = 0L;
shiftOnRequest.setId(id);
Element employeeElement = element.getChild("EmployeeID");
Employee employee = employeeMap.get(employeeElement.getText());
if (employee == null) {
throw new IllegalArgumentException("The shift (" + employeeElement.getText()
+ ") of shiftOnRequest (" + shiftOnRequest + ") does not exist.");
Element dateElement = element.getChild("Date");
Element shiftTypeElement = element.getChild("ShiftTypeID");
LocalDate date = LocalDate.parse(dateElement.getText(), DateTimeFormatter.ISO_DATE);
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date, shiftTypeElement.getText()));
if (shift == null) {
throw new IllegalArgumentException("The date (" + dateElement.getText()
+ ") or the shiftType (" + shiftTypeElement.getText()
+ ") of shiftOnRequest (" + shiftOnRequest + ") does not exist.");
shiftOnRequest.setWeight(element.getAttribute("weight").getIntValue());
代码示例来源:origin: x-ream/x7
SAXBuilder builder = new SAXBuilder(false);
Document doc = builder.build(in);
Element configRoot = doc.getRootElement();
List<?> configList = configRoot.getChildren("book");
fileNames.clear();
Element configItem = (Element) configObject;
String fileName = configItem.getAttributeValue("name");
fileNames.add(fileName);
fileSheetNameClassMap.put(fileName, sheetNameList);
List<Element> sheetElementList = configItem.getChildren("sheet");
String sheetName = sheetE.getAttributeValue("name");
Class<ITemplateable> clz = (Class<ITemplateable>) Class.forName(sheetE.getAttributeValue("type"));
代码示例来源:origin: voldemort/voldemort
public static SerializerDefinition readSerializer(Element elmt) {
String name = elmt.getChild(STORE_SERIALIZATION_TYPE_ELMT).getText();
boolean hasVersion = true;
Map<Integer, String> schemaInfosByVersion = new HashMap<Integer, String>();
for(Object schemaInfo: elmt.getChildren(STORE_SERIALIZATION_META_ELMT)) {
Element schemaInfoElmt = (Element) schemaInfo;
String versionStr = schemaInfoElmt.getAttributeValue(STORE_VERSION_ATTR);
int version;
if(versionStr == null) {
version = Integer.parseInt(versionStr);
String info = schemaInfoElmt.getText();
String previous = schemaInfosByVersion.put(version, info);
if(previous != null)
throw new IllegalArgumentException("Specified multiple schemas AND version=none, which is not permitted.");
Element compressionElmt = elmt.getChild(STORE_COMPRESSION_ELMT);
Compression compression = null;
if(compressionElmt != null)
compression = new Compression(compressionElmt.getChildText("type"),
compressionElmt.getChildText("options"));
return new SerializerDefinition(name, schemaInfosByVersion, hasVersion, compression);
代码示例来源:origin: jaxen/jaxen
Element node = (Element) contextNode;
if (namespaceURI == null) {
return node.getChildren(localName).iterator();
return node.getChildren(localName, Namespace.getNamespace(namespacePrefix, namespaceURI)).iterator();
Element el = node.getRootElement();
if (el.getName().equals(localName) == false) {
return JaxenConstants.EMPTY_ITERATOR;
if (!Namespace.getNamespace(namespacePrefix, namespaceURI).equals(el.getNamespace())) {
return JaxenConstants.EMPTY_ITERATOR;
else if(el.getNamespace() != Namespace.NO_NAMESPACE) {
return JaxenConstants.EMPTY_ITERATOR;
代码示例来源:origin: org.freemarker/freemarker
@Override
void getChildren(Object node, String localName, String namespaceUri, List result) {
if (node instanceof Element) {
Element e = (Element) node;
if (localName == null) {
result.addAll(e.getChildren());
} else {
result.addAll(e.getChildren(localName, Namespace.getNamespace("", namespaceUri)));
}
} else if (node instanceof Document) {
Element root = ((Document) node).getRootElement();
if (localName == null || (equal(root.getName(), localName) && equal(root.getNamespaceURI(), namespaceUri))) {
result.add(root);
}
}
}
代码示例来源:origin: org.freemarker/freemarker
public List operate(Object node, String localName, Namespace namespace) {
if (node instanceof Element) {
return((Element) node).getChildren(localName, namespace);
} else if (node instanceof Document) {
Element root = ((Document) node).getRootElement();
if (root != null &&
root.getName().equals(localName) &&
root.getNamespaceURI().equals(namespace.getURI())) {
return Collections.singletonList(root);
} else
return Collections.EMPTY_LIST;
}
// With 2.1 semantics it makes more sense to just return a null and let the core
// throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR)
return null;
/*
else
throw new TemplateModelException("_namedChildren can not be applied on " + node.getClass());
*/
}
}
代码示例来源:origin: banq/jdonframework
/**
* Sets the value of the specified property. If the property doesn't
* currently exist, it will be automatically created.
*
* @param name
* the name of the property to set.
* @param value
* the new value for the property.
*/
public void setProperty(String name, String value) {
// Set cache correctly with prop name and value.
propertyCache.put(name, value);
String[] propName = parsePropertyName(name);
// Search for this property by traversing down the XML heirarchy.
Element element = doc.getRootElement();
for (int i = 0; i < propName.length; i++) {
// If we don't find this part of the property in the XML heirarchy
// we add it as a new node
if (element.getChild(propName[i]) == null) {
element.addContent(new Element(propName[i]));
}
element = element.getChild(propName[i]);
}
// Set the value of the property in this node.
element.setText(value);
}
代码示例来源:origin: voldemort/voldemort
private Element mapZone(Zone zone) {
Element zoneElement = new Element(ZONE_ELMT);
zoneElement.addContent(new Element(ZONE_ID_ELMT).setText(Integer.toString(zone.getId())));
String proximityListTest = StringUtils.join(zone.getProximityList().toArray(), ", ");
zoneElement.addContent(new Element(ZONE_PROXIMITY_LIST_ELMT).setText(proximityListTest));
return zoneElement;
}
代码示例来源:origin: JetBrains/ideavim
public void readData(@NotNull Element element) {
final Element conflictsElement = element.getChild(SHORTCUT_CONFLICTS_ELEMENT);
if (conflictsElement != null) {
final java.util.List<Element> conflictElements = conflictsElement.getChildren(SHORTCUT_CONFLICT_ELEMENT);
for (Element conflictElement : conflictElements) {
final String ownerValue = conflictElement.getAttributeValue(OWNER_ATTRIBUTE);
ShortcutOwner owner = ShortcutOwner.UNDEFINED;
try {
owner = ShortcutOwner.fromString(ownerValue);
}
catch (IllegalArgumentException ignored) {
}
final Element textElement = conflictElement.getChild(TEXT_ELEMENT);
if (textElement != null) {
final String text = StringHelper.getSafeXmlText(textElement);
if (text != null) {
final KeyStroke keyStroke = KeyStroke.getKeyStroke(text);
if (keyStroke != null) {
shortcutConflicts.put(keyStroke, owner);
}
}
}
}
}
}
代码示例来源:origin: voldemort/voldemort
public static void addSerializer(Element parent, SerializerDefinition def) {
parent.addContent(new Element(STORE_SERIALIZATION_TYPE_ELMT).setText(def.getName()));
if(def.hasSchemaInfo()) {
for(Map.Entry<Integer, String> entry: def.getAllSchemaInfoVersions().entrySet()) {
Element schemaElmt = new Element(STORE_SERIALIZATION_META_ELMT);
if(def.hasVersion())
schemaElmt.setAttribute(STORE_VERSION_ATTR, Integer.toString(entry.getKey()));
else
schemaElmt.setAttribute(STORE_VERSION_ATTR, "none");
schemaElmt.setText(entry.getValue());
parent.addContent(schemaElmt);
}
}
if(def.hasCompression()) {
Compression compression = def.getCompression();
Element compressionElmt = new Element(STORE_COMPRESSION_ELMT);
Element type = new Element(STORE_COMPRESSION_TYPE_ELMT);
type.setText(compression.getType());
compressionElmt.addContent(type);
String optionsText = compression.getOptions();
if(optionsText != null) {
Element options = new Element(STORE_COMPRESSION_OPTIONS_ELMT);
options.setText(optionsText);
compressionElmt.addContent(options);
}
parent.addContent(compressionElmt);
}
}
内容来源于网络,如有侵权,请联系作者删除!