equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package javax.swing.text.html.parser; |
26 package javax.swing.text.html.parser; |
|
27 |
|
28 import sun.awt.AppContext; |
27 |
29 |
28 import java.io.PrintStream; |
30 import java.io.PrintStream; |
29 import java.io.File; |
31 import java.io.File; |
30 import java.io.FileInputStream; |
32 import java.io.FileInputStream; |
31 import java.io.InputStream; |
33 import java.io.InputStream; |
312 public String toString() { |
314 public String toString() { |
313 return name; |
315 return name; |
314 } |
316 } |
315 |
317 |
316 /** |
318 /** |
317 * The hashtable of DTDs. |
319 * The hashtable key of DTDs in AppContext. |
318 */ |
320 */ |
319 static Hashtable<String, DTD> dtdHash = new Hashtable<String, DTD>(); |
321 private static final Object DTD_HASH_KEY = new Object(); |
320 |
322 |
321 public static void putDTDHash(String name, DTD dtd) { |
323 public static void putDTDHash(String name, DTD dtd) { |
322 dtdHash.put(name, dtd); |
324 getDtdHash().put(name, dtd); |
323 } |
325 } |
|
326 |
324 /** |
327 /** |
325 * Returns a DTD with the specified <code>name</code>. If |
328 * Returns a DTD with the specified <code>name</code>. If |
326 * a DTD with that name doesn't exist, one is created |
329 * a DTD with that name doesn't exist, one is created |
327 * and returned. Any uppercase characters in the name |
330 * and returned. Any uppercase characters in the name |
328 * are converted to lowercase. |
331 * are converted to lowercase. |
330 * @param name the name of the DTD |
333 * @param name the name of the DTD |
331 * @return the DTD which corresponds to <code>name</code> |
334 * @return the DTD which corresponds to <code>name</code> |
332 */ |
335 */ |
333 public static DTD getDTD(String name) throws IOException { |
336 public static DTD getDTD(String name) throws IOException { |
334 name = name.toLowerCase(); |
337 name = name.toLowerCase(); |
335 DTD dtd = dtdHash.get(name); |
338 DTD dtd = getDtdHash().get(name); |
336 if (dtd == null) |
339 if (dtd == null) |
337 dtd = new DTD(name); |
340 dtd = new DTD(name); |
338 |
341 |
339 return dtd; |
342 return dtd; |
|
343 } |
|
344 |
|
345 private static Hashtable<String, DTD> getDtdHash() { |
|
346 AppContext appContext = AppContext.getAppContext(); |
|
347 |
|
348 Hashtable<String, DTD> result = (Hashtable<String, DTD>) appContext.get(DTD_HASH_KEY); |
|
349 |
|
350 if (result == null) { |
|
351 result = new Hashtable<String, DTD>(); |
|
352 |
|
353 appContext.put(DTD_HASH_KEY, result); |
|
354 } |
|
355 |
|
356 return result; |
340 } |
357 } |
341 |
358 |
342 /** |
359 /** |
343 * Recreates a DTD from an archived format. |
360 * Recreates a DTD from an archived format. |
344 * @param in the <code>DataInputStream</code> to read from |
361 * @param in the <code>DataInputStream</code> to read from |