1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Entity Resolver for using external DTD files in XML parsing. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.tools.themeinstaller.xmlparser; |
|
20 |
|
21 import java.io.IOException; |
|
22 |
|
23 import org.xml.sax.EntityResolver; |
|
24 import org.xml.sax.InputSource; |
|
25 import org.xml.sax.SAXException; |
|
26 |
|
27 /** |
|
28 * DTD Entity Resolver is for using external DTD files in XML parsing. |
|
29 * The resolveEntity method returns null if the provided system id does |
|
30 * not end with the ".dtd". |
|
31 */ |
|
32 public class DTDEntityResolver implements EntityResolver |
|
33 { |
|
34 |
|
35 // CONSTANTS |
|
36 // DTD file extension |
|
37 private static final String DTD_FILE_EXT = ".dtd"; |
|
38 |
|
39 // File name of the external DTD |
|
40 private String iFileName; |
|
41 |
|
42 /** |
|
43 * Constructor. |
|
44 * @param aFileName file name of the DTD file |
|
45 */ |
|
46 public DTDEntityResolver( String aFileName ) |
|
47 { |
|
48 iFileName = aFileName; |
|
49 } |
|
50 |
|
51 /* (non-Javadoc) |
|
52 * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String) |
|
53 */ |
|
54 public InputSource resolveEntity( String aPublicId, String aSystemId ) |
|
55 throws SAXException, IOException |
|
56 { |
|
57 DTDInputSource is = null; |
|
58 |
|
59 // For DTD files, provide input source containing the external DTD for |
|
60 // the XML parser |
|
61 if( aSystemId.endsWith( DTD_FILE_EXT ) ) |
|
62 { |
|
63 is = new DTDInputSource( iFileName ); |
|
64 } |
|
65 |
|
66 return is; |
|
67 } |
|
68 |
|
69 } |
|