本文整理汇总了Java中org.xml.sax.ext.Attributes2Impl.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes2Impl.addAttribute方法的具体用法?Java Attributes2Impl.addAttribute怎么用?Java Attributes2Impl.addAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.ext.Attributes2Impl
的用法示例。
在下文中一共展示了Attributes2Impl.addAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test03
import org.xml.sax.ext.Attributes2Impl; //导入方法依赖的package包/类
@Test
public void test03() {
System.out.println("===in test03()===");
Attributes2Impl impl1 = new Attributes2Impl();
impl1.addAttribute("http://www.cars.com/xml", "attr1", "Qname1", "type", "value");
impl1.addAttribute("http://www.cars.com/xml", "attr2", "Qname2", "type", "value");
impl1.addAttribute("http://www.cars.com/xml", "attr3", "Qname3", "type", "value");
Attributes2Impl impl2 = new Attributes2Impl(impl1);
Attributes2Impl impl3 = new Attributes2Impl();
impl3.setAttributes(impl1);
Assert.assertTrue(impl1.getQName(0).equals(impl2.getQName(0)));
Assert.assertTrue(impl1.getQName(0).equals(impl3.getQName(0)));
Assert.assertTrue(impl1.getQName(1).equals(impl2.getQName(1)));
Assert.assertTrue(impl1.getQName(1).equals(impl3.getQName(1)));
Assert.assertTrue(impl1.getQName(2).equals(impl2.getQName(2)));
Assert.assertTrue(impl1.getQName(2).equals(impl3.getQName(2)));
}
示例2: addBaseAttributes
import org.xml.sax.ext.Attributes2Impl; //导入方法依赖的package包/类
void addBaseAttributes(MCRFSNODES node, Attributes2Impl atts) {
atts.clear();
atts.addAttribute(NS_URI, ATT_SIZE, ATT_SIZE, CDATA, Long.toString(node.getSize()));
atts.addAttribute(NS_URI, ATT_MD5, ATT_MD5, CDATA, node.getMd5());
atts.addAttribute(NS_URI, ATT_STORAGEID, ATT_STORAGEID, CDATA, node.getStorageid());
atts.addAttribute(NS_URI, ATT_OWNER, ATT_OWNER, CDATA, node.getOwner());
atts.addAttribute(NS_URI, ATT_NAME, ATT_NAME, CDATA, node.getName());
atts.addAttribute(NS_URI, ATT_IFS_ID, ATT_IFS_ID, CDATA, node.getId());
}
示例3: checkNode
import org.xml.sax.ext.Attributes2Impl; //导入方法依赖的package包/类
@Override
public boolean checkNode(MCRFSNODES node, File localFile, Attributes2Impl atts) {
if (!super.checkNode(node, localFile, atts)) {
atts.addAttribute(MCRIFSCommands.NS_URI, super.getName(), super.getName(), MCRIFSCommands.CDATA,
"true");
return false;
}
addBaseAttributes(node, atts);
if (localFile.length() != node.getSize()) {
LOGGER.warn("File size does not match for file: {}", localFile);
atts.addAttribute(MCRIFSCommands.NS_URI, "actualSize", "actualSize", MCRIFSCommands.CDATA,
Long.toString(localFile.length()));
return false;
}
//we can check MD5Sum
FileInputStream fileInputStream;
try {
fileInputStream = new FileInputStream(localFile);
} catch (FileNotFoundException e1) {
//should not happen as we check it before
LOGGER.warn(e1);
return false;
}
String md5Sum;
try {
md5Sum = MCRUtils.getMD5Sum(fileInputStream);
} catch (IOException e) {
LOGGER.error(e);
return false;
}
if (md5Sum.equals(node.getMd5())) {
return true;
}
LOGGER.warn("MD5 sum does not match for file: {}", localFile);
atts.addAttribute(MCRIFSCommands.NS_URI, "actualMD5", "actualMD5", MCRIFSCommands.CDATA, md5Sum);
return false;
}
示例4: testAddAttribute
import org.xml.sax.ext.Attributes2Impl; //导入方法依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "addAttribute",
args = { String.class, String.class, String.class, String.class,
String.class }
)
public void testAddAttribute() {
Attributes2Impl attrs = new Attributes2Impl();
// Ordinary case
attrs.addAttribute("http://yet.another.uri", "doe", "john:doe",
"string", "abc");
assertEquals(1, attrs.getLength());
assertEquals("http://yet.another.uri", attrs.getURI(0));
assertEquals("doe", attrs.getLocalName(0));
assertEquals("john:doe", attrs.getQName(0));
assertEquals("string", attrs.getType(0));
assertEquals("abc", attrs.getValue(0));
assertEquals(true, attrs.isDeclared(0));
assertEquals(true, attrs.isSpecified(0));
// CDATA case
attrs.addAttribute("http://yet.another.uri", "doe", "jane:doe",
"CDATA", "abc");
assertEquals(2, attrs.getLength());
assertEquals("http://yet.another.uri", attrs.getURI(1));
assertEquals("doe", attrs.getLocalName(1));
assertEquals("jane:doe", attrs.getQName(1));
assertEquals("CDATA", attrs.getType(1));
assertEquals("abc", attrs.getValue(1));
assertEquals(false, attrs.isDeclared(1));
assertEquals(true, attrs.isSpecified(1));
}
示例5: testSetAttributes
import org.xml.sax.ext.Attributes2Impl; //导入方法依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "setAttributes",
args = { Attributes.class }
)
public void testSetAttributes() {
// Ordinary case with Attributes2Impl
Attributes2Impl attrs = new Attributes2Impl();
attrs.addAttribute("", "", "john", "string", "doe");
attrs.setAttributes(empty);
assertEquals(0, attrs.getLength());
attrs.setAttributes(multi);
for (int i = 0; i < multi.getLength(); i++) {
assertEquals(multi.getURI(i), attrs.getURI(i));
assertEquals(multi.getLocalName(i), attrs.getLocalName(i));
assertEquals(multi.getQName(i), attrs.getQName(i));
assertEquals(multi.getType(i), attrs.getType(i));
assertEquals(multi.getValue(i), attrs.getValue(i));
assertEquals(multi.isDeclared(i), attrs.isDeclared(i));
assertEquals(multi.isSpecified(i), attrs.isSpecified(i));
}
attrs.setAttributes(empty);
assertEquals(0, attrs.getLength());
// Ordinary case with AttributesImpl
attrs.setAttributes(new AttributesImpl(multi));
assertEquals(multi.getLength(), attrs.getLength());
for (int i = 0; i < multi.getLength(); i++) {
assertEquals(multi.getURI(i), attrs.getURI(i));
assertEquals(multi.getLocalName(i), attrs.getLocalName(i));
assertEquals(multi.getQName(i), attrs.getQName(i));
assertEquals(multi.getType(i), attrs.getType(i));
assertEquals(multi.getValue(i), attrs.getValue(i));
assertEquals(true, attrs.isDeclared(i));
assertEquals(true, attrs.isSpecified(i));
}
// Special case with CDATA
attrs.setAttributes(new AttributesImpl(cdata));
assertEquals(1, attrs.getLength());
assertEquals(false, attrs.isDeclared(0));
assertEquals(true, attrs.isSpecified(0));
// null case
try {
attrs.setAttributes(null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected
}
}