本文整理了Java中org.jdom2.Element.setAttribute()
方法的一些代码示例,展示了Element.setAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.setAttribute()
方法的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
方法名:setAttribute
[英]This sets an attribute value for this element. Any existing attribute with the same name and namespace URI is removed.
[中]这将为此元素设置属性值。将删除具有相同名称和命名空间URI的任何现有属性。
代码示例来源:origin: gocd/gocd
public Element ccTrayXmlElement(String fullContextPath) {
Element element = new Element("Project");
element.setAttribute("name", name);
element.setAttribute("activity", activity);
element.setAttribute("lastBuildStatus", lastBuildStatus);
element.setAttribute("lastBuildLabel", lastBuildLabel);
element.setAttribute("lastBuildTime", DateUtils.formatIso8601ForCCTray(lastBuildTime));
element.setAttribute("webUrl", fullContextPath + "/" + webUrl);
if (!breakers.isEmpty()) {
addBreakers(element);
}
return element;
}
代码示例来源:origin: gocd/gocd
private void addBreakers(Element element) {
Element messages = new Element("messages");
Element message = new Element("message");
String breakerNames = StringUtils.join(breakers, ", ");
message.setAttribute("text", breakerNames);
message.setAttribute("kind", "Breakers");
messages.addContent(message);
element.addContent(messages);
}
代码示例来源: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: geotools/geotools
private Element createIFD() {
Element ifd = new Element(GeoTiffConstants.GEOTIFF_IFD_TAG);
ifd.setAttribute(
GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME,
BaselineTIFFTagSet.class.getName() + "," + GeoTIFFTagSet.class.getName());
if (modelPixelScale.isSet()) {
ifd.addContent(createModelPixelScaleElement());
}
if (isModelTiePointsSet()) {
ifd.addContent(createModelTiePointsElement());
} else if (isModelTransformationSet()) {
ifd.addContent(createModelTransformationElement());
}
if (getNumGeoKeyEntries() > 1) {
ifd.addContent(createGeoKeyDirectoryElement());
}
if (numGeoTiffDoubleParams > 0) {
ifd.addContent(createGeoDoubleParamsElement());
}
if (numGeoTiffAsciiParams > 0) {
ifd.addContent(createGeoAsciiParamsElement());
}
if (isNodataSet) {
ifd.addContent(createNoDataElement());
}
if (isMetadataSet) {
createMetadataElement(ifd);
}
return ifd;
}
代码示例来源:origin: gocd/gocd
private Document createEmptyCruiseConfigDocument() {
Element root = new Element("cruise");
Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS);
root.addNamespaceDeclaration(xsiNamespace);
registry.registerNamespacesInto(root);
root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace);
String xsds = registry.xsds();
if (!xsds.isEmpty()) {
root.setAttribute("schemaLocation", xsds, xsiNamespace);
}
root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION));
return new Document(root);
}
代码示例来源:origin: org.jdom/jdom
/**
* Read an Element off the ObjectInputStream.
*
* @see #writeObject(ObjectOutputStream)
* @param in where to read the Element from.
* @throws IOException if there is a reading problem.
* @throws ClassNotFoundException when a class cannot be found
*/
private void readObject(final ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
content = new ContentList(this);
int nss = in.readInt();
while (--nss >= 0) {
addNamespaceDeclaration((Namespace)in.readObject());
}
int ats = in.readInt();
while (--ats >= 0) {
setAttribute((Attribute)in.readObject());
}
int cs = in.readInt();
while (--cs >= 0) {
addContent((Content)in.readObject());
}
}
代码示例来源:origin: isisaddons/isis-app-todoapp
private static Element addTable(final Element body, final String id) {
final Element table = new Element("table");
body.addContent(table);
table.setAttribute("id", id);
return table;
}
代码示例来源:origin: gocd/gocd
private static Element elementFor(Class<?> aClass, ConfigCache configCache) {
final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class);
if (attributeAwareConfigTag != null) {
final Element element = new Element(attributeAwareConfigTag.value(), namespaceFor(attributeAwareConfigTag));
element.setAttribute(attributeAwareConfigTag.attribute(), attributeAwareConfigTag.attributeValue());
return element;
}
ConfigTag configTag = annotationFor(aClass, ConfigTag.class);
if (configTag == null)
throw bomb(format("Cannot get config tag for {0}", aClass));
return new Element(configTag.value(), namespaceFor(configTag));
}
代码示例来源:origin: geotools/geotools
public void assignTo(Element element) {
if (!element.getName().equals(GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME)) {
throw new IllegalArgumentException(
"root not found: " + GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME);
}
final Element ifd1 = element.getChild(GeoTiffConstants.GEOTIFF_IFD_TAG);
if (ifd1 == null) {
throw new IllegalArgumentException(
"Unable to find child " + GeoTiffConstants.GEOTIFF_IFD_TAG);
}
final Element ifd2 = createIFD();
ifd1.setAttribute(
GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME,
ifd2.getAttributeValue(GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME));
final Element[] childElems = (Element[]) ifd2.getChildren().toArray(new Element[0]);
for (int i = 0; i < childElems.length; i++) {
final Element child = childElems[i];
ifd2.removeContent(child);
ifd1.addContent(child);
}
}
代码示例来源:origin: edu.ucar/cdm
private void addCoord(Element tableElem, String name, String kind) {
if (name != null) {
Element elem = new Element("coordinate").setAttribute("kind", kind);
elem.addContent(name);
tableElem.addContent(elem);
}
}
代码示例来源:origin: gocd/gocd
@Test(expected = RuntimeException.class) public void shouldValidateAndConvertOnlyIfAppropriate()
throws NoSuchFieldException {
final Foo object = new Foo();
final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null);
final Element element = new Element("foo");
element.setAttribute("number", "anything");
field.setValueIfNotNull(element, object);
}
代码示例来源:origin: Unidata/thredds
private void addCoord(Element tableElem, String name, String kind) {
if (name != null) {
Element elem = new Element("coordinate").setAttribute("kind", kind);
elem.addContent(name);
tableElem.addContent(elem);
}
}
代码示例来源:origin: gocd/gocd
@Test public void shouldConvertFromXmlToJavaObjectCorrectly() throws Exception {
final Foo object = new Foo();
final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null);
final Element element = new Element("foo");
element.setAttribute("number", "100");
field.setValueIfNotNull(element, object);
assertThat(object.number, is(100L));
}
代码示例来源:origin: edu.ucar/netcdf
private void addCoord(Element tableElem, String name, String kind) {
if (name != null) {
Element elem = new Element("coordinate").setAttribute("kind", kind);
elem.addContent(name);
tableElem.addContent(elem);
}
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldContinueParsingWhenConfigClassHasValidAttributeAwareConfigTagAnnotation() {
final Element element = new Element("example");
element.setAttribute("type", "example-type");
when(configCache.getFieldCache()).thenReturn(new ClassAttributeCache.FieldCache());
final GoConfigClassLoader<ConfigWithAttributeAwareConfigTagAnnotation> loader = GoConfigClassLoader.classParser(element, ConfigWithAttributeAwareConfigTagAnnotation.class, configCache, goCipher, registry, referenceElements);
final ConfigWithAttributeAwareConfigTagAnnotation configWithConfigTagAnnotation = loader.parse();
assertNotNull(configWithConfigTagAnnotation);
}
代码示例来源:origin: jpos/jPOS
protected void addAttr (Element e, String name, Object obj, String type) {
String value = obj == null ? "null" : obj.toString();
Element attr = new Element ("attr");
attr.setAttribute ("name", name);
if (type != null)
attr.setAttribute ("type", type);
attr.setText (value);
e.addContent (attr);
}
protected Iterator getAttrs () {
代码示例来源:origin: gocd/gocd
@Test public void shouldConvertFileCorrectly() throws Exception {
final Foo object = new Foo();
final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("directory"), object, configCache, null);
final Element element = new Element("foo");
element.setAttribute("directory", "foo" + FileUtil.fileseparator() + "dir");
field.setValueIfNotNull(element, object);
assertThat(object.directory.getPath(), is("foo" + FileUtil.fileseparator() + "dir"));
}
代码示例来源:origin: edu.ucar/netcdf
private Element writeJoinParentIndex(JoinParentIndex join) {
Element joinElem = new Element("join");
joinElem.setAttribute("class", join.getClass().toString());
if (join.parentStructure != null)
joinElem.addContent( new Element("parentStructure").setAttribute("name", join.parentStructure.getFullName()));
if (join.parentIndex != null)
joinElem.addContent( new Element("parentIndex").setAttribute("name", join.parentIndex));
return joinElem;
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldErrorOutWhenConfigClassHasAttributeAwareConfigTagAnnotationButAttributeValueIsNotMatching() {
final Element element = new Element("example");
element.setAttribute("type", "foo-bar");
when(configCache.getFieldCache()).thenReturn(new ClassAttributeCache.FieldCache());
final GoConfigClassLoader<ConfigWithAttributeAwareConfigTagAnnotation> loader = GoConfigClassLoader.classParser(element, ConfigWithAttributeAwareConfigTagAnnotation.class, configCache, goCipher, registry, referenceElements);
thrown.expect(RuntimeException.class);
thrown.expectMessage("Unable to determine type to generate. Type: com.thoughtworks.go.config.parser.ConfigWithAttributeAwareConfigTagAnnotation Element: \n" +
"\t<example type=\"foo-bar\" />");
loader.parse();
}
代码示例来源:origin: edu.ucar/cdm
private Element writeJoinParentIndex(JoinParentIndex join) {
Element joinElem = new Element("join");
joinElem.setAttribute("class", join.getClass().toString());
if (join.parentStructure != null)
joinElem.addContent( new Element("parentStructure").setAttribute("name", join.parentStructure.getFullName()));
if (join.parentIndex != null)
joinElem.addContent( new Element("parentIndex").setAttribute("name", join.parentIndex));
return joinElem;
}
内容来源于网络,如有侵权,请联系作者删除!