本文整理了Java中org.jdom2.Element.getAttribute()
方法的一些代码示例,展示了Element.getAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getAttribute()
方法的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
方法名:getAttribute
[英]This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
[中]这将返回具有给定名称且不在名称空间内的该元素的属性,如果不存在此类属性,则返回null。
代码示例来源:origin: gocd/gocd
public String getAttribute(Element e, String attribute) {
Attribute attr = e.getAttribute(attribute);
if(attr == null) {
throw bomb("Error finding attribute '" + attribute + "' in config: " + configFile + elementOutput(e));
}
return attr.getValue();
}
代码示例来源:origin: simpligility/android-maven-plugin
@SuppressWarnings( "unchecked" )
private void appendElement( Element source, Element target )
{
for ( Iterator<Attribute> itr = source.getAttributes().iterator(); itr.hasNext(); )
{
Attribute a = itr.next();
itr.remove();
Attribute mergedAtt = target.getAttribute( a.getName(), a.getNamespace() );
if ( mergedAtt == null )
{
target.setAttribute( a );
}
}
for ( Iterator<Element> itr = source.getChildren().iterator(); itr.hasNext(); )
{
Content n = itr.next();
itr.remove();
target.addContent( n );
}
}
代码示例来源:origin: jwpttcg66/NettyGameServer
public FieldObject(Element element){
this.type = element.getAttributeValue("type");
this.name = element.getAttributeValue("name");
this.comment =element.getAttributeValue("comment");
Attribute genericAttr = element.getAttribute("generic");
if(genericAttr != null){
this.generic = genericAttr.getValue();
}
MacroObject macroObj = MacroObject.getAllMacros().get(this.type);
if(macroObj != null){
this.selfObj = macroObj;
}
macroObj = MacroObject.getAllMacros().get(this.generic);
if(macroObj != null){
this.genericObj = macroObj;
}
}
代码示例来源:origin: rometools/rome
protected void parseCategoriesElement(final Element catsElem) {
if (catsElem.getAttribute("href", AtomService.ATOM_PROTOCOL) != null) {
setHref(catsElem.getAttribute("href", AtomService.ATOM_PROTOCOL).getValue());
}
if (catsElem.getAttribute("fixed", AtomService.ATOM_PROTOCOL) != null) {
if ("yes".equals(catsElem.getAttribute("fixed", AtomService.ATOM_PROTOCOL).getValue())) {
setFixed(true);
}
}
if (catsElem.getAttribute("scheme", AtomService.ATOM_PROTOCOL) != null) {
setScheme(catsElem.getAttribute("scheme", AtomService.ATOM_PROTOCOL).getValue());
}
// Loop to parse <atom:category> elemenents to Category objects
final List<Element> catElems = catsElem.getChildren("category", AtomService.ATOM_FORMAT);
for (final Element catElem : catElems) {
final Category cat = new Category();
cat.setTerm(catElem.getAttributeValue("term", AtomService.ATOM_FORMAT));
cat.setLabel(catElem.getAttributeValue("label", AtomService.ATOM_FORMAT));
cat.setScheme(catElem.getAttributeValue("scheme", AtomService.ATOM_FORMAT));
addCategory(cat);
}
}
代码示例来源:origin: rometools/rome
/** Use feed links and/or xml:base attribute to determine baseURI of feed */
private static URL findBaseURI(final Element root) {
URL baseURI = null;
final List<Element> linksList = root.getChildren("link", OS_NS);
if (linksList != null) {
for (final Element element : linksList) {
final Element link = element;
if (!root.equals(link.getParent())) {
break;
}
String href = link.getAttribute("href").getValue();
if (link.getAttribute("rel", OS_NS) == null || link.getAttribute("rel", OS_NS).getValue().equals("alternate")) {
href = resolveURI(null, link, href);
try {
baseURI = new URL(href);
break;
} catch (final MalformedURLException e) {
System.err.println("Base URI is malformed: " + href);
}
}
}
}
return baseURI;
}
}
代码示例来源:origin: rometools/rome
if (element.getChild("treatAs", NS) == null) {
return null;
sle.setTreatAs(element.getChildText("treatAs", NS));
final Element listInfo = element.getChild("listinfo", NS);
ArrayList<Object> values = new ArrayList<Object>();
for (final Element ge : listInfo.getChildren("group", NS)) {
final Namespace ns = ge.getAttribute("ns") == null ? element.getNamespace() : Namespace.getNamespace(ge.getAttributeValue("ns"));
final String elementName = ge.getAttributeValue("element");
final String label = ge.getAttributeValue("label");
values = values.size() == 0 ? values : new ArrayList<Object>();
for (final Element se : listInfo.getChildren("sort", NS)) {
LOG.debug("Parse cf:sort {}{}", se.getAttributeValue("element"), se.getAttributeValue("data-type"));
final Namespace ns = se.getAttributeValue("ns") == null ? element.getNamespace() : Namespace.getNamespace(se.getAttributeValue("ns"));
insertValues(sle, element.getChildren());
代码示例来源:origin: sc.fiji/TrackMate_
/**
* Returns the version string stored in the file.
*/
public String getVersion()
{
return root.getChild( "trackfile" ).getAttribute( "version" ).getValue();
}
代码示例来源:origin: vasl-developers/vasl
for(Element e: element.getChildren()) {
e.getAttribute(colorRedAttribute).getIntValue(),
e.getAttribute(colorGreenAttribute).getIntValue(),
e.getAttribute(colorBlueAttribute).getIntValue()
);
代码示例来源:origin: sc.fiji/TrackMate_
private static final double readDistanceCutoffAttribute( final Element element )
{
double val = 0;
try
{
val = element.getChild( TRACKER_SETTINGS_DISTANCE_CUTOFF_ELEMENT )
.getAttribute( TRACKER_SETTINGS_DISTANCE_CUTOFF_ATTNAME_v12 ).getDoubleValue();
}
catch ( final DataConversionException e )
{}
return val;
}
代码示例来源:origin: org.apache.marmotta/ldclient-provider-mediawiki
protected List<String> parseRevision(URI resource, String requestUrl, Model model, ValueFactory valueFactory,
Element revisions, Context context) throws RepositoryException {
List<String> followUp = Collections.emptyList();
if (revisions == null) return followUp;
final Element rev = revisions.getChild("rev");
if (rev == null) return followUp;
final Resource subject = resource;
if (context == Context.META && "0".equals(rev.getAttributeValue("parentid"))) {
// This is the first revision, so we use the creation date
addLiteralTriple(subject, Namespaces.NS_DC_TERMS + "created", rev.getAttributeValue("timestamp"), Namespaces.NS_XSD + "dateTime", model,
valueFactory);
}
if (context == Context.CONTENT && rev.getValue() != null && rev.getValue().trim().length() > 0) {
final String content = rev.getValue().trim();
final Matcher m = REDIRECT_PATTERN.matcher(content);
if (((Element) revisions.getParent()).getAttribute("redirect") != null && m.find()) {
followUp = Collections.singletonList(buildApiPropQueryUrl(requestUrl, m.group(1), "info", getDefaultParams("info", null),
Context.REDIRECT));
} else {
addLiteralTriple(subject, Namespaces.NS_RSS_CONTENT + "encoded", content, Namespaces.NS_XSD + "string", model, valueFactory);
}
}
return followUp;
}
代码示例来源:origin: sc.fiji/TrackMate_
final Element allTracksElement = root.getChild( TRACK_COLLECTION_ELEMENT_KEY_v12 );
if ( null == allTracksElement ) { return null; }
final List< Element > trackElements = allTracksElement.getChildren( TRACK_ELEMENT_KEY_v12 );
for ( final Element trackElement : trackElements )
try
trackID = trackElement.getAttribute( TRACK_ID_ATTRIBUTE_NAME_v12 ).getIntValue();
代码示例来源:origin: pwm-project/pwm
public CustomLinkValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey key )
throws PwmOperationalException
{
final List valueElements = settingElement.getChildren( "value" );
final List<CustomLinkConfiguration> values = new ArrayList<>();
for ( final Object loopValue : valueElements )
{
final Element loopValueElement = ( Element ) loopValue;
final String value = loopValueElement.getText();
if ( value != null && value.length() > 0 && loopValueElement.getAttribute( "locale" ) == null )
{
values.add( JsonUtil.deserialize( value, CustomLinkConfiguration.class ) );
}
}
return new CustomLinkValue( values );
}
};
代码示例来源:origin: rometools/rome
/** Deserialize a Atom workspace XML element into an object */
protected void parseWorkspaceElement(final Element element, final String baseURI) throws ProponoException {
final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT);
setTitle(titleElem.getText());
if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) {
setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue());
}
final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL);
for (final Element e : collections) {
addCollection(new ClientCollection(e, this, baseURI));
}
}
代码示例来源:origin: com.rometools/rome-modules
/** Use feed links and/or xml:base attribute to determine baseURI of feed */
private static URL findBaseURI(final Element root) {
URL baseURI = null;
final List<Element> linksList = root.getChildren("link", OS_NS);
if (linksList != null) {
for (final Element element : linksList) {
final Element link = element;
if (!root.equals(link.getParent())) {
break;
}
String href = link.getAttribute("href").getValue();
if (link.getAttribute("rel", OS_NS) == null || link.getAttribute("rel", OS_NS).getValue().equals("alternate")) {
href = resolveURI(null, link, href);
try {
baseURI = new URL(href);
break;
} catch (final MalformedURLException e) {
System.err.println("Base URI is malformed: " + href);
}
}
}
}
return baseURI;
}
}
代码示例来源:origin: com.rometools/rome-modules
if (element.getChild("treatAs", NS) == null) {
return null;
sle.setTreatAs(element.getChildText("treatAs", NS));
final Element listInfo = element.getChild("listinfo", NS);
ArrayList<Object> values = new ArrayList<Object>();
for (final Element ge : listInfo.getChildren("group", NS)) {
final Namespace ns = ge.getAttribute("ns") == null ? element.getNamespace() : Namespace.getNamespace(ge.getAttributeValue("ns"));
final String elementName = ge.getAttributeValue("element");
final String label = ge.getAttributeValue("label");
values = values.size() == 0 ? values : new ArrayList<Object>();
for (final Element se : listInfo.getChildren("sort", NS)) {
LOG.debug("Parse cf:sort {}{}", se.getAttributeValue("element"), se.getAttributeValue("data-type"));
final Namespace ns = se.getAttributeValue("ns") == null ? element.getNamespace() : Namespace.getNamespace(se.getAttributeValue("ns"));
insertValues(sle, element.getChildren());
代码示例来源:origin: fiji/TrackMate
/**
* Returns the version string stored in the file.
*/
public String getVersion()
{
return root.getChild( "trackfile" ).getAttribute( "version" ).getValue();
}
代码示例来源:origin: gocd/gocd
List<Element> encryptedPasswordElements = xpathExpression.evaluate(document);
for (Element element : encryptedPasswordElements) {
Attribute encryptedPassword = element.getAttribute(attributeName);
encryptedPassword.setValue(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), encryptedPassword.getValue()));
LOGGER.debug("Replaced encrypted value at {}", element.toString());
代码示例来源:origin: pwm-project/pwm
public FormValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey key )
throws PwmOperationalException
{
final boolean oldType = PwmSettingSyntax.LOCALIZED_STRING_ARRAY.toString().equals(
settingElement.getAttributeValue( "syntax" ) );
final List valueElements = settingElement.getChildren( "value" );
final List<FormConfiguration> values = new ArrayList<>();
for ( final Object loopValue : valueElements )
{
final Element loopValueElement = ( Element ) loopValue;
final String value = loopValueElement.getText();
if ( value != null && value.length() > 0 && loopValueElement.getAttribute( "locale" ) == null )
{
if ( oldType )
{
values.add( FormConfiguration.parseOldConfigString( value ) );
}
else
{
values.add( JsonUtil.deserialize( value, FormConfiguration.class ) );
}
}
}
final FormValue formValue = new FormValue( values );
formValue.needsXmlUpdate = oldType;
return formValue;
}
};
代码示例来源:origin: sc.fiji/TrackMate_
private static final double readTimeCutoffAttribute( final Element element )
{
double val = 0;
try
{
val = element.getChild( TRACKER_SETTINGS_TIME_CUTOFF_ELEMENT )
.getAttribute( TRACKER_SETTINGS_TIME_CUTOFF_ATTNAME_v12 ).getDoubleValue();
}
catch ( final DataConversionException e )
{}
return val;
}
代码示例来源:origin: apache/marmotta
protected List<String> parseRevision(URI resource, String requestUrl, Model model, ValueFactory valueFactory,
Element revisions, Context context) throws RepositoryException {
List<String> followUp = Collections.emptyList();
if (revisions == null) return followUp;
final Element rev = revisions.getChild("rev");
if (rev == null) return followUp;
final Resource subject = resource;
if (context == Context.META && "0".equals(rev.getAttributeValue("parentid"))) {
// This is the first revision, so we use the creation date
addLiteralTriple(subject, Namespaces.NS_DC_TERMS + "created", rev.getAttributeValue("timestamp"), Namespaces.NS_XSD + "dateTime", model,
valueFactory);
}
if (context == Context.CONTENT && rev.getValue() != null && rev.getValue().trim().length() > 0) {
final String content = rev.getValue().trim();
final Matcher m = REDIRECT_PATTERN.matcher(content);
if (((Element) revisions.getParent()).getAttribute("redirect") != null && m.find()) {
followUp = Collections.singletonList(buildApiPropQueryUrl(requestUrl, m.group(1), "info", getDefaultParams("info", null),
Context.REDIRECT));
} else {
addLiteralTriple(subject, Namespaces.NS_RSS_CONTENT + "encoded", content, Namespaces.NS_XSD + "string", model, valueFactory);
}
}
return followUp;
}
内容来源于网络,如有侵权,请联系作者删除!