001 /* $Id: GenericParser.java 992077 2010-09-02 19:45:22Z simonetripodi $ 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 020 package org.apache.commons.digester.parser; 021 022 import java.util.Properties; 023 024 import javax.xml.parsers.ParserConfigurationException; 025 import javax.xml.parsers.SAXParser; 026 import javax.xml.parsers.SAXParserFactory; 027 028 import org.apache.commons.logging.Log; 029 import org.apache.commons.logging.LogFactory; 030 import org.xml.sax.SAXException; 031 import org.xml.sax.SAXNotRecognizedException; 032 033 /** 034 * Create a <code>SAXParser</code> configured to support XML Schema and DTD. 035 * 036 * @since 1.6 037 * @deprecated Create an XMLParser instance yourself, configure validation 038 * appropriately, and pass it as a parameter to the 039 * {@link org.apache.commons.digester.Digester} constructor, or use 040 * {@link org.apache.commons.digester.Digester#setXMLSchema(javax.xml.validation.Schema)} for validation. 041 */ 042 043 @Deprecated 044 public class GenericParser{ 045 046 /** 047 * The Log to which all SAX event related logging calls will be made. 048 */ 049 protected static Log log = 050 LogFactory.getLog("org.apache.commons.digester.Digester.sax"); 051 052 /** 053 * The JAXP 1.2 property required to set up the schema location. 054 */ 055 private static final String JAXP_SCHEMA_SOURCE = 056 "http://java.sun.com/xml/jaxp/properties/schemaSource"; 057 058 /** 059 * The JAXP 1.2 property to set up the schemaLanguage used. 060 */ 061 protected static String JAXP_SCHEMA_LANGUAGE = 062 "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; 063 064 /** 065 * Create a <code>SAXParser</code> configured to support XML Scheman and DTD 066 * @param properties parser specific properties/features 067 * @return an XML Schema/DTD enabled <code>SAXParser</code> 068 */ 069 public static SAXParser newSAXParser(Properties properties) 070 throws ParserConfigurationException, 071 SAXException, 072 SAXNotRecognizedException{ 073 074 SAXParserFactory factory = 075 (SAXParserFactory)properties.get("SAXParserFactory"); 076 SAXParser parser = factory.newSAXParser(); 077 String schemaLocation = (String)properties.get("schemaLocation"); 078 String schemaLanguage = (String)properties.get("schemaLanguage"); 079 080 try{ 081 if (schemaLocation != null) { 082 parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); 083 parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); 084 } 085 } catch (SAXNotRecognizedException e){ 086 log.info(parser.getClass().getName() + ": " 087 + e.getMessage() + " not supported."); 088 } 089 return parser; 090 } 091 092 }