From d8f4792f8e20bf7c0c0ca7a057245c3fd1e2a75d Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 2 Nov 2007 00:43:07 +0000 Subject: [PATCH] HADOOP-2137 hql.jsp : The character 0x19 is not valid git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@591177 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../shell/formatter/HtmlTableFormatter.java | 48 ++++++++++++++++++- .../hadoop/hbase/shell/TestConsoleTable.java | 37 -------------- src/webapps/master/hql.jsp | 4 +- 4 files changed, 50 insertions(+), 40 deletions(-) delete mode 100644 src/test/org/apache/hadoop/hbase/shell/TestConsoleTable.java diff --git a/CHANGES.txt b/CHANGES.txt index 4fe31100c9c..e8b7d44c69b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,7 @@ Trunk (unreleased changes) HADOOP-2124 Use of `hostname` does not work on Cygwin in some cases HADOOP-2083 TestTableIndex failed in #970 and #956 HADOOP-2109 Fixed race condition in processing server lease timeout. + HADOOP-2137 hql.jsp : The character 0x19 is not valid IMPROVEMENTS HADOOP-2401 Add convenience put method that takes writable diff --git a/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java b/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java index 318e471d9b2..33352918d75 100644 --- a/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java +++ b/src/java/org/apache/hadoop/hbase/shell/formatter/HtmlTableFormatter.java @@ -2,11 +2,14 @@ package org.apache.hadoop.hbase.shell.formatter; import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.io.Writer; import org.apache.hadoop.hbase.shell.TableFormatter; import org.znerd.xmlenc.LineBreak; import org.znerd.xmlenc.XMLOutputter; +import org.znerd.xmlenc.XMLEncoder; +import org.znerd.xmlenc.InvalidXMLException; /** * Formatter that outputs data inside an HTML table. If only a single cell @@ -28,13 +31,56 @@ public class HtmlTableFormatter implements TableFormatter { private HtmlTableFormatter() { this(null); } + + /* + * An encoder that replaces illegal XML characters with the '@' sign. + */ + private static class HbaseXMLEncoder extends XMLEncoder { + @SuppressWarnings("deprecation") + public HbaseXMLEncoder() + throws IllegalArgumentException, UnsupportedEncodingException { + super("UTF-8"); + } + + @Override + public void text(Writer w, char c, boolean escape) + throws InvalidXMLException, IOException { + super.text(w, legalize(c), escape); + } + + @Override + public void text(Writer w, char[] cs, int start, int length, boolean b) + throws NullPointerException, IndexOutOfBoundsException, + InvalidXMLException, IOException { + for (int i = start; i < start + length; i++) { + cs[i] = legalize(cs[i]); + } + super.text(w, cs, start, length, b); + } + + /** + * If character is in range A, C, or E, then replace with '@' + *
+     * A   0-8     Control characters   -- Not allowed in XML 1.0 --
+     * B   9-10    Normal characters    Never needed
+     * C   11-12   Control characters   -- Not allowed in XML 1.0 --
+     * D   13      Normal character     Never needed
+     * E   14-31   Control characters   -- Not allowed in XML 1.0 --
+     * 
+ * @param c Character to look at. + * @return + */ + private char legalize(final char c) { + return (c <= 8 || c == 11 || c == 12 || (c >= 14 && c <= 31))? '@': c; + } + } public HtmlTableFormatter(final Writer o) { this.out = o; try { // Looking at the xmlenc source, there should be no issue w/ wrapping // the stream -- i.e. no hanging resources. - this.outputter = new XMLOutputter(this.out, "UTF-8"); + this.outputter = new XMLOutputter(this.out, new HbaseXMLEncoder()); String os = System.getProperty("os.name").toLowerCase(); // Shell likes the DOS output. this.outputter.setLineBreak(os.contains("windows")? diff --git a/src/test/org/apache/hadoop/hbase/shell/TestConsoleTable.java b/src/test/org/apache/hadoop/hbase/shell/TestConsoleTable.java deleted file mode 100644 index a340f2af022..00000000000 --- a/src/test/org/apache/hadoop/hbase/shell/TestConsoleTable.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.shell; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import junit.textui.TestRunner; - -/** - * Test the console table class - */ -public class TestConsoleTable extends TestCase { - public void testPrintTable() { - - } - - public static void main(String[] args) { - TestRunner.run(new TestSuite(TestConsoleTable.class)); - } -} diff --git a/src/webapps/master/hql.jsp b/src/webapps/master/hql.jsp index 366769f992f..97abc6d753c 100644 --- a/src/webapps/master/hql.jsp +++ b/src/webapps/master/hql.jsp @@ -28,11 +28,11 @@

- +

-

Enter 'help;' -- thats 'help' plus a semi-colon -- for a list of HQL commands. +

Enter 'help;' -- thats 'help' plus a semi-colon -- for the list of HQL commands. Data Definition, SHELL, INSERTS, DELETES, and UPDATE commands are disabled in this interface