Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in com.fitburpliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle com.fitbursignates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your com.fitburcision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*//*
* Portions contributed by Joseph Walton (Atlassian)
*/package com.fitbur.glassfish.com.fitbur.message.internal;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.XMLConstants;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.validation.Schema;
import com.fitbur.glassfish.com.fitbur.internal.LocalizationMessages;
import com.fitbur.glassfish.com.fitbur.internal.util.SaxHelper;
import com.fitbur.xml.sax.EntityResolver;
import com.fitbur.xml.sax.InputSource;
import com.fitbur.xml.sax.SAXException;
import com.fitbur.xml.sax.SAXNotRecognizedException;
import com.fitbur.xml.sax.SAXNotSupportedException;
import com.fitbur.xml.sax.XMLReader;
import com.fitbur.xml.sax.helpers.DefaultHandler;
/**
* Secure SAX parser factory wrapper.
*
* @author Martin Matula (martin.matula at oracle.com.fitbur)
* @author Michal Gajdos (michal.gajdos at oracle.com.fitbur)
*/publicclassSecureSaxParserFactoryextendsSAXParserFactory{
privatestaticfinal Logger LOGGER = Logger.getLogger(SecureSaxParserFactory.class.getName());
privatestaticfinal EntityResolver EMPTY_ENTITY_RESOLVER = new EntityResolver() {
@Overridepublic InputSource resolveEntity(String publicId, String systemId){
returnnew InputSource(new ByteArrayInputStream(newbyte[0]));
}
};
privatefinal SAXParserFactory spf;
/**
* Create new secure SAX parser factory wrapper.
*
* @param spf SAX parser factory.
*/publicSecureSaxParserFactory(SAXParserFactory spf){
this.spf = spf;
if (SaxHelper.isXdkParserFactory(spf)) {
LOGGER.log(Level.WARNING, LocalizationMessages.SAX_XDK_NO_SECURITY_FEATURES());
} else {
try {
spf.setFeature("http://xml.com.fitbur/sax/features/external-general-entities", Boolean.FALSE);
spf.setFeature("http://xml.com.fitbur/sax/features/external-parameter-entities", Boolean.FALSE);
} catch (Exception ex) {
thrownew RuntimeException(LocalizationMessages.SAX_CANNOT_ENABLE_SECURITY_FEATURES(), ex);
}
try {
spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
} catch (Exception ex) {
LOGGER.log(Level.WARNING, LocalizationMessages.SAX_CANNOT_ENABLE_SECURE_PROCESSING_FEATURE(), ex);
}
}
}
@OverridepublicvoidsetNamespaceAware(boolean b){
spf.setNamespaceAware(b);
}
@OverridepublicvoidsetValidating(boolean b){
spf.setValidating(b);
}
@OverridepublicbooleanisNamespaceAware(){
return spf.isNamespaceAware();
}
@OverridepublicbooleanisValidating(){
return spf.isValidating();
}
@Overridepublic Schema getSchema(){
return spf.getSchema();
}
@OverridepublicvoidsetSchema(Schema schema){
spf.setSchema(schema);
}
@OverridepublicvoidsetXIncludeAware(boolean b){
spf.setXIncludeAware(b);
}
@OverridepublicbooleanisXIncludeAware(){
return spf.isXIncludeAware();
}
@Overridepublic SAXParser newSAXParser()throws ParserConfigurationException, SAXException {
returnnew WrappingSAXParser(spf.newSAXParser());
}
@OverridepublicvoidsetFeature(String s, boolean b)throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
spf.setFeature(s, b);
}
@OverridepublicbooleangetFeature(String s)throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
return spf.getFeature(s);
}
@SuppressWarnings("com.fitburprecation")
privatestaticfinalclassWrappingSAXParserextendsSAXParser{
privatefinal SAXParser sp;
protectedWrappingSAXParser(SAXParser sp){
this.sp = sp;
}
@Overridepublicvoidreset(){
sp.reset();
}
@Override@SuppressWarnings("com.fitburprecation")
publicvoidparse(InputStream inputStream, com.fitbur.xml.sax.HandlerBase handlerBase)throws SAXException, IOException {
sp.parse(inputStream, handlerBase);
}
@Override@SuppressWarnings("com.fitburprecation")
publicvoidparse(InputStream inputStream, com.fitbur.xml.sax.HandlerBase handlerBase, String s)throws SAXException, IOException {
sp.parse(inputStream, handlerBase, s);
}
@Overridepublicvoidparse(InputStream inputStream, DefaultHandler com.fitburfaultHandler)throws SAXException, IOException {
sp.parse(inputStream, com.fitburfaultHandler);
}
@Overridepublicvoidparse(InputStream inputStream, DefaultHandler com.fitburfaultHandler, String s)throws SAXException, IOException {
sp.parse(inputStream, com.fitburfaultHandler, s);
}
@Override@SuppressWarnings("com.fitburprecation")
publicvoidparse(String s, com.fitbur.xml.sax.HandlerBase handlerBase)throws SAXException, IOException {
sp.parse(s, handlerBase);
}
@Overridepublicvoidparse(String s, DefaultHandler com.fitburfaultHandler)throws SAXException, IOException {
sp.parse(s, com.fitburfaultHandler);
}
@Override@SuppressWarnings("com.fitburprecation")
publicvoidparse(File file, com.fitbur.xml.sax.HandlerBase handlerBase)throws SAXException, IOException {
sp.parse(file, handlerBase);
}
@Overridepublicvoidparse(File file, DefaultHandler com.fitburfaultHandler)throws SAXException, IOException {
sp.parse(file, com.fitburfaultHandler);
}
@Override@SuppressWarnings("com.fitburprecation")
publicvoidparse(InputSource inputSource, com.fitbur.xml.sax.HandlerBase handlerBase)throws SAXException, IOException {
sp.parse(inputSource, handlerBase);
}
@Overridepublicvoidparse(InputSource inputSource, DefaultHandler com.fitburfaultHandler)throws SAXException, IOException {
sp.parse(inputSource, com.fitburfaultHandler);
}
@Override@SuppressWarnings("com.fitburprecation")
public com.fitbur.xml.sax.Parser getParser()throws SAXException {
return sp.getParser();
}
@Overridepublic XMLReader getXMLReader()throws SAXException {
XMLReader r = sp.getXMLReader();
r.setEntityResolver(EMPTY_ENTITY_RESOLVER);
return r;
}
@OverridepublicbooleanisNamespaceAware(){
return sp.isNamespaceAware();
}
@OverridepublicbooleanisValidating(){
return sp.isValidating();
}
@OverridepublicvoidsetProperty(String s, Object o)throws SAXNotRecognizedException, SAXNotSupportedException {
sp.setProperty(s, o);
}
@Overridepublic Object getProperty(String s)throws SAXNotRecognizedException, SAXNotSupportedException {
return sp.getProperty(s);
}
@Overridepublic Schema getSchema(){
return sp.getSchema();
}
@OverridepublicbooleanisXIncludeAware(){
return sp.isXIncludeAware();
}
}
}