KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > xhtml > XHTMLCharsetHandler


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.xhtml;
12
13 import org.eclipse.help.internal.UAElement;
14 import org.eclipse.help.internal.dynamic.ProcessorHandler;
15
16 /*
17  * Converts the charset in XHTML meta tag to UTF-8. This is the encoding
18  * output by the XMLProcessor, and we need the charset in the meta tags
19  * to match, otherwise browsers will be confused.
20  */

21 public class XHTMLCharsetHandler extends ProcessorHandler {
22
23     private static final String JavaDoc ELEMENT_META = "meta"; //$NON-NLS-1$
24
private static final String JavaDoc ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$
25
private static final String JavaDoc PREFIX_CHARSET = "text/html; charset="; //$NON-NLS-1$
26
private static final String JavaDoc ENCODING_UTF8 = "UTF-8"; //$NON-NLS-1$
27

28     public short handle(UAElement element, String JavaDoc id) {
29         if (ELEMENT_META.equals(element.getElementName())) {
30             String JavaDoc content = element.getAttribute(ATTRIBUTE_CONTENT);
31             if (content != null && content.startsWith(PREFIX_CHARSET)) {
32                 element.setAttribute(ATTRIBUTE_CONTENT, PREFIX_CHARSET + ENCODING_UTF8);
33                 return HANDLED_CONTINUE;
34             }
35         }
36         return UNHANDLED;
37     }
38 }
39
Popular Tags