handler = new ParserHandler(configuration); return handler.getValue();
/** * Returns the namespace mappings maintained by the parser. * <p> * Clients may register additional namespace mappings. This is useful when * an application whishes to provide some "default" namespace mappings. * </p> * <p> * Clients should register namespace mappings in the current "context", ie * do not call {@link NamespaceSupport#pushContext()}. Example: * <code> * Parser parser = new Parser( ... ); * parser.getNamespaces().declarePrefix( "foo", "http://www.foo.com" ); * ... * </code> * </p> * * @return The namespace support containing prefix to uri mappings. * @since 2.4 */ public NamespaceSupport getNamespaces() { return handler.getNamespaceSupport(); }
public ElementHandler createElementHandler(QName qName, Handler parent, ParserHandler parser) { SchemaIndex index = parser.getSchemaIndex(); //look up the element in the schema XSDElementDeclaration element = index.getElementDeclaration(qName); if (element != null) { return createElementHandler(element, parent, parser); } return null; }
ParserHandler ph = new ParserHandler(); ph.setOnParsingDoneListener (new ParserHandler.OnParsingDoneListener(){ public void onParsingDone(List dogList){ // do whatever you want to the doglist // at this point all parsing is done and dogList contains the data from xml } });
@Override public void element(XMLStreamReader xml, SldTransformContext context) throws XMLStreamException, IOException { try { if (delegate == null && "Filter".equals(xml.getLocalName())) { delegate = new ParserHandler(config(context)); delegate.startDocument(); } if (delegate != null) { delegate.startElement( xml.getNamespaceURI(), xml.getLocalName(), qname(xml.getName()), attributes(xml)); } } catch (SAXException e) { throw new XMLStreamException(e); } }
String uri = parser.getNamespaceSupport().getURI(prefix); if (!parser.isStrict()) { if (parser.getLogger().isLoggable(Level.FINE)) { parser.getLogger().fine("Parsing unknown attribute: " + attQName); parser.getLogger().warning("Could not find attribute declaration: " + attQName); ParseExecutor executor = new ParseExecutor(attribute, null, parent.getContext(), parser); parser.getBindingWalker() .walk(attribute.getAttributeDeclaration(), executor, parent.getContext()); ((BindingFactoryImpl) parser.getBindingFactory()).setContext(getContext());
if (!isStrict() && (locations == null)) { XSDSchemaLocator[] locators = findSchemaLocators(); XSDSchemaLocationResolver[] resolvers = findSchemaLocationResolvers(); if (!isStrict()) { logger.fine( "schema specified by parser configuration not found, supplementing..."); if (!isStrict()) { if (logger.isLoggable(Level.FINE)) { logger.fine("Could not find declaration for: " + qualifiedName if (!isStrict()) { String msg = "Could not find declaration for: " + qualifiedName + ". Performing lookup by ignoring namespace"; if (!isStrict()) { String msg = "Could not find declaration for: " + qualifiedName + ". Creating a mock element declaration and parsing anyways...";
if (!isStrict() && (locations == null)) { XSDSchemaLocator[] locators = findSchemaLocators(); XSDSchemaLocationResolver[] resolvers = findSchemaLocationResolvers(); if ( isValidating() ) { try { Schemas.validateImportsIncludes(location,locators,resolvers); if (isStrict()) { if (isStrict()) { if (!isStrict()) { logger.fine( "schema specified by parser configuration not found, supplementing..."); if (!isStrict()) { if (logger.isLoggable(Level.FINE)) { logger.fine("Could not find declaration for: " + qualifiedName if (!isStrict()) { String msg = "Could not find declaration for: " + qualifiedName + ". Performing lookup by ignoring namespace"; if (!isStrict()) { String msg = "Could not find declaration for: " + qualifiedName + ". Creating a mock element declaration and parsing anyways...";
private Handler getChildHandlerInternal(QName qName) { SchemaIndex index = parser.getSchemaIndex(); ElementHandler handler = parser.getHandlerFactory() .createElementHandler(element, this, parser); handler = parser.getHandlerFactory().createElementHandler(element, this, parser);
/** * Creats a new instance of the parser. * * @param configuration The parser configuration, bindings and context, * must never be <code>null</code>. * */ public Parser(Configuration configuration) { if (configuration == null) { throw new NullPointerException("configuration"); } handler = new ParserHandler(configuration); }
public void endElement(String uri, String localName, String qName) throws SAXException { //pop the last handler off of the stack ElementHandler handler = (ElementHandler) handlers.pop(); //create a qName object from the string QName qualifiedName = new QName(uri, localName); handler.endElement( qualifiedName ); endElementInternal(handler); //pop namespace context namespaces.popContext(); }
/** * Parses an instance documented defined by a sax input source. * <p> * The object returned from the parse is the object which has been bound to the root * element of the document. This method should only be called once for a single instance document. * </p> * * @return The object representation of the root element of the document. * * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ public Object parse(InputSource source) throws IOException, SAXException, ParserConfigurationException { parser = parser(); parser.setContentHandler(handler); parser.setErrorHandler(handler); parser.parse(source); return handler.getValue(); }
@Override public void endElement(XMLStreamReader xml, SldTransformContext context) throws XMLStreamException, IOException { if (delegate != null) { try { delegate.endElement( xml.getNamespaceURI(), xml.getLocalName(), qname(xml.getName())); } catch (SAXException e) { throw new XMLStreamException(e); } } if ("Filter".equals(xml.getLocalName())) { Filter filter = (Filter) delegate.getValue(); context.scalar(ECQL.toCQL(filter)).pop(); delegate = null; } }
public void endDocument() throws SAXException { super.endDocument(); buffer.close(); }
public void startDocument() throws SAXException { //perform teh configuration configure(config); //create the document handler + root context DocumentHandler docHandler = handlerFactory.createDocumentHandler(this); context = new DefaultPicoContainer(); context = config.setupContext(context); docHandler.setContext(context); // create the stack and add handler for document element handlers = new Stack(); handlers.push(docHandler); // get a logger from the context logger = (Logger) context.getComponentInstanceOfType(Logger.class); if (logger == null) { //create a default logger = Logger.getLogger("org.geotools.xml"); context.registerComponentInstance(logger); } //setup the namespace support namespaces = new NamespaceSupport(); context.registerComponentInstance(namespaces); context.registerComponentInstance(new NamespaceSupportWrapper(namespaces)); //binding factory support bindingFactory = new BindingFactoryImpl(bindingLoader); context.registerComponentInstance(bindingFactory); //binding walker support context.registerComponentInstance(new BindingWalkerFactoryImpl(bindingLoader, context)); }
String uri = parser.getNamespaceSupport().getURI(prefix); if (!parser.isStrict()) { if (parser.getLogger().isLoggable(Level.FINE)) { parser.getLogger().fine("Parsing unknown attribute: " + attQName); parser.getLogger().warning("Could not find attribute declaration: " + attQName); ParseExecutor executor = new ParseExecutor(attribute, null, parent.getContext(), parser); parser.getBindingWalker() .walk(attribute.getAttributeDeclaration(), executor, parent.getContext()); ((BindingFactoryImpl) parser.getBindingFactory()).setContext(getContext());
if ( !isStrict() && locations == null ) { XSDSchemaLocator[] locators = findSchemaLocators(); XSDSchemaLocationResolver[] resolvers = findSchemaLocationResolvers(); if ( !isStrict() ) { logger.fine("schema specified by parser configuration not found, supplementing..."); if (!isStrict() ) { String msg = "Could not find declaration for: " + qualifiedName + ". Checking if containing type declares a single particle."; if ( !isStrict() ) { String msg = "Could not find declaration for: " + qualifiedName + ". Performing lookup by ignoring namespace"; if (!isStrict() ) { String msg = "Could not find declaration for: " + qualifiedName + ". Creating a mock element declaration and parsing anyways...";
private Handler getChildHandlerInternal(QName qName) { SchemaIndex index = parser.getSchemaIndex(); ElementHandler handler = parser.getHandlerFactory() .createElementHandler(element, this, parser); handler = parser.getHandlerFactory().createElementHandler(element, this, parser);
/** * Creats a new instance of the parser. * * @param configuration The parser configuration, bindings and context, * must never be <code>null</code>. * */ public Parser(Configuration configuration) { if ( configuration == null ) { throw new NullPointerException( "configuration" ); } handler = new ParserHandler(configuration); }
public void endElement(String uri, String localName, String qName) throws SAXException { //pop the last handler off of the stack ElementHandler handler = (ElementHandler) handlers.pop(); //create a qName object from the string QName qualifiedName = new QName(uri, localName); handler.endElement(qualifiedName); endElementInternal(handler); //pop namespace context namespaces.popContext(); }