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 |
} |