View | Details | Raw Unified | Return to bug 40880
Collapse All | Expand All

(-)src/org/apache/xml/security/encryption/FragmentParserFactory.java (+58 lines)
Line 0 Link Here
1
/*
2
 * Copyright 2004,2005 The Apache Software Foundation.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.apache.xml.security.encryption;
18
19
import org.w3c.dom.Document;
20
import org.xml.sax.InputSource;
21
import org.xml.sax.SAXException;
22
23
import javax.xml.parsers.DocumentBuilder;
24
import javax.xml.parsers.DocumentBuilderFactory;
25
import javax.xml.parsers.ParserConfigurationException;
26
27
import sun.misc.Service;
28
29
import java.io.IOException;
30
import java.io.StringReader;
31
import java.util.Iterator;
32
33
/**
34
 *
35
 * @author Ruchith Fernando (ruchith.fernando@gmail.com)
36
 */
37
public class FragmentParserFactory {
38
39
    public static FragmentParser getFragmentParser() {
40
        
41
        for (Iterator providers = Service.providers(FragmentParser.class); providers.hasNext();) {
42
            return (FragmentParser)providers.next();
43
        }
44
        
45
        return new FragmentParser() {
46
            public Document parseFragment(String fragment) throws ParserConfigurationException, SAXException, IOException {
47
                DocumentBuilderFactory dbf =
48
                    DocumentBuilderFactory.newInstance();
49
                dbf.setNamespaceAware(true);
50
                dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
51
                DocumentBuilder db = dbf.newDocumentBuilder();
52
                Document d = db.parse(
53
                    new InputSource(new StringReader(fragment)));
54
                return d;
55
            }
56
        };
57
    }
58
}
(-)src/org/apache/xml/security/encryption/FragmentParser.java (+33 lines)
Line 0 Link Here
1
/*
2
 * Copyright 2004,2005 The Apache Software Foundation.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.apache.xml.security.encryption;
18
19
import org.w3c.dom.Document;
20
import org.xml.sax.SAXException;
21
22
import javax.xml.parsers.ParserConfigurationException;
23
24
import java.io.IOException;
25
26
/**
27
 *
28
 * @author Ruchith Fernando (ruchith.fernando@gmail.com)
29
 */
30
public interface FragmentParser {
31
    
32
    Document parseFragment(String fragment) throws ParserConfigurationException, SAXException, IOException;
33
}
(-)src/org/apache/xml/security/encryption/XMLCipher.java (-14 / +4 lines)
Lines 37-44 Link Here
37
import javax.crypto.IllegalBlockSizeException;
37
import javax.crypto.IllegalBlockSizeException;
38
import javax.crypto.NoSuchPaddingException;
38
import javax.crypto.NoSuchPaddingException;
39
import javax.crypto.spec.IvParameterSpec;
39
import javax.crypto.spec.IvParameterSpec;
40
import javax.xml.parsers.DocumentBuilder;
41
import javax.xml.parsers.DocumentBuilderFactory;
42
import javax.xml.parsers.ParserConfigurationException;
40
import javax.xml.parsers.ParserConfigurationException;
43
41
44
import org.apache.xml.security.algorithms.JCEMapper;
42
import org.apache.xml.security.algorithms.JCEMapper;
Lines 1939-1945 Link Here
1939
			String fragment = sb.toString();
1937
			String fragment = sb.toString();
1940
1938
1941
            try {
1939
            try {
1942
                Document d = parseFragment(fragment);
1940
                Document d = FragmentParserFactory.getFragmentParser()
1941
                        .parseFragment(fragment);
1942
                
1943
				Element fragElt = (Element) _contextDocument.importNode(
1943
				Element fragElt = (Element) _contextDocument.importNode(
1944
						 d.getDocumentElement(), true);
1944
						 d.getDocumentElement(), true);
1945
				result = _contextDocument.createDocumentFragment();
1945
				result = _contextDocument.createDocumentFragment();
Lines 1960-1978 Link Here
1960
            return (result);
1960
            return (result);
1961
        }
1961
        }
1962
1962
1963
        protected Document parseFragment(String fragment) throws ParserConfigurationException, SAXException, IOException {
1964
            DocumentBuilderFactory dbf =
1965
                DocumentBuilderFactory.newInstance();
1966
            dbf.setNamespaceAware(true);
1967
            dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
1968
            DocumentBuilder db = dbf.newDocumentBuilder();
1969
            Document d = db.parse(
1970
                new InputSource(new StringReader(fragment)));
1971
            return d;
1972
        }
1973
    }
1963
    }
1964
    
1974
1965
1975
1976
    /**
1966
    /**
1977
     *
1967
     *
1978
     * @author Axl Mattheus
1968
     * @author Axl Mattheus

Return to bug 40880