本文整理汇总了Java中org.xml.sax.AttributeList类的典型用法代码示例。如果您正苦于以下问题:Java AttributeList类的具体用法?Java AttributeList怎么用?Java AttributeList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeList类属于org.xml.sax包,在下文中一共展示了AttributeList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStartElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "startElement",
args = { String.class, AttributeList.class }
)
public void testStartElement() {
AttributeListImpl atts = new AttributeListImpl();
atts.addAttribute("john:doe", "int", "42");
try {
adapter.startDocument();
adapter.startElement("foo:bar", atts);
} catch (SAXException e) {
throw new RuntimeException("Unexpected exception", e);
}
assertEquals("startElement", logger.getMethod());
assertEquals("", logger.getArgs()[0]);
assertEquals("", logger.getArgs()[1]);
assertEquals("foo:bar", logger.getArgs()[2]);
assertEquals("john:doe", ((Attributes)logger.getArgs()[3]).getQName(0));
}
示例2: testStartElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "startElement",
args = { String.class, String.class, String.class, Attributes.class }
)
public void testStartElement() {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("http://some.other.uri", "gabba", "gabba:hey",
"int", "42");
try {
adapter.startElement("http://some.uri", "bar", "foo:bar", atts);
} catch (SAXException e) {
throw new RuntimeException("Unexpected exception", e);
}
assertEquals(logger.size(), 1);
assertEquals("startElement", logger.getMethod());
assertEquals("foo:bar", logger.getArgs()[0]);
assertEquals("gabba:hey",
((AttributeList)logger.getArgs()[1]).getName(0));
}
示例3: configure
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* Configures an object using an introspection handler.
*
* @param target The target object to be configured.
* Must not be <code>null</code>.
* @param attrs A list of attributes to configure within the target.
* Must not be <code>null</code>.
* @param project The project containing the target.
* Must not be <code>null</code>.
*
* @deprecated since 1.6.x.
* Use IntrospectionHelper for each property.
*
* @exception BuildException if any of the attributes can't be handled by
* the target
*/
public static void configure(Object target, AttributeList attrs,
Project project) throws BuildException {
if (target instanceof TypeAdapter) {
target = ((TypeAdapter) target).getProxy();
}
IntrospectionHelper ih = IntrospectionHelper.getHelper(project, target.getClass());
for (int i = 0, length = attrs.getLength(); i < length; i++) {
// reflect these into the target
String value = replaceProperties(project, attrs.getValue(i), project.getProperties());
try {
ih.setAttribute(project, target, attrs.getName(i).toLowerCase(Locale.ENGLISH), value);
} catch (BuildException be) {
// id attribute must be set externally
if (!attrs.getName(i).equals("id")) {
throw be;
}
}
}
}
示例4: init
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* Initialisation routine called after handler creation
* with the element name and attributes. This configures
* the element with its attributes and sets it up with
* its parent container (if any). Nested elements are then
* added later as the parser encounters them.
*
* @param propType Name of the element which caused this handler
* to be created. Must not be <code>null</code>.
*
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
* @exception SAXParseException in case of error, such as a
* BuildException being thrown during configuration.
*/
public void init(String propType, AttributeList attrs) throws SAXParseException {
Class<?> parentClass = parent.getClass();
IntrospectionHelper ih = IntrospectionHelper.getHelper(helperImpl.project, parentClass);
try {
String elementName = propType.toLowerCase(Locale.ENGLISH);
if (parent instanceof UnknownElement) {
UnknownElement uc = new UnknownElement(elementName);
uc.setProject(helperImpl.project);
((UnknownElement) parent).addChild(uc);
child = uc;
} else {
child = ih.createElement(helperImpl.project, parent, elementName);
}
helperImpl.configureId(child, attrs);
childWrapper = new RuntimeConfigurable(child, propType);
childWrapper.setAttributes(attrs);
parentWrapper.addChild(childWrapper);
} catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
}
}
示例5: startElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* Receive notification that the start of an XML element has been found.
*
* @param name String name of the element found.
* @param atts AttributeList of the attributes included with the element
* (if any).
* @throws SAXException If the parser cannot process the document.
*/
@Override
public void startElement(String name, AttributeList atts)
throws SAXException {
/*
* I need to "push" the element onto the String (currentLoc) which
* always represents the current location in the XML document.
*/
currentLoc += "\\" + name;
/* A new element has started, so reset the text being captured */
currentText = "";
if ("\\ejb-jar".equals(currentLoc)) {
iasDescriptor = false;
} else if ("\\ias-ejb-jar".equals(currentLoc)) {
iasDescriptor = true;
}
if (("session".equals(name)) || ("entity".equals(name))) {
ejbType = name;
}
}
示例6: startElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* SAX parser call-back method that is invoked when a new element is entered
* into. Used to store the context (attribute name) in the currentAttribute
* instance variable.
* @param name The name of the element being entered.
* @param attrs Attributes associated to the element.
* @throws SAXException on error
*/
@Override
public void startElement(String name, AttributeList attrs)
throws SAXException {
this.currentElement = name;
currentText = "";
if (EJB_REF.equals(name) || EJB_LOCAL_REF.equals(name)) {
inEJBRef = true;
} else if (parseState == STATE_LOOKING_EJBJAR && EJB_JAR.equals(name)) {
parseState = STATE_IN_EJBJAR;
} else if (parseState == STATE_IN_EJBJAR && ENTERPRISE_BEANS.equals(name)) {
parseState = STATE_IN_BEANS;
} else if (parseState == STATE_IN_BEANS && SESSION_BEAN.equals(name)) {
parseState = STATE_IN_SESSION;
} else if (parseState == STATE_IN_BEANS && ENTITY_BEAN.equals(name)) {
parseState = STATE_IN_ENTITY;
} else if (parseState == STATE_IN_BEANS && MESSAGE_BEAN.equals(name)) {
parseState = STATE_IN_MESSAGE;
}
}
示例7: startElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
public void startElement (String name, AttributeList atts)
{
currentOpeningTag = name;
// Start of a news item
if (currentOpeningTag.equals("REUTERS")) {
currentNewsItem = new ParsedNewsItem();
// Set the ID of the current news item
currentNewsItem.setId(atts.getValue("NEWID"));
}
// Start of a block of topics
if (currentOpeningTag.equals("TOPICS")) {
parsingTopics = true;
}
// Start of the text content of a news item
if (currentOpeningTag.equals("TEXT")) {
parsingText = true;
}
}
示例8: setAttributeList
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* Set the attribute list, discarding previous contents.
*
* <p>This method allows an application writer to reuse an
* attribute list easily.</p>
*
* @param atts The attribute list to copy.
*/
public void setAttributeList (AttributeList atts)
{
int count = atts.getLength();
clear();
for (int i = 0; i < count; i++) {
addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i));
}
}
示例9: startElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
boolean preserveSpace;
ElementState state;
try {
state = getElementState();
if ( isDocumentState() ) {
// If this is the root element handle it differently.
// If the first root element in the document, serialize
// the document's DOCTYPE. Space preserving defaults
// to that of the output format.
if ( ! _started )
startDocument( tagName );
}
// For any other element, if first in parent, then
// use the parnet's space preserving.
preserveSpace = state.preserveSpace;
// Do not change the current element state yet.
// This only happens in endElement().
// Ignore all other attributes of the element, only printing
// its contents.
// Now it's time to enter a new element state
// with the tag name and space preserving.
// We still do not change the curent element state.
state = enterElementState( null, null, tagName, preserveSpace );
} catch ( IOException except ) {
throw new SAXException( except );
}
}
示例10: startElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
/** SAX DocumentHandler API. */
public void startElement(String name, AttributeList atts)
throws SAXException {
allowXMLCatalogPI = false;
if (documentHandler != null) {
documentHandler.startElement(name,atts);
}
}
示例11: setAttributeList
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* Set the attribute list, discarding previous contents.
*
* <p>This method allows an application writer to reuse an
* attribute list easily.</p>
*
* @param atts The attribute list to copy.
*/
public void setAttributeList (AttributeList atts)
{
int count = atts.getLength();
clear();
for (int i = 0; i < count; i++) {
addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i));
}
}
示例12: setAttributeList
import org.xml.sax.AttributeList; //导入依赖的package包/类
/**
* Set the attribute list, discarding previous contents.
*
* <p>This method allows an application writer to reuse an
* attribute list easily.</p>
*
* @param atts The attribute list to copy.
*/
public void setAttributeList (AttributeList atts)
{
int count = atts.getLength();
clear();
for (int i = 0; i < count; i++) {
addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i));
}
}
示例13: startElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
public void startElement (String tag, AttributeList attrs)
throws SAXException
{
// emit ("<"); emit (tag);
// if (attrs != null) {
// for (int i = 0; i < attrs.getLength (); i++) {
// emit (" "); emit (attrs.getName (i)); emit ("\"");
// XXX this doesn't quote '&', '<', and '"' in the
// way it should ... needs to scan the value and
// emit '&', '<', and '"' respectively
// emit (attrs.getValue (i)); emit ("\"");
// }
// }
// emit (">");
}
示例14: testSetAttributeList
import org.xml.sax.AttributeList; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "setAttributeList",
args = { AttributeList.class }
)
public void testSetAttributeList() {
// Ordinary cases
AttributeListImpl attrs = new AttributeListImpl();
attrs.addAttribute("doe", "boolean", "false");
attrs.setAttributeList(empty);
assertEquals(0, attrs.getLength());
attrs.setAttributeList(multi);
assertEquals(multi.getLength(), attrs.getLength());
for (int i = 0; i < multi.getLength(); i++) {
assertEquals(multi.getName(i), attrs.getName(i));
assertEquals(multi.getType(i), attrs.getType(i));
assertEquals(multi.getValue(i), attrs.getValue(i));
}
// null case
try {
attrs.setAttributeList(null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected, must still have old elements
assertEquals(3, attrs.getLength());
}
}
示例15: testStartElement
import org.xml.sax.AttributeList; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "startElement",
args = { String.class, AttributeList.class }
)
public void testStartElement() {
try {
h.startElement("name", new AttributeListImpl());
} catch (SAXException e) {
throw new RuntimeException(e);
}
}