本文整理汇总了Java中org.jdom.Attribute.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.setValue方法的具体用法?Java Attribute.setValue怎么用?Java Attribute.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.Attribute
的用法示例。
在下文中一共展示了Attribute.setValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceVariablesAttributes
import org.jdom.Attribute; //导入方法依赖的package包/类
/**
* Scan all attributes of a given Element and replace variable name by their
* real value
*
* @param elt
* the Element to scan
* @param p
* the variable Pattern
* @param vars
* the variables values
*/
private static void replaceVariablesAttributes(Element elt, Pattern p, HashMap<String, String> vars) {
@SuppressWarnings("unchecked")
Iterator itAttr = elt.getAttributes().iterator();
while (itAttr.hasNext()) {
Attribute attr = (Attribute) itAttr.next();
String values = attr.getValue();
Matcher m = p.matcher(values);
while (m.find()) {
String var = m.group(1);
String resolve = vars.get(var);
values = values.replaceAll("\\x24\\x7B" + var + "\\x7D", // ${*}
(resolve.split(",").length == 1) ? resolve : ("#{" + resolve + "}"));
attr.setValue(values);
}
}
}
示例2: substitute
import org.jdom.Attribute; //导入方法依赖的package包/类
public final void substitute(@NotNull Element e, boolean caseSensitive, final boolean recursively,
@Nullable PathMacroFilter filter) {
List content = e.getContent();
//noinspection ForLoopReplaceableByForEach
for (int i = 0, contentSize = content.size(); i < contentSize; i++) {
Object child = content.get(i);
if (child instanceof Element) {
Element element = (Element)child;
substitute(element, caseSensitive, recursively, filter);
}
else if (child instanceof Text) {
Text t = (Text)child;
if (filter == null || !filter.skipPathMacros(t)) {
t.setText((recursively || (filter != null && filter.recursePathMacros(t)))
? substituteRecursively(t.getText(), caseSensitive)
: substitute(t.getText(), caseSensitive));
}
}
else if (!(child instanceof Comment)) {
LOG.error("Wrong content: " + child.getClass());
}
}
List attributes = e.getAttributes();
//noinspection ForLoopReplaceableByForEach
for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) {
Object attribute1 = attributes.get(i);
Attribute attribute = (Attribute)attribute1;
if (filter == null || !filter.skipPathMacros(attribute)) {
final String value = (recursively || (filter != null && filter.recursePathMacros(attribute)))
? substituteRecursively(attribute.getValue(), caseSensitive)
: substitute(attribute.getValue(), caseSensitive);
attribute.setValue(value);
}
}
}
示例3: conv
import org.jdom.Attribute; //导入方法依赖的package包/类
/**
* Converts String into java primitive type
* @param type <code>Class</code> target type
* @param attr <code>Attribute</code> value field needs to provide convertable String
* @return <code>Object</code> primitive wrapped into wrapper object
*/
public static Object conv( final Class type, final Attribute attr, final Localizer localizer ) throws Exception {
Attribute a = (Attribute) attr.clone();
Object obj = null;
if ( Parser.LOCALIZED_ATTRIBUTES.contains( a.getName().toLowerCase() ))
if (a.getAttributeType() == Attribute.CDATA_TYPE )
a.setValue( localizer.getString( a.getValue() ));
try {
if (boolean.class.equals( type )) {
obj = new Boolean( a.getBooleanValue() );
} else if (int.class.equals( type )) {
obj = new Integer( a.getIntValue() );
} else if (long.class.equals( type )) {
obj = new Long( a.getLongValue() );
} else if (float.class.equals( type )) {
obj = new Float( a.getFloatValue() );
} else if (double.class.equals( type )) {
obj = new Double( a.getDoubleValue() );
}
} catch (DataConversionException e) {
} finally {
if (obj==null) {
try {
String s = a.getValue();
int k = s.indexOf( '.' ) - 1;
Class pp = (Class) dictionaries.get( s.substring( 0, s.indexOf( '.' ) ) );
obj = pp.getField( s.substring( k + 2 ) ).get( pp );
} catch (Exception ex) {
//
// Try to find the given value as a Constant in SwingConstants
//
obj = PrimitiveConverter.class.getField( a.getValue() ).get( PrimitiveConverter.class );
}
}
}
return obj;
}
示例4: replaceAll
import org.jdom.Attribute; //导入方法依赖的package包/类
/**
* Replace all occurences of old by value in all attributes of elt
*
* @param elt
* the Element to parse
* @param old
* the old value to replace
* @param value
* the new value
*/
public static void replaceAll(Element elt, String old, String value) {
@SuppressWarnings("unchecked")
Iterator itAttr = elt.getAttributes().iterator();
while (itAttr.hasNext()) {
Attribute attr = (Attribute) itAttr.next();
attr.setValue(attr.getValue().replaceAll(old, value));
}
}