diff --git a/au/com/bytecode/opencsv/CSVParser.java b/au/com/bytecode/opencsv/CSVParser.java new file mode 100644 index 0000000..6ae036f --- /dev/null +++ b/au/com/bytecode/opencsv/CSVParser.java @@ -0,0 +1,323 @@ +package au.com.bytecode.opencsv; + +/** + Copyright 2005 Bytecode Pty Ltd. + + Licensed 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * A very simple CSV parser released under a commercial-friendly license. + * This just implements splitting a single line into fields. + * + * @author Glen Smith + * @author Rainer Pruy + */ +public class CSVParser { + + private final char separator; + + private final char quotechar; + + private final char escape; + + private final boolean strictQuotes; + + private String pending; + private boolean inField = false; + + private final boolean ignoreLeadingWhiteSpace; + + /** + * The default separator to use if none is supplied to the constructor. + */ + public static final char DEFAULT_SEPARATOR = ','; + + public static final int INITIAL_READ_SIZE = 128; + + /** + * The default quote character to use if none is supplied to the + * constructor. + */ + public static final char DEFAULT_QUOTE_CHARACTER = '"'; + + + /** + * The default escape character to use if none is supplied to the + * constructor. + */ + public static final char DEFAULT_ESCAPE_CHARACTER = '\\'; + + /** + * The default strict quote behavior to use if none is supplied to the + * constructor + */ + public static final boolean DEFAULT_STRICT_QUOTES = false; + + /** + * The default leading whitespace behavior to use if none is supplied to the + * constructor + */ + public static final boolean DEFAULT_IGNORE_LEADING_WHITESPACE = true; + + /** + * This is the "null" character - if a value is set to this then it is ignored. + * I.E. if the quote character is set to null then there is no quote character. + */ + public static final char NULL_CHARACTER = '\0'; + + /** + * Constructs CSVParser using a comma for the separator. + */ + public CSVParser() { + this(DEFAULT_SEPARATOR, DEFAULT_QUOTE_CHARACTER, DEFAULT_ESCAPE_CHARACTER); + } + + /** + * Constructs CSVParser with supplied separator. + * + * @param separator the delimiter to use for separating entries. + */ + public CSVParser(char separator) { + this(separator, DEFAULT_QUOTE_CHARACTER, DEFAULT_ESCAPE_CHARACTER); + } + + + /** + * Constructs CSVParser with supplied separator and quote char. + * + * @param separator the delimiter to use for separating entries + * @param quotechar the character to use for quoted elements + */ + public CSVParser(char separator, char quotechar) { + this(separator, quotechar, DEFAULT_ESCAPE_CHARACTER); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param separator the delimiter to use for separating entries + * @param quotechar the character to use for quoted elements + * @param escape the character to use for escaping a separator or quote + */ + public CSVParser(char separator, char quotechar, char escape) { + this(separator, quotechar, escape, DEFAULT_STRICT_QUOTES); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * Allows setting the "strict quotes" flag + * + * @param separator the delimiter to use for separating entries + * @param quotechar the character to use for quoted elements + * @param escape the character to use for escaping a separator or quote + * @param strictQuotes if true, characters outside the quotes are ignored + */ + public CSVParser(char separator, char quotechar, char escape, boolean strictQuotes) { + this(separator, quotechar, escape, strictQuotes, DEFAULT_IGNORE_LEADING_WHITESPACE); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * Allows setting the "strict quotes" and "ignore leading whitespace" flags + * + * @param separator the delimiter to use for separating entries + * @param quotechar the character to use for quoted elements + * @param escape the character to use for escaping a separator or quote + * @param strictQuotes if true, characters outside the quotes are ignored + * @param ignoreLeadingWhiteSpace if true, white space in front of a quote in a field is ignored + */ + public CSVParser(char separator, char quotechar, char escape, boolean strictQuotes, boolean ignoreLeadingWhiteSpace) { + if (anyCharactersAreTheSame(separator, quotechar, escape)) { + throw new UnsupportedOperationException("The separator, quote, and escape characters must be different!"); + } + if (separator == NULL_CHARACTER) { + throw new UnsupportedOperationException("The separator character must be defined!"); + } + this.separator = separator; + this.quotechar = quotechar; + this.escape = escape; + this.strictQuotes = strictQuotes; + this.ignoreLeadingWhiteSpace = ignoreLeadingWhiteSpace; + } + + private boolean anyCharactersAreTheSame(char separator, char quotechar, char escape) { + return isSameCharacter(separator, quotechar) || isSameCharacter(separator, escape) || isSameCharacter(quotechar, escape); + } + + private boolean isSameCharacter(char c1, char c2) { + return c1 != NULL_CHARACTER && c1 == c2; + } + + /** + * @return true if something was left over from last call(s) + */ + public boolean isPending() { + return pending != null; + } + + public String[] parseLineMulti(String nextLine) throws IOException { + return parseLine(nextLine, true); + } + + public String[] parseLine(String nextLine) throws IOException { + return parseLine(nextLine, false); + } + + /** + * Parses an incoming String and returns an array of elements. + * + * @param nextLine the string to parse + * @param multi + * @return the comma-tokenized list of elements, or null if nextLine is null + * @throws IOException if bad things happen during the read + */ + private String[] parseLine(String nextLine, boolean multi) throws IOException { + + if (!multi && pending != null) { + pending = null; + } + + if (nextLine == null) { + if (pending != null) { + String s = pending; + pending = null; + return new String[]{s}; + } else { + return null; + } + } + + List tokensOnThisLine = new ArrayList(); + StringBuilder sb = new StringBuilder(INITIAL_READ_SIZE); + boolean inQuotes = false; + if (pending != null) { + sb.append(pending); + pending = null; + inQuotes = true; + } + for (int i = 0; i < nextLine.length(); i++) { + + char c = nextLine.charAt(i); + if (c == this.escape) { + if (isNextCharacterEscapable(nextLine, inQuotes || inField, i)) { + sb.append(nextLine.charAt(i + 1)); + i++; + } + } else if (c == quotechar) { + if (isNextCharacterEscapedQuote(nextLine, inQuotes || inField, i)) { + sb.append(nextLine.charAt(i + 1)); + i++; + } else { + //inQuotes = !inQuotes; + + // the tricky case of an embedded quote in the middle: a,bc"d"ef,g + if (!strictQuotes) { + if (i > 2 //not on the beginning of the line + && nextLine.charAt(i - 1) != this.separator //not at the beginning of an escape sequence + && nextLine.length() > (i + 1) && + nextLine.charAt(i + 1) != this.separator //not at the end of an escape sequence + ) { + + if (ignoreLeadingWhiteSpace && sb.length() > 0 && isAllWhiteSpace(sb)) { + sb.setLength(0); //discard white space leading up to quote + } else { + sb.append(c); + //continue; + } + + } + } + + inQuotes = !inQuotes; + } + inField = !inField; + } else if (c == separator && !inQuotes) { + tokensOnThisLine.add(sb.toString()); + sb.setLength(0); // start work on next token + inField = false; + } else { + if (!strictQuotes || inQuotes) { + sb.append(c); + inField = true; + } + } + } + // line is done - check status + if (inQuotes) { + if (multi) { + // continuing a quoted section, re-append newline + sb.append("\n"); + pending = sb.toString(); + sb = null; // this partial content is not to be added to field list yet + } else { + throw new IOException("Un-terminated quoted field at end of CSV line"); + } + } + if (sb != null) { + tokensOnThisLine.add(sb.toString()); + } + return tokensOnThisLine.toArray(new String[tokensOnThisLine.size()]); + + } + + /** + * precondition: the current character is a quote or an escape + * + * @param nextLine the current line + * @param inQuotes true if the current context is quoted + * @param i current index in line + * @return true if the following character is a quote + */ + private boolean isNextCharacterEscapedQuote(String nextLine, boolean inQuotes, int i) { + return inQuotes // we are in quotes, therefore there can be escaped quotes in here. + && nextLine.length() > (i + 1) // there is indeed another character to check. + && nextLine.charAt(i + 1) == quotechar; + } + + /** + * precondition: the current character is an escape + * + * @param nextLine the current line + * @param inQuotes true if the current context is quoted + * @param i current index in line + * @return true if the following character is a quote + */ + protected boolean isNextCharacterEscapable(String nextLine, boolean inQuotes, int i) { + return inQuotes // we are in quotes, therefore there can be escaped quotes in here. + && nextLine.length() > (i + 1) // there is indeed another character to check. + && (nextLine.charAt(i + 1) == quotechar || nextLine.charAt(i + 1) == this.escape); + } + + /** + * precondition: sb.length() > 0 + * + * @param sb A sequence of characters to examine + * @return true if every character in the sequence is whitespace + */ + protected boolean isAllWhiteSpace(CharSequence sb) { + boolean result = true; + for (int i = 0; i < sb.length(); i++) { + char c = sb.charAt(i); + + if (!Character.isWhitespace(c)) { + return false; + } + } + return result; + } +} diff --git a/au/com/bytecode/opencsv/CSVReader.java b/au/com/bytecode/opencsv/CSVReader.java new file mode 100644 index 0000000..1cd0d04 --- /dev/null +++ b/au/com/bytecode/opencsv/CSVReader.java @@ -0,0 +1,282 @@ +package au.com.bytecode.opencsv; + +/** + Copyright 2005 Bytecode Pty Ltd. + + Licensed 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. + */ + +import java.io.BufferedReader; +import java.io.Closeable; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; + +/** + * A very simple CSV reader released under a commercial-friendly license. + * + * @author Glen Smith + * + */ +public class CSVReader implements Closeable { + + private BufferedReader br; + + private boolean hasNext = true; + + private CSVParser parser; + + private int skipLines; + + private boolean linesSkiped; + + /** + * The default line to start reading. + */ + public static final int DEFAULT_SKIP_LINES = 0; + + /** + * Constructs CSVReader using a comma for the separator. + * + * @param reader + * the reader to an underlying CSV source. + */ + public CSVReader(Reader reader) { + this(reader, CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER); + } + + /** + * Constructs CSVReader with supplied separator. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries. + */ + public CSVReader(Reader reader, char separator) { + this(reader, separator, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + */ + public CSVReader(Reader reader, char separator, char quotechar) { + this(reader, separator, quotechar, CSVParser.DEFAULT_ESCAPE_CHARACTER, DEFAULT_SKIP_LINES, CSVParser.DEFAULT_STRICT_QUOTES); + } + + /** + * Constructs CSVReader with supplied separator, quote char and quote handling + * behavior. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param strictQuotes + * sets if characters outside the quotes are ignored + */ + public CSVReader(Reader reader, char separator, char quotechar, boolean strictQuotes) { + this(reader, separator, quotechar, CSVParser.DEFAULT_ESCAPE_CHARACTER, DEFAULT_SKIP_LINES, strictQuotes); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param escape + * the character to use for escaping a separator or quote + */ + + public CSVReader(Reader reader, char separator, + char quotechar, char escape) { + this(reader, separator, quotechar, escape, DEFAULT_SKIP_LINES, CSVParser.DEFAULT_STRICT_QUOTES); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param line + * the line number to skip for start reading + */ + public CSVReader(Reader reader, char separator, char quotechar, int line) { + this(reader, separator, quotechar, CSVParser.DEFAULT_ESCAPE_CHARACTER, line, CSVParser.DEFAULT_STRICT_QUOTES); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param escape + * the character to use for escaping a separator or quote + * @param line + * the line number to skip for start reading + */ + public CSVReader(Reader reader, char separator, char quotechar, char escape, int line) { + this(reader, separator, quotechar, escape, line, CSVParser.DEFAULT_STRICT_QUOTES); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param escape + * the character to use for escaping a separator or quote + * @param line + * the line number to skip for start reading + * @param strictQuotes + * sets if characters outside the quotes are ignored + */ + public CSVReader(Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes) { + this(reader, separator, quotechar, escape, line, strictQuotes, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE); + } + + /** + * Constructs CSVReader with supplied separator and quote char. + * + * @param reader + * the reader to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param escape + * the character to use for escaping a separator or quote + * @param line + * the line number to skip for start reading + * @param strictQuotes + * sets if characters outside the quotes are ignored + * @param ignoreLeadingWhiteSpace + * it true, parser should ignore white space before a quote in a field + */ + public CSVReader(Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace) { + this.br = new BufferedReader(reader); + this.parser = new CSVParser(separator, quotechar, escape, strictQuotes, ignoreLeadingWhiteSpace); + this.skipLines = line; + } + + /** + * Reads the entire file into a List with each element being a String[] of + * tokens. + * + * @return a List of String[], with each String[] representing a line of the + * file. + * + * @throws IOException + * if bad things happen during the read + */ + public List readAll() throws IOException { + + List allElements = new ArrayList(); + while (hasNext) { + String[] nextLineAsTokens = readNext(); + if (nextLineAsTokens != null) + allElements.add(nextLineAsTokens); + } + return allElements; + + } + + /** + * Reads the next line from the buffer and converts to a string array. + * + * @return a string array with each comma-separated element as a separate + * entry. + * + * @throws IOException + * if bad things happen during the read + */ + public String[] readNext() throws IOException { + + String[] result = null; + do { + String nextLine = getNextLine(); + if (!hasNext) { + return result; // should throw if still pending? + } + String[] r = parser.parseLineMulti(nextLine); + if (r.length > 0) { + if (result == null) { + result = r; + } else { + String[] t = new String[result.length+r.length]; + System.arraycopy(result, 0, t, 0, result.length); + System.arraycopy(r, 0, t, result.length, r.length); + result = t; + } + } + } while (parser.isPending()); + return result; + } + + /** + * Reads the next line from the file. + * + * @return the next line from the file without trailing newline + * @throws IOException + * if bad things happen during the read + */ + private String getNextLine() throws IOException { + if (!this.linesSkiped) { + for (int i = 0; i < skipLines; i++) { + br.readLine(); + } + this.linesSkiped = true; + } + String nextLine = br.readLine(); + if (nextLine == null) { + hasNext = false; + } + return hasNext ? nextLine : null; + } + + /** + * Closes the underlying reader. + * + * @throws IOException if the close fails + */ + public void close() throws IOException{ + br.close(); + } + +} diff --git a/au/com/bytecode/opencsv/CSVWriter.java b/au/com/bytecode/opencsv/CSVWriter.java new file mode 100644 index 0000000..74c3482 --- /dev/null +++ b/au/com/bytecode/opencsv/CSVWriter.java @@ -0,0 +1,302 @@ +package au.com.bytecode.opencsv; + +/** + Copyright 2005 Bytecode Pty Ltd. + + Licensed 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. + */ + +import java.io.Closeable; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Writer; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +/** + * A very simple CSV writer released under a commercial-friendly license. + * + * @author Glen Smith + * + */ +public class CSVWriter implements Closeable { + + public static final int INITIAL_STRING_SIZE = 128; + + private Writer rawWriter; + + private PrintWriter pw; + + private char separator; + + private char quotechar; + + private char escapechar; + + private String lineEnd; + + /** The character used for escaping quotes. */ + public static final char DEFAULT_ESCAPE_CHARACTER = '"'; + + /** The default separator to use if none is supplied to the constructor. */ + public static final char DEFAULT_SEPARATOR = ','; + + /** + * The default quote character to use if none is supplied to the + * constructor. + */ + public static final char DEFAULT_QUOTE_CHARACTER = '"'; + + /** The quote constant to use when you wish to suppress all quoting. */ + public static final char NO_QUOTE_CHARACTER = '\u0000'; + + /** The escape constant to use when you wish to suppress all escaping. */ + public static final char NO_ESCAPE_CHARACTER = '\u0000'; + + /** Default line terminator uses platform encoding. */ + public static final String DEFAULT_LINE_END = "\n"; + + private ResultSetHelper resultService = new ResultSetHelperService(); + + /** + * Constructs CSVWriter using a comma for the separator. + * + * @param writer + * the writer to an underlying CSV source. + */ + public CSVWriter(Writer writer) { + this(writer, DEFAULT_SEPARATOR); + } + + /** + * Constructs CSVWriter with supplied separator. + * + * @param writer + * the writer to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries. + */ + public CSVWriter(Writer writer, char separator) { + this(writer, separator, DEFAULT_QUOTE_CHARACTER); + } + + /** + * Constructs CSVWriter with supplied separator and quote char. + * + * @param writer + * the writer to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + */ + public CSVWriter(Writer writer, char separator, char quotechar) { + this(writer, separator, quotechar, DEFAULT_ESCAPE_CHARACTER); + } + + /** + * Constructs CSVWriter with supplied separator and quote char. + * + * @param writer + * the writer to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param escapechar + * the character to use for escaping quotechars or escapechars + */ + public CSVWriter(Writer writer, char separator, char quotechar, char escapechar) { + this(writer, separator, quotechar, escapechar, DEFAULT_LINE_END); + } + + + /** + * Constructs CSVWriter with supplied separator and quote char. + * + * @param writer + * the writer to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param lineEnd + * the line feed terminator to use + */ + public CSVWriter(Writer writer, char separator, char quotechar, String lineEnd) { + this(writer, separator, quotechar, DEFAULT_ESCAPE_CHARACTER, lineEnd); + } + + + + /** + * Constructs CSVWriter with supplied separator, quote char, escape char and line ending. + * + * @param writer + * the writer to an underlying CSV source. + * @param separator + * the delimiter to use for separating entries + * @param quotechar + * the character to use for quoted elements + * @param escapechar + * the character to use for escaping quotechars or escapechars + * @param lineEnd + * the line feed terminator to use + */ + public CSVWriter(Writer writer, char separator, char quotechar, char escapechar, String lineEnd) { + this.rawWriter = writer; + this.pw = new PrintWriter(writer); + this.separator = separator; + this.quotechar = quotechar; + this.escapechar = escapechar; + this.lineEnd = lineEnd; + } + + /** + * Writes the entire list to a CSV file. The list is assumed to be a + * String[] + * + * @param allLines + * a List of String[], with each String[] representing a line of + * the file. + */ + public void writeAll(List allLines) { + for (String[] line : allLines) { + writeNext(line); + } + } + + protected void writeColumnNames(ResultSet rs) + throws SQLException { + + writeNext(resultService.getColumnNames(rs)); + } + + /** + * Writes the entire ResultSet to a CSV file. + * + * The caller is responsible for closing the ResultSet. + * + * @param rs the recordset to write + * @param includeColumnNames true if you want column names in the output, false otherwise + * + * @throws java.io.IOException thrown by getColumnValue + * @throws java.sql.SQLException thrown by getColumnValue + */ + public void writeAll(java.sql.ResultSet rs, boolean includeColumnNames) throws SQLException, IOException { + + + if (includeColumnNames) { + writeColumnNames(rs); + } + + while (rs.next()) + { + writeNext(resultService.getColumnValues(rs)); + } + } + + + /** + * Writes the next line to the file. + * + * @param nextLine + * a string array with each comma-separated element as a separate + * entry. + */ + public void writeNext(String[] nextLine) { + + if (nextLine == null) + return; + + StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE); + for (int i = 0; i < nextLine.length; i++) { + + if (i != 0) { + sb.append(separator); + } + + String nextElement = nextLine[i]; + if (nextElement == null) + continue; + if (quotechar != NO_QUOTE_CHARACTER) + sb.append(quotechar); + + sb.append(stringContainsSpecialCharacters(nextElement) ? processLine(nextElement) : nextElement); + + if (quotechar != NO_QUOTE_CHARACTER) + sb.append(quotechar); + } + + sb.append(lineEnd); + pw.write(sb.toString()); + + } + + private boolean stringContainsSpecialCharacters(String line) { + return line.indexOf(quotechar) != -1 || line.indexOf(escapechar) != -1; + } + + protected StringBuilder processLine(String nextElement) + { + StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE); + for (int j = 0; j < nextElement.length(); j++) { + char nextChar = nextElement.charAt(j); + if (escapechar != NO_ESCAPE_CHARACTER && nextChar == quotechar) { + sb.append(escapechar).append(nextChar); + } else if (escapechar != NO_ESCAPE_CHARACTER && nextChar == escapechar) { + sb.append(escapechar).append(nextChar); + } else { + sb.append(nextChar); + } + } + + return sb; + } + + /** + * Flush underlying stream to writer. + * + * @throws IOException if bad things happen + */ + public void flush() throws IOException { + + pw.flush(); + + } + + /** + * Close the underlying stream writer flushing any buffered content. + * + * @throws IOException if bad things happen + * + */ + public void close() throws IOException { + flush(); + pw.close(); + rawWriter.close(); + } + + /** + * Checks to see if the there has been an error in the printstream. + */ + public boolean checkError() { + return pw.checkError(); + } + + public void setResultService(ResultSetHelper resultService) { + this.resultService = resultService; + } + +} diff --git a/au/com/bytecode/opencsv/ResultSetHelper.java b/au/com/bytecode/opencsv/ResultSetHelper.java new file mode 100644 index 0000000..aa61d4a --- /dev/null +++ b/au/com/bytecode/opencsv/ResultSetHelper.java @@ -0,0 +1,33 @@ +package au.com.bytecode.opencsv; +/** + Copyright 2005 Bytecode Pty Ltd. + + Licensed 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. + */ + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * + * + * + * + * + */ +public interface ResultSetHelper { + public String[] getColumnNames(ResultSet rs) throws SQLException; + + public String[] getColumnValues(ResultSet rs) throws SQLException, IOException; +} diff --git a/au/com/bytecode/opencsv/ResultSetHelperService.java b/au/com/bytecode/opencsv/ResultSetHelperService.java new file mode 100644 index 0000000..23d9661 --- /dev/null +++ b/au/com/bytecode/opencsv/ResultSetHelperService.java @@ -0,0 +1,183 @@ +package au.com.bytecode.opencsv; +/** + Copyright 2005 Bytecode Pty Ltd. + + Licensed 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. + */ +import java.io.IOException; +import java.io.Reader; +import java.math.BigDecimal; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +/** + * + * + * helper class for processing JDBC ResultSet objects + * + * + */ +public class ResultSetHelperService implements ResultSetHelper { + public static final int CLOBBUFFERSIZE = 2048; + + // note: we want to maintain compatibility with Java 5 VM's + // These types don't exist in Java 5 + private static final int NVARCHAR = -9; + private static final int NCHAR = -15; + private static final int LONGNVARCHAR = -16; + private static final int NCLOB = 2011; + + public String[] getColumnNames(ResultSet rs) throws SQLException { + List names = new ArrayList(); + ResultSetMetaData metadata = rs.getMetaData(); + + for (int i = 0; i < metadata.getColumnCount(); i++) { + names.add(metadata.getColumnName(i+1)); + } + + String[] nameArray = new String[names.size()]; + return names.toArray(nameArray); + } + + public String[] getColumnValues(ResultSet rs) throws SQLException, IOException { + + List values = new ArrayList(); + ResultSetMetaData metadata = rs.getMetaData(); + + for (int i = 0; i < metadata.getColumnCount(); i++) { + values.add(getColumnValue(rs, metadata.getColumnType(i + 1), i + 1)); + } + + String[] valueArray = new String[values.size()]; + return values.toArray(valueArray); + } + + private String handleObject(Object obj){ + return obj == null ? "" : String.valueOf(obj); + } + + private String handleBigDecimal(BigDecimal decimal) { + return decimal == null ? "" : decimal.toString(); + } + + private String handleLong(ResultSet rs, int columnIndex) throws SQLException { + long lv = rs.getLong(columnIndex); + return rs.wasNull() ? "" : Long.toString(lv); + } + + private String handleInteger(ResultSet rs, int columnIndex) throws SQLException { + int i = rs.getInt(columnIndex); + return rs.wasNull() ? "" : Integer.toString(i); + } + + private String handleDate(ResultSet rs, int columnIndex) throws SQLException { + java.sql.Date date = rs.getDate(columnIndex); + String value = null; + if (date != null) { + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); + value = dateFormat.format(date); + } + return value; + } + + private String handleTime(Time time) { + return time == null ? null : time.toString(); + } + + private String handleTimestamp(Timestamp timestamp) { + SimpleDateFormat timeFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); + return timestamp == null ? null : timeFormat.format(timestamp); + } + + private String getColumnValue(ResultSet rs, int colType, int colIndex) + throws SQLException, IOException { + + String value = ""; + + switch (colType) + { + case Types.BIT: + case Types.JAVA_OBJECT: + value = handleObject(rs.getObject(colIndex)); + break; + case Types.BOOLEAN: + boolean b = rs.getBoolean(colIndex); + value = Boolean.valueOf(b).toString(); + break; + case NCLOB: // todo : use rs.getNClob + case Types.CLOB: + Clob c = rs.getClob(colIndex); + if (c != null) { + value = read(c); + } + break; + case Types.BIGINT: + value = handleLong(rs, colIndex); + break; + case Types.DECIMAL: + case Types.DOUBLE: + case Types.FLOAT: + case Types.REAL: + case Types.NUMERIC: + value = handleBigDecimal(rs.getBigDecimal(colIndex)); + break; + case Types.INTEGER: + case Types.TINYINT: + case Types.SMALLINT: + value = handleInteger(rs, colIndex); + break; + case Types.DATE: + value = handleDate(rs, colIndex); + break; + case Types.TIME: + value = handleTime(rs.getTime(colIndex)); + break; + case Types.TIMESTAMP: + value = handleTimestamp(rs.getTimestamp(colIndex)); + break; + case NVARCHAR: // todo : use rs.getNString + case NCHAR: // todo : use rs.getNString + case LONGNVARCHAR: // todo : use rs.getNString + case Types.LONGVARCHAR: + case Types.VARCHAR: + case Types.CHAR: + value = rs.getString(colIndex); + break; + default: + value = ""; + } + + + if (value == null) + { + value = ""; + } + + return value; + + } + + private static String read(Clob c) throws SQLException, IOException + { + StringBuilder sb = new StringBuilder( (int) c.length()); + Reader r = c.getCharacterStream(); + char[] cbuf = new char[CLOBBUFFERSIZE]; + int n; + while ((n = r.read(cbuf, 0, cbuf.length)) != -1) { + sb.append(cbuf, 0, n); + } + return sb.toString(); + } +} diff --git a/au/com/bytecode/opencsv/bean/ColumnPositionMappingStrategy.java b/au/com/bytecode/opencsv/bean/ColumnPositionMappingStrategy.java new file mode 100644 index 0000000..86db1d1 --- /dev/null +++ b/au/com/bytecode/opencsv/bean/ColumnPositionMappingStrategy.java @@ -0,0 +1,37 @@ +package au.com.bytecode.opencsv.bean; + +import au.com.bytecode.opencsv.CSVReader; + +import java.io.IOException; + +/** + Copyright 2007 Kyle Miller. + + Licensed 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. + */ + +public class ColumnPositionMappingStrategy extends HeaderColumnNameMappingStrategy { + private String[] columnMapping = new String[] {}; + public void captureHeader(CSVReader reader) throws IOException { + //do nothing, first line is not header + } + protected String getColumnName(int col) { + return (null != columnMapping && col < columnMapping.length) ? columnMapping[col] : null ; + } + public String[] getColumnMapping() { + return columnMapping != null ? columnMapping.clone() : null; + } + public void setColumnMapping(String[] columnMapping) { + this.columnMapping = columnMapping != null ? columnMapping.clone() : null; + } +} diff --git a/au/com/bytecode/opencsv/bean/CsvToBean.java b/au/com/bytecode/opencsv/bean/CsvToBean.java new file mode 100644 index 0000000..1d12cb6 --- /dev/null +++ b/au/com/bytecode/opencsv/bean/CsvToBean.java @@ -0,0 +1,119 @@ +package au.com.bytecode.opencsv.bean; + +/** + Copyright 2007 Kyle Miller. + + Licensed 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. + */ + +import au.com.bytecode.opencsv.CSVReader; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.beans.PropertyEditor; +import java.beans.PropertyEditorManager; +import java.io.Reader; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CsvToBean { + private Map, PropertyEditor> editorMap = null; + + public CsvToBean() { + } + + public List parse(MappingStrategy mapper, Reader reader) { + return parse(mapper, new CSVReader(reader)); + } + + public List parse(MappingStrategy mapper, CSVReader csv) { + try { + mapper.captureHeader(csv); + String[] line; + List list = new ArrayList(); + while (null != (line = csv.readNext())) { + T obj = processLine(mapper, line); + list.add(obj); // TODO: (Kyle) null check object + } + return list; + } catch (Exception e) { + throw new RuntimeException("Error parsing CSV!", e); + } + } + + protected T processLine(MappingStrategy mapper, String[] line) throws IllegalAccessException, InvocationTargetException, InstantiationException, IntrospectionException { + T bean = mapper.createBean(); + for (int col = 0; col < line.length; col++) { + PropertyDescriptor prop = mapper.findDescriptor(col); + if (null != prop) { + String value = checkForTrim(line[col], prop); + Object obj = convertValue(value, prop); + prop.getWriteMethod().invoke(bean, obj); + } + } + return bean; + } + + private String checkForTrim(String s, PropertyDescriptor prop) { + return trimmableProperty(prop) ? s.trim() : s; + } + + private boolean trimmableProperty(PropertyDescriptor prop) { + return !prop.getPropertyType().getName().contains("String"); + } + + protected Object convertValue(String value, PropertyDescriptor prop) throws InstantiationException, IllegalAccessException { + PropertyEditor editor = getPropertyEditor(prop); + Object obj = value; + if (null != editor) { + editor.setAsText(value); + obj = editor.getValue(); + } + return obj; + } + + private PropertyEditor getPropertyEditorValue(Class cls) { + if (editorMap == null) { + editorMap = new HashMap, PropertyEditor>(); + } + + PropertyEditor editor = editorMap.get(cls); + + if (editor == null) { + editor = PropertyEditorManager.findEditor(cls); + addEditorToMap(cls, editor); + } + + return editor; + } + + private void addEditorToMap(Class cls, PropertyEditor editor) { + if (editor != null) { + editorMap.put(cls, editor); + } + } + + + /* + * Attempt to find custom property editor on descriptor first, else try the propery editor manager. + */ + protected PropertyEditor getPropertyEditor(PropertyDescriptor desc) throws InstantiationException, IllegalAccessException { + Class cls = desc.getPropertyEditorClass(); + if (null != cls) return (PropertyEditor) cls.newInstance(); + return getPropertyEditorValue(desc.getPropertyType()); + } + +} diff --git a/au/com/bytecode/opencsv/bean/HeaderColumnNameMappingStrategy.java b/au/com/bytecode/opencsv/bean/HeaderColumnNameMappingStrategy.java new file mode 100644 index 0000000..b9c1b0d --- /dev/null +++ b/au/com/bytecode/opencsv/bean/HeaderColumnNameMappingStrategy.java @@ -0,0 +1,84 @@ +package au.com.bytecode.opencsv.bean; + +import au.com.bytecode.opencsv.CSVReader; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * Copyright 2007 Kyle Miller. + *

+ * Licensed 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. + */ + +public class HeaderColumnNameMappingStrategy implements MappingStrategy { + protected String[] header; + protected Map descriptorMap = null; + protected Class type; + + public void captureHeader(CSVReader reader) throws IOException { + header = reader.readNext(); + } + + public PropertyDescriptor findDescriptor(int col) throws IntrospectionException { + String columnName = getColumnName(col); + return (null != columnName && columnName.trim().length() > 0) ? findDescriptor(columnName) : null; + } + + protected String getColumnName(int col) { + return (null != header && col < header.length) ? header[col] : null; + } + + protected PropertyDescriptor findDescriptor(String name) throws IntrospectionException { + if (null == descriptorMap) descriptorMap = loadDescriptorMap(getType()); //lazy load descriptors + return descriptorMap.get(name.toUpperCase().trim()); + } + + protected boolean matches(String name, PropertyDescriptor desc) { + return desc.getName().equals(name.trim()); + } + + protected Map loadDescriptorMap(Class cls) throws IntrospectionException { + Map map = new HashMap(); + + PropertyDescriptor[] descriptors; + descriptors = loadDescriptors(getType()); + for (PropertyDescriptor descriptor : descriptors) { + map.put(descriptor.getName().toUpperCase().trim(), descriptor); + } + + return map; + } + + private PropertyDescriptor[] loadDescriptors(Class cls) throws IntrospectionException { + BeanInfo beanInfo = Introspector.getBeanInfo(cls); + return beanInfo.getPropertyDescriptors(); + } + + public T createBean() throws InstantiationException, IllegalAccessException { + return type.newInstance(); + } + + public Class getType() { + return type; + } + + public void setType(Class type) { + this.type = type; + } +} diff --git a/au/com/bytecode/opencsv/bean/HeaderColumnNameTranslateMappingStrategy.java b/au/com/bytecode/opencsv/bean/HeaderColumnNameTranslateMappingStrategy.java new file mode 100644 index 0000000..49365d1 --- /dev/null +++ b/au/com/bytecode/opencsv/bean/HeaderColumnNameTranslateMappingStrategy.java @@ -0,0 +1,34 @@ +package au.com.bytecode.opencsv.bean; +import java.util.HashMap; +import java.util.Map; + +/** + Copyright 2007,2010 Kyle Miller. + + Licensed 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. + */ + +public class HeaderColumnNameTranslateMappingStrategy extends HeaderColumnNameMappingStrategy { + private Map columnMapping = new HashMap(); + protected String getColumnName(int col) { + return col < header.length ? columnMapping.get(header[col].toUpperCase()) : null; + } + public Map getColumnMapping() { + return columnMapping; + } + public void setColumnMapping(Map columnMapping) { + for (String key : columnMapping.keySet()) { + this.columnMapping.put(key.toUpperCase(), columnMapping.get(key)); + } + } +} diff --git a/au/com/bytecode/opencsv/bean/MappingStrategy.java b/au/com/bytecode/opencsv/bean/MappingStrategy.java new file mode 100644 index 0000000..528e8de --- /dev/null +++ b/au/com/bytecode/opencsv/bean/MappingStrategy.java @@ -0,0 +1,46 @@ +package au.com.bytecode.opencsv.bean; + + +/** + Copyright 2007 Kyle Miller. + + Licensed 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. + */ + +import au.com.bytecode.opencsv.CSVReader; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.io.IOException; + +public interface MappingStrategy { + + /** + * Implementation will have to return a property descriptor from a bean based on the current column. + * @param col the column to find the description for + * @throws java.beans.IntrospectionException + * @return the related PropertyDescriptor + */ + public abstract PropertyDescriptor findDescriptor(int col) throws IntrospectionException; + + public abstract T createBean() throws InstantiationException, IllegalAccessException; + + /** + * Implementation of this method can grab the header line before parsing begins to use to map columns + * to bean properties. + * @param reader the CSVReader to use for header parsing + * @throws java.io.IOException if parsing fails + */ + public void captureHeader(CSVReader reader) throws IOException; + +} \ No newline at end of file diff --git a/au/com/bytecode/opencsv/bean/package.html b/au/com/bytecode/opencsv/bean/package.html new file mode 100644 index 0000000..92fef43 --- /dev/null +++ b/au/com/bytecode/opencsv/bean/package.html @@ -0,0 +1,12 @@ + + + + + +

+A simple bean binding interface for use with opencsv. +

+
+opencsv.sourceforge.net + + diff --git a/au/com/bytecode/opencsv/package.html b/au/com/bytecode/opencsv/package.html new file mode 100644 index 0000000..00b160e --- /dev/null +++ b/au/com/bytecode/opencsv/package.html @@ -0,0 +1,12 @@ + + + + + +

+A very simple CSV parser for Java released under a commercial-friendly license. +

+
+opencsv.sourceforge.net + + diff --git a/gource.sh b/gource.sh new file mode 100755 index 0000000..fe99eb2 --- /dev/null +++ b/gource.sh @@ -0,0 +1,3 @@ +#gource --file-idle-time 0 --camera-mode overview --title "Minecraft Coder Pack" -s 2 --hide-filenames --stop-at-end --disable-progress --output-ppm-stream - | ffmpeg -y -r 60 -b 6000K -f image2pipe -vcodec ppm -i - -vcodec libtheora out.ogg +gource --file-idle-time 0 --camera-mode overview --title "Waila" -s 2 --hide-filenames --stop-at-end --disable-progress --output-ppm-stream - | ffmpeg -y -f image2pipe -vcodec ppm -i - -vpre libx264-medium -vcodec libx264 out_small.mkv + diff --git a/mcp/mobius/waila/addons/ic2/IC2Module.java b/mcp/mobius/waila/addons/ic2/IC2Module.java index 03827f2..2ee62e9 100644 --- a/mcp/mobius/waila/addons/ic2/IC2Module.java +++ b/mcp/mobius/waila/addons/ic2/IC2Module.java @@ -2,6 +2,7 @@ package mcp.mobius.waila.addons.ic2; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.List; import java.util.logging.Level; import net.minecraft.item.ItemStack; @@ -11,6 +12,7 @@ import mcp.mobius.waila.mod_Waila; import mcp.mobius.waila.api.IWailaDataAccessor; import mcp.mobius.waila.api.impl.ConfigHandler; import mcp.mobius.waila.api.impl.ModuleRegistrar; +import mcp.mobius.waila.tools.AccessHelper; public class IC2Module { @@ -147,7 +149,10 @@ public class IC2Module { if (!inventory.hasKey("upgrade")) return null; NBTTagList nbtupgrades = inventory.getCompoundTag("upgrade").getTagList("Contents"); - for (Object subobj : nbtupgrades.tagList){ + + List tagList = (List)AccessHelper.getField("net.minecraft.nbt.NBTTagList", "tagList", nbtupgrades); + + for (Object subobj : tagList){ NBTTagCompound subtag = (NBTTagCompound)subobj; int id = subtag.getShort("id"); int meta = subtag.getShort("Damage"); diff --git a/mcp/mobius/waila/gui/screens/config/ScreenModuleChoice.java b/mcp/mobius/waila/gui/screens/config/ScreenModuleChoice.java index 89f1903..2815ec0 100644 --- a/mcp/mobius/waila/gui/screens/config/ScreenModuleChoice.java +++ b/mcp/mobius/waila/gui/screens/config/ScreenModuleChoice.java @@ -8,7 +8,6 @@ import mcp.mobius.waila.gui.widgets.LayoutBase; import mcp.mobius.waila.gui.widgets.WidgetGeometry; import mcp.mobius.waila.gui.widgets.buttons.ButtonContainer; import mcp.mobius.waila.gui.widgets.buttons.ButtonScreenChange; -import mcp.mobius.waila.gui_old.widget_old.ButtonChangeScreen; import net.minecraft.client.gui.GuiScreen; public class ScreenModuleChoice extends ScreenBase { diff --git a/mcp/mobius/waila/gui/screens/config/ScreenModuleConfig.java b/mcp/mobius/waila/gui/screens/config/ScreenModuleConfig.java index 80f2966..4b8e27a 100644 --- a/mcp/mobius/waila/gui/screens/config/ScreenModuleConfig.java +++ b/mcp/mobius/waila/gui/screens/config/ScreenModuleConfig.java @@ -11,8 +11,6 @@ import mcp.mobius.waila.gui.widgets.buttons.ButtonBooleanConfigRemote; import mcp.mobius.waila.gui.widgets.buttons.ButtonContainer; import mcp.mobius.waila.gui.widgets.buttons.ButtonContainerLabel; import mcp.mobius.waila.gui.widgets.buttons.ButtonScreenChange; -import mcp.mobius.waila.gui_old.widget_old.ButtonConfigOption; -import mcp.mobius.waila.gui_old.widget_old.ButtonConfigRemote; import net.minecraft.client.gui.GuiScreen; public class ScreenModuleConfig extends ScreenBase { diff --git a/mcp/mobius/waila/gui/truetyper/FontLoader.java b/mcp/mobius/waila/gui/truetyper/FontLoader.java index 59d3885..232bb83 100644 --- a/mcp/mobius/waila/gui/truetyper/FontLoader.java +++ b/mcp/mobius/waila/gui/truetyper/FontLoader.java @@ -57,7 +57,7 @@ public class FontLoader{ Font font; TrueTypeFont out = null; try { - font = Font.createFont(type, Minecraft.getMinecraft().func_110442_L().func_110536_a(res).func_110527_b()); + font = Font.createFont(type, Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream()); font = font.deriveFont(defSize); out = new TrueTypeFont(font, antialias); } catch (Exception e) { diff --git a/mcp/mobius/waila/gui/widgets/PictureDisplay.java b/mcp/mobius/waila/gui/widgets/PictureDisplay.java index 1fd5c9c..9faccc7 100644 --- a/mcp/mobius/waila/gui/widgets/PictureDisplay.java +++ b/mcp/mobius/waila/gui/widgets/PictureDisplay.java @@ -22,7 +22,7 @@ public class PictureDisplay extends WidgetBase { this.saveGLState(); GL11.glPushMatrix(); - this.texManager.func_110577_a(texture); + this.texManager.bindTexture(texture); UIHelper.drawTexture(pos.getX(), pos.getY(), this.getSize().getX(), this.getSize().getY()); GL11.glPopMatrix(); diff --git a/mcp/mobius/waila/gui/widgets/PictureSwitch.java b/mcp/mobius/waila/gui/widgets/PictureSwitch.java index 7faf598..a8b87f5 100644 --- a/mcp/mobius/waila/gui/widgets/PictureSwitch.java +++ b/mcp/mobius/waila/gui/widgets/PictureSwitch.java @@ -27,7 +27,7 @@ public class PictureSwitch extends WidgetBase { ResourceLocation texture = mouseOver ? this.texture2 : this.texture1; GL11.glPushMatrix(); - this.texManager.func_110577_a(texture); + this.texManager.bindTexture(texture); UIHelper.drawTexture(pos.getX(), pos.getY(), this.getSize().getX(), this.getSize().getY()); GL11.glPopMatrix(); diff --git a/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java b/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java index 8856fb9..046dd91 100644 --- a/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java +++ b/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java @@ -42,7 +42,7 @@ public abstract class ButtonBase extends WidgetBase { if (this.mouseOver) texOffset = 1; - this.mc.func_110434_K().func_110577_a(widgetsTexture); + this.mc.getTextureManager().bindTexture(widgetsTexture); UIHelper.drawTexture(this.getPos().getX(), this.getPos().getY(), this.getSize().getX(), this.getSize().getY(), 0, 66 + texOffset*20, 200, 20); this.loadGLState(); diff --git a/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java b/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java index ad357f2..c4df556 100644 --- a/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java +++ b/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java @@ -44,7 +44,7 @@ public class ButtonBooleanConfigRemote extends ButtonBooleanConfig { else{ this.saveGLState(); int texOffset = -1; - this.mc.func_110434_K().func_110577_a(widgetsTexture); + this.mc.getTextureManager().bindTexture(widgetsTexture); UIHelper.drawTexture(this.getPos().getX(), this.getPos().getY(), this.getSize().getX(), this.getSize().getY(), 0, 66 + texOffset*20, 200, 20); this.loadGLState(); } diff --git a/mcp/mobius/waila/gui/widgets/movable/PictureMovableRC.java b/mcp/mobius/waila/gui/widgets/movable/PictureMovableRC.java index 6ba702f..ce3fdc4 100644 --- a/mcp/mobius/waila/gui/widgets/movable/PictureMovableRC.java +++ b/mcp/mobius/waila/gui/widgets/movable/PictureMovableRC.java @@ -58,7 +58,7 @@ public class PictureMovableRC extends WidgetBase { this.saveGLState(); GL11.glPushMatrix(); - this.texManager.func_110577_a(texture); + this.texManager.bindTexture(texture); UIHelper.drawTexture(pos.getX(), pos.getY(), this.getSize().getX(), this.getSize().getY()); GL11.glPopMatrix(); diff --git a/mcp/mobius/waila/gui_old/BaseWailaScreen.java b/mcp/mobius/waila/gui_old/BaseWailaScreen.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/BaseWailaScreen.java rename to mcp/mobius/waila/gui_old/BaseWailaScreen.java.bak diff --git a/mcp/mobius/waila/gui_old/GuiIngameWiki.java b/mcp/mobius/waila/gui_old/GuiIngameWiki.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/GuiIngameWiki.java rename to mcp/mobius/waila/gui_old/GuiIngameWiki.java.bak diff --git a/mcp/mobius/waila/gui_old/GuiTechTree.java b/mcp/mobius/waila/gui_old/GuiTechTree.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/GuiTechTree.java rename to mcp/mobius/waila/gui_old/GuiTechTree.java.bak diff --git a/mcp/mobius/waila/gui_old/NEI/CraftingTreeNode.java b/mcp/mobius/waila/gui_old/NEI/CraftingTreeNode.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/NEI/CraftingTreeNode.java rename to mcp/mobius/waila/gui_old/NEI/CraftingTreeNode.java.bak diff --git a/mcp/mobius/waila/gui_old/NEI/HandlerTechTree.java b/mcp/mobius/waila/gui_old/NEI/HandlerTechTree.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/NEI/HandlerTechTree.java rename to mcp/mobius/waila/gui_old/NEI/HandlerTechTree.java.bak diff --git a/mcp/mobius/waila/gui_old/NEI/HandlerWiki.java b/mcp/mobius/waila/gui_old/NEI/HandlerWiki.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/NEI/HandlerWiki.java rename to mcp/mobius/waila/gui_old/NEI/HandlerWiki.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/BaseWidget.java b/mcp/mobius/waila/gui_old/widget/BaseWidget.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/BaseWidget.java rename to mcp/mobius/waila/gui_old/widget/BaseWidget.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/ComponentDisplay.java b/mcp/mobius/waila/gui_old/widget/ComponentDisplay.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/ComponentDisplay.java rename to mcp/mobius/waila/gui_old/widget/ComponentDisplay.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/ContainerTable.java b/mcp/mobius/waila/gui_old/widget/ContainerTable.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/ContainerTable.java rename to mcp/mobius/waila/gui_old/widget/ContainerTable.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/DraggableViewport.java b/mcp/mobius/waila/gui_old/widget/DraggableViewport.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/DraggableViewport.java rename to mcp/mobius/waila/gui_old/widget/DraggableViewport.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/IWidget.java b/mcp/mobius/waila/gui_old/widget/IWidget.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/IWidget.java rename to mcp/mobius/waila/gui_old/widget/IWidget.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/Label.java b/mcp/mobius/waila/gui_old/widget/Label.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/Label.java rename to mcp/mobius/waila/gui_old/widget/Label.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/StackDisplay.java b/mcp/mobius/waila/gui_old/widget/StackDisplay.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/StackDisplay.java rename to mcp/mobius/waila/gui_old/widget/StackDisplay.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/VerticalScrollBar.java b/mcp/mobius/waila/gui_old/widget/VerticalScrollBar.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/VerticalScrollBar.java rename to mcp/mobius/waila/gui_old/widget/VerticalScrollBar.java.bak diff --git a/mcp/mobius/waila/gui_old/widget/WikiReader.java b/mcp/mobius/waila/gui_old/widget/WikiReader.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget/WikiReader.java rename to mcp/mobius/waila/gui_old/widget/WikiReader.java.bak diff --git a/mcp/mobius/waila/gui_old/widget_old/Button2States.java b/mcp/mobius/waila/gui_old/widget_old/Button2States.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget_old/Button2States.java rename to mcp/mobius/waila/gui_old/widget_old/Button2States.java.bak diff --git a/mcp/mobius/waila/gui_old/widget_old/ButtonChangeScreen.java b/mcp/mobius/waila/gui_old/widget_old/ButtonChangeScreen.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget_old/ButtonChangeScreen.java rename to mcp/mobius/waila/gui_old/widget_old/ButtonChangeScreen.java.bak diff --git a/mcp/mobius/waila/gui_old/widget_old/ButtonConfigNEI.java b/mcp/mobius/waila/gui_old/widget_old/ButtonConfigNEI.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget_old/ButtonConfigNEI.java rename to mcp/mobius/waila/gui_old/widget_old/ButtonConfigNEI.java.bak diff --git a/mcp/mobius/waila/gui_old/widget_old/ButtonConfigOption.java b/mcp/mobius/waila/gui_old/widget_old/ButtonConfigOption.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget_old/ButtonConfigOption.java rename to mcp/mobius/waila/gui_old/widget_old/ButtonConfigOption.java.bak diff --git a/mcp/mobius/waila/gui_old/widget_old/ButtonConfigRemote.java b/mcp/mobius/waila/gui_old/widget_old/ButtonConfigRemote.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget_old/ButtonConfigRemote.java rename to mcp/mobius/waila/gui_old/widget_old/ButtonConfigRemote.java.bak diff --git a/mcp/mobius/waila/gui_old/widget_old/ContainerButtons.java b/mcp/mobius/waila/gui_old/widget_old/ContainerButtons.java.bak similarity index 100% rename from mcp/mobius/waila/gui_old/widget_old/ContainerButtons.java rename to mcp/mobius/waila/gui_old/widget_old/ContainerButtons.java.bak diff --git a/mcp/mobius/waila/mod_Waila.java b/mcp/mobius/waila/mod_Waila.java index abf1e83..7e79614 100644 --- a/mcp/mobius/waila/mod_Waila.java +++ b/mcp/mobius/waila/mod_Waila.java @@ -27,6 +27,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; import codechicken.core.CommonUtils; import codechicken.lib.lang.LangUtil; import cpw.mods.fml.client.registry.KeyBindingRegistry; @@ -54,7 +55,7 @@ import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.ItemData; import cpw.mods.fml.common.registry.LanguageRegistry; -@Mod(modid="Waila", name="Waila", version="1.4.4", dependencies="required-after:NotEnoughItems") +@Mod(modid="Waila", name="Waila", version="1.4.5", dependencies="required-after:NotEnoughItems") @NetworkMod(channels = {"Waila"},clientSideRequired=false, serverSideRequired=false, connectionHandler = WailaConnectionHandler.class, packetHandler = WailaPacketHandler.class, versionBounds="[1.3.0,)") @@ -127,7 +128,7 @@ public class mod_Waila { if (ConfigHandler.instance().getConfig(Constants.CFG_WAILA_KEYBIND)){ for (String key: ModIdentification.keyhandlerStrings.keySet()){ - String orig = I18n.func_135053_a(key); + String orig = I18n.getString(key); if (orig.equals(key)) orig = LanguageRegistry.instance().getStringLocalization(key); if (orig.equals(key)) @@ -162,6 +163,12 @@ public class mod_Waila { @Subscribe public void loadComplete(FMLLoadCompleteEvent event) { proxy.registerMods(); + + String[] ores = OreDictionary.getOreNames(); + for (String s : ores) + for (ItemStack stack : OreDictionary.getOres(s)) + System.out.printf("%s : %s\n", s, stack); + } @IMCCallback