@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)); }
@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)); }
/** * 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; } } } }
/** * 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); } }
/** * 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; } }
/** * 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; } }
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; } }
/** * 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)); } }
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 ); } }
/** SAX DocumentHandler API. */ public void startElement(String name, AttributeList atts) throws SAXException { allowXMLCatalogPI = false; if (documentHandler != null) { documentHandler.startElement(name,atts); } }
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 (">"); }
@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()); } }
@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); } }
/** * Sets the attributes for the wrapped element. * * @param attributes List of attributes defined in the XML for this * element. May be <code>null</code>. * @deprecated since 1.6.x. */ @Deprecated public synchronized void setAttributes(AttributeList attributes) { this.attributes = new AttributeListImpl(attributes); for (int i = 0; i < attributes.getLength(); i++) { setAttribute(attributes.getName(i), attributes.getValue(i)); } }
/** * Start a new DataTypeHandler if element is known to be a * data-type and a TaskHandler otherwise. * * <p>Factored out of TargetHandler.</p> * * @since Ant 1.6 */ private static void handleElement(ProjectHelperImpl helperImpl, DocumentHandler parent, Target target, String elementName, AttributeList attrs) throws SAXParseException { if ("description".equals(elementName)) { // created for side effect new DescriptionHandler(helperImpl, parent); //NOSONAR } else if (helperImpl.project.getDataTypeDefinitions().get(elementName) != null) { new DataTypeHandler(helperImpl, parent, target).init(elementName, attrs); } else { new TaskHandler(helperImpl, parent, target, null, target).init(elementName, attrs); } }