aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/softsynth/util
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2014-12-30 17:54:28 -0800
committerPhil Burk <[email protected]>2014-12-30 17:54:28 -0800
commit6bed96c300097e29760330afaafeba44bb943470 (patch)
tree4bee0dbd44087c5b88eaad251668a4e3f6350475 /src/com/softsynth/util
parente4cb838aa8a9eff7332069c421001df37689af91 (diff)
Remove obsolete com.softsynth.util package.
Fix a few warnings.
Diffstat (limited to 'src/com/softsynth/util')
-rw-r--r--src/com/softsynth/util/AlertBox.java84
-rw-r--r--src/com/softsynth/util/FileSearch.java193
-rw-r--r--src/com/softsynth/util/IndentingWriter.java94
-rw-r--r--src/com/softsynth/util/InsetPanel.java78
-rw-r--r--src/com/softsynth/util/Logger.java133
-rw-r--r--src/com/softsynth/util/NumericOutput.java187
-rw-r--r--src/com/softsynth/util/RandomOutputStream.java60
-rw-r--r--src/com/softsynth/util/Semaphore.java36
-rw-r--r--src/com/softsynth/util/TextOutput.java186
-rw-r--r--src/com/softsynth/util/XMLListener.java36
-rw-r--r--src/com/softsynth/util/XMLPrinter.java102
-rw-r--r--src/com/softsynth/util/XMLReader.java328
-rw-r--r--src/com/softsynth/util/XMLTools.java122
-rw-r--r--src/com/softsynth/util/XMLWriter.java122
14 files changed, 0 insertions, 1761 deletions
diff --git a/src/com/softsynth/util/AlertBox.java b/src/com/softsynth/util/AlertBox.java
deleted file mode 100644
index 11891aa..0000000
--- a/src/com/softsynth/util/AlertBox.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2000 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.awt.BorderLayout;
-import java.awt.Button;
-import java.awt.Component;
-import java.awt.Dialog;
-import java.awt.Frame;
-import java.awt.Panel;
-import java.awt.TextArea;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-/**
- * AlertBox class to display error messages.
- *
- * @author (C) 2000 Phil Burk, SoftSynth.com
- */
-
-public class AlertBox extends Dialog {
- TextArea textArea;
- Button okButton;
- Button abortButton;
-
- public AlertBox(Frame frame, String title) {
- super(frame, title, true);
- setLayout(new BorderLayout());
- setSize(620, 200);
- textArea = new TextArea("", 6, 80, TextArea.SCROLLBARS_BOTH);
- add("Center", textArea);
-
- Panel panel = new Panel();
- add("South", panel);
-
- panel.add(okButton = new Button("Acknowledge"));
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- hide();
- }
- });
-
- panel.add(abortButton = new Button("Abort"));
- abortButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
-
- validate();
- }
-
- /**
- * Search up the component hierarchy to find the first Frame containing the component.
- */
- public static Frame getFrame(Component c) {
- do {
- if (c instanceof Frame)
- return (Frame) c;
- } while ((c = c.getParent()) != null);
- return null;
- }
-
- public void showError(String msg) {
- textArea.setText(msg);
- show();
- }
-}
diff --git a/src/com/softsynth/util/FileSearch.java b/src/com/softsynth/util/FileSearch.java
deleted file mode 100644
index f691728..0000000
--- a/src/com/softsynth/util/FileSearch.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright 1999 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.Enumeration;
-import java.util.Vector;
-
-class WildcardFilenameFilter implements FilenameFilter {
- String pattern;
-
- public WildcardFilenameFilter(String pattern) {
- this.pattern = pattern;
- }
-
- /* abc*frog*xyz =?= abctreefroglegxyz */
- static boolean wildMatch(String pattern, String candidate) {
- int starPos = pattern.indexOf('*');
- // System.out.println("------pattern = " + pattern + ", candidate = " + candidate +
- // ", starPos = " + starPos );
- if (starPos < 0)
- return (pattern.equalsIgnoreCase(candidate));
- else if (starPos > 0) {
- // System.out.println("------ beginning, pattern = " + pattern + ", candidate = " +
- // candidate );
- if (pattern.regionMatches(true, 0, candidate, 0, starPos)) {
- /* Recursively check remainder of string. */
- return wildMatch(pattern.substring(starPos), candidate.substring(starPos));
- }
- return false;
- } else {
- /* Compare remainder of string. */
- // System.out.println("------ remainder, pattern = " + pattern + ", candidate = " +
- // candidate );
- if (pattern.regionMatches(true, 1, candidate, 0, candidate.length()))
- return true;
-
- for (int i = 0; i < candidate.length(); i++) {
- if (wildMatch(pattern.substring(1), candidate.substring(i)))
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean accept(File dir, String name) {
- return wildMatch(pattern, name);
- }
-}
-
-/**
- * Wildcard search for files in directory.
- *
- * @author Phil Burk (C) 1999 SoftSynth.com
- */
-
-public class FileSearch {
- /**
- * Expand vector of filenames that may contain wildcards into a new vector of filenames without
- * wildcards.
- */
- public static Vector expandFilenames(Vector filenames) {
- Vector expandedFilenames = new Vector();
- Enumeration e = filenames.elements();
- while (e.hasMoreElements()) {
- expandFilename((String) e.nextElement(), expandedFilenames);
- }
- return expandedFilenames;
- }
-
- /**
- * Expand filename that may contain wildcards and add to a vector of filenames without
- * wildcards.
- */
- public static void expandFilename(String filename, Vector expandedFilenames) {
- int lastSepPos = filename.lastIndexOf(File.separatorChar);
-
- // System.out.println("expandFilename: separator = " + File.separatorChar + " , index = " +
- // lastSepPos );
-
- int starPos = filename.indexOf('*');
- if (starPos < 0) {
- expandedFilenames.addElement(filename);
- } else if (starPos < lastSepPos) {
- TextOutput.error("Wildcard * not allowed in directory names! " + filename);
- } else {
- String parent;
- String wildFile;
- if (lastSepPos < 0) {
- parent = ".";
- wildFile = filename;
- } else {
- parent = filename.substring(0, lastSepPos);
- wildFile = filename.substring(lastSepPos + 1);
- }
-
- File dir = new File(parent);
- // System.out.println("expandFilename: parent = " + parent + " , dir = " + dir );
- if (!dir.exists()) {
- TextOutput.error("Invalid directory = " + parent);
- }
-
- String[] files = dir.list(new WildcardFilenameFilter(wildFile));
- if (files == null)
- return;
- for (int i = 0; i < files.length; i++) {
- expandedFilenames.addElement(parent + File.separatorChar + files[i]);
- }
- }
- }
-
- /**
- * Extract file name from full pathname. For example, if pathname is "/usr/data/report.txt" then
- * the output will be "report.txt".
- */
- public static String removeParent(String pathName) {
- int lastSepPos = pathName.lastIndexOf(File.separatorChar);
- if (lastSepPos < 0) {
- return pathName;
- } else {
- return pathName.substring(lastSepPos + 1);
- }
- }
-
- /**
- * Remove any dot extension from file name. For example, if pathname is "/usr/data/report.txt"
- * then the output will be "/usr/data/report".
- */
- public static String removeExtension(String pathName) {
- int lastDotPos = pathName.lastIndexOf('.');
- if (lastDotPos > 0) {
- return pathName.substring(0, lastDotPos);
- } else {
- return pathName;
- }
- }
-
- public static void main(String args[]) {
- System.out.println("FileSearch - by Phil Burk");
- boolean result;
- result = WildcardFilenameFilter.wildMatch("abc*frog*xyz", "abctreefroglegxyz");
- System.out.println("result = " + result);
- result = WildcardFilenameFilter.wildMatch("abc*frog*xyz", "abctreefrxglegxyz");
- System.out.println("result = " + result);
-
- test();
- }
-
- static void test() {
- Vector expandedFilenames = new Vector();
- expandFilename("../data/ov*.mid", expandedFilenames);
- Enumeration e = expandedFilenames.elements();
- while (e.hasMoreElements()) {
- String name = (String) e.nextElement();
- System.out.println("file = " + name);
- }
- }
-
- /********************************************************
- * Create directory if it doesn't exist.
- */
- public static void createDirectoryIfNeeded(String directoryName) throws SecurityException {
- createDirectoryIfNeeded(new File(directoryName));
- }
-
- /********************************************************
- * Create directory with the given name if it doesn't exist.
- */
- public static void createDirectoryIfNeeded(File dir) throws SecurityException {
- if (!dir.isDirectory()) {
- if (!dir.mkdirs()) {
- TextOutput.error("Could not make output directory " + dir.getAbsolutePath());
- }
- }
- }
-
-}
diff --git a/src/com/softsynth/util/IndentingWriter.java b/src/com/softsynth/util/IndentingWriter.java
deleted file mode 100644
index bb9ed99..0000000
--- a/src/com/softsynth/util/IndentingWriter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2000 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Writer;
-
-/**
- * Write to a file with indentation at the beginning of a line. One advantage of using a PrintWriter
- * is that it automatically handles line terminators properly on different hosts.
- *
- * @author Phil Burk, (C) 2000 SoftSynth.com All Rights Reserved
- */
-
-public class IndentingWriter extends PrintWriter {
- int spacesPerIndentation = 4;
- int indentation = 0;
- int position = 0;
-
- public IndentingWriter(OutputStream stream) {
- super(stream, true);
- }
-
- public IndentingWriter(Writer outputStreamWriter) {
- super(outputStreamWriter, true);
- }
-
- public void setIndentation(int level) {
- indentation = level;
- }
-
- public int getIndentation() {
- return indentation;
- }
-
- /**
- * Increase level of indentation by one.
- */
- public void indent() {
- indentation++;
- }
-
- /**
- * Decrease level of indentation by one. Don't let level go below zero.
- */
- public void undent() {
- indentation--;
- if (indentation < 0)
- indentation = 0;
- }
-
- /**
- * Print string. If at left margin, add spaces for current level of indentation.
- */
- @Override
- public void print(String s) {
- if (position == 0) {
- int numSpaces = indentation * spacesPerIndentation;
- for (int i = 0; i < numSpaces; i++)
- print(' ');
- position += numSpaces;
- }
- super.print(s);
- // System.out.print(s);
- position += s.length();
- }
-
- @Override
- public void println() {
- super.println();
- position = 0;
- }
-
- @Override
- public void println(String s) {
- print(s);
- println();
- }
-}
diff --git a/src/com/softsynth/util/InsetPanel.java b/src/com/softsynth/util/InsetPanel.java
deleted file mode 100644
index d1b2794..0000000
--- a/src/com/softsynth/util/InsetPanel.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Insets;
-import java.awt.Panel;
-
-/**
- * Panel with insets that can be used to border a centered component.
- *
- * @author (C) 1997 Phil Burk, SoftSynth.com
- */
-public class InsetPanel extends Panel {
- int border; /* Pixels in border. */
- static final int default_border = 6;
-
- public InsetPanel(Component borderMe) {
- this(borderMe, Color.blue, default_border);
- }
-
- public InsetPanel(Component borderMe, Color borderColor) {
- this(borderMe, borderColor, default_border);
- }
-
- public InsetPanel(Component borderMe, int border) {
- this(borderMe, Color.blue, border);
- }
-
- /**
- * @param borderMe component to be centerred in this panel. Typically another Panel.
- * @param borderColor color to paint the border.
- * @param border width in pixels of border.
- */
- public InsetPanel(Component borderMe, Color borderColor, int border) {
- this.border = border;
- setLayout(new BorderLayout());
- /* Force a background for the component so the border shows up. */
- if (borderMe != null) {
- add("Center", borderMe);
- if (borderMe.getBackground() == null)
- borderMe.setBackground(Color.white);
- }
- if (borderColor != null)
- setBackground(borderColor);
- }
-
- @Override
- public Insets insets() {
- return new Insets(border, border, border, border);
- }
-
- /** @param border width in pixels of border. */
- public void setBorder(int borderWidth) {
- border = borderWidth;
- repaint();
- }
-
- public int getBorder() {
- return border;
- }
-}
diff --git a/src/com/softsynth/util/Logger.java b/src/com/softsynth/util/Logger.java
deleted file mode 100644
index 03b2ec6..0000000
--- a/src/com/softsynth/util/Logger.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 1999 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-/**
- * Logger logs output to a file if enabled.
- *
- * @author Phil Burk (C) 1999 SoftSynth.com
- */
-public class Logger {
- FileOutputStream fileStream = null;
- BufferedOutputStream stream = null;
- int column = 0;
- boolean enabled;
- String lineTerminator;
-
- public Logger() {
- lineTerminator = System.getProperty("line.separator", "\n");
- // System.out.println("lineTerminator.length = " + lineTerminator.length() );
- // for( int i=0; i<lineTerminator.length(); i++ )
- // {
- // System.out.println("lineTerminator[" + i + "] = " + ((int)lineTerminator.charAt(i)) );
- // }
- }
-
- public void setEnable(boolean enabled) {
- this.enabled = enabled;
- }
-
- public boolean getEnable() {
- return enabled;
- }
-
- public void log(String msg) {
- if (!enabled)
- return;
-
- if (stream == null)
- System.out.print(msg);
- else {
- try {
- stream.write(msg.getBytes());
- } catch (IOException e) {
- System.err.println("Log File: " + e);
- }
- }
- column += msg.length();
- }
-
- public void logln(String msg) {
- log(msg);
- logln();
- }
-
- public void logln() {
- log(lineTerminator);
- column = 0;
- }
-
- /**
- * Output spaces if needed to position output at desired column. Nothing will be output if
- * already past that column.
- */
- public void advanceToColumn(int toColumn) {
- if (!enabled)
- return;
-
- try {
- for (; column < toColumn; column++) {
- stream.write(' ');
- }
- } catch (IOException e) {
- System.err.println("Log File: " + e);
- }
- }
-
- /**
- * Start a new line if there is already text on current line.
- */
- public void newLine() {
- if (column > 0)
- logln("");
- }
-
- /**
- * Open a log file.
- */
- public void open(String logFileName) throws IOException, SecurityException {
- open(new File(logFileName));
- }
-
- /**
- * Open a log file by name.
- */
- public void open(File logFile) throws IOException, SecurityException {
- // Close any existing log file.
- close();
- // Open a new log file.
- fileStream = new FileOutputStream(logFile);
- // Buffer it so it isn't awfully slow.
- stream = new BufferedOutputStream(fileStream);
- column = 0;
- }
-
- public void close() throws IOException {
- if (stream != null) {
- stream.flush();
- stream.close();
- }
- if (fileStream != null)
- fileStream.close();
- stream = null;
- }
-}
diff --git a/src/com/softsynth/util/NumericOutput.java b/src/com/softsynth/util/NumericOutput.java
deleted file mode 100644
index 92acbdf..0000000
--- a/src/com/softsynth/util/NumericOutput.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright 1999 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-/**
- * Formatted numeric output. Convert integers and floats to strings based on field widths and
- * desired decimal places.
- *
- * @author Phil Burk (C) 1999 SoftSynth.com
- */
-
-public class NumericOutput {
- static char digitToChar(int digit) {
- if (digit > 9) {
- return (char) ('A' + digit - 10);
- } else {
- return (char) ('0' + digit);
- }
- }
-
- public static String integerToString(int n, int width, boolean leadingZeros) {
- return integerToString(n, width, leadingZeros, 10);
- }
-
- public static String integerToString(int n, int width) {
- return integerToString(n, width, false, 10);
- }
-
- public static String integerToString(int n, int width, boolean leadingZeros, int radix) {
- if (width > 32)
- width = 32;
- StringBuffer buf = new StringBuffer();
- long ln = n;
- boolean ifNeg = false;
- // only do sign if decimal
- if (radix != 10) {
- // System.out.println("MASK before : ln = " + ln );
- ln = ln & 0x00000000FFFFFFFFL;
- // System.out.println("MASK after : ln = " + ln );
- } else if (ln < 0) {
- ifNeg = true;
- ln = -ln;
- }
- if (ln == 0) {
- buf.append('0');
- } else {
- // System.out.println(" ln = " + ln );
- while (ln > 0) {
- int rem = (int) (ln % radix);
- buf.append(digitToChar(rem));
- ln = ln / radix;
- }
- }
- if (leadingZeros) {
- int pl = width;
- if (ifNeg)
- pl -= 1;
- for (int i = buf.length(); i < pl; i++)
- buf.append('0');
- }
- if (ifNeg)
- buf.append('-');
- // leading spaces
- for (int i = buf.length(); i < width; i++)
- buf.append(' ');
- // reverse buffer to put characters in correct order
- buf.reverse();
-
- return buf.toString();
- }
-
- /**
- * Convert double to string.
- *
- * @param width = minimum width of formatted string
- * @param places = number of digits displayed after decimal point
- */
- public static String doubleToString(double value, int width, int places) {
- return doubleToString(value, width, places, false);
- }
-
- /**
- * Convert double to string.
- *
- * @param width = minimum width of formatted string
- * @param places = number of digits displayed after decimal point
- */
- public static String doubleToString(double value, int width, int places, boolean leadingZeros) {
- if (width > 32)
- width = 32;
- if (places > 16)
- places = 16;
-
- boolean ifNeg = false;
- if (value < 0.0) {
- ifNeg = true;
- value = -value;
- }
- // round at relevant decimal place
- value += 0.5 * Math.pow(10.0, 0 - places);
- int ival = (int) Math.floor(value);
- // get portion after decimal point as an integer
- int fval = (int) ((value - Math.floor(value)) * Math.pow(10.0, places));
- String result = "";
-
- result += integerToString(ival, 0, false, 10);
- result += ".";
- result += integerToString(fval, places, true, 10);
-
- if (leadingZeros) {
- // prepend leading zeros and {-}
- int zw = width;
- if (ifNeg)
- zw -= 1;
- while (result.length() < zw)
- result = "0" + result;
- if (ifNeg)
- result = "-" + result;
- } else {
- // prepend {-} and leading spaces
- if (ifNeg)
- result = "-" + result;
- while (result.length() < width)
- result = " " + result;
- }
- return result;
- }
-
- static void testInteger(int n) {
- System.out.println("Test " + n + ", 0x" + Integer.toHexString(n) + ", %"
- + Integer.toBinaryString(n));
- System.out.println(" +,8,t,10 = " + integerToString(n, 8, true, 10));
- System.out.println(" +,8,f,10 = " + integerToString(n, 8, false, 10));
- System.out.println(" -,8,t,10 = " + integerToString(-n, 8, true, 10));
- System.out.println(" -,8,f,10 = " + integerToString(-n, 8, false, 10));
- System.out.println(" +,8,t,16 = " + integerToString(n, 8, true, 16));
- System.out.println(" +,8,f,16 = " + integerToString(n, 8, false, 16));
- System.out.println(" -,8,t,16 = " + integerToString(-n, 8, true, 16));
- System.out.println(" -,8,f,16 = " + integerToString(-n, 8, false, 16));
- System.out.println(" +,8,t, 2 = " + integerToString(n, 8, true, 2));
- System.out.println(" +,8,f, 2 = " + integerToString(n, 8, false, 2));
- }
-
- static void testDouble(double value) {
- System.out.println("Test " + value);
- System.out.println(" +,5,1 = " + doubleToString(value, 5, 1));
- System.out.println(" -,5,1 = " + doubleToString(-value, 5, 1));
-
- System.out.println(" +,14,3 = " + doubleToString(value, 14, 3));
- System.out.println(" -,14,3 = " + doubleToString(-value, 14, 3));
-
- System.out.println(" +,6,2,true = " + doubleToString(value, 6, 2, true));
- System.out.println(" -,6,2,true = " + doubleToString(-value, 6, 2, true));
- }
-
- public static void main(String argv[]) {
- System.out.println("Test NumericOutput");
- testInteger(0);
- testInteger(1);
- testInteger(16);
- testInteger(23456);
- testInteger(0x23456);
- testInteger(0x89ABC);
- testDouble(0.0);
- testDouble(0.0678);
- testDouble(0.1234567);
- testDouble(1.234567);
- testDouble(12.34567);
- testDouble(123.4567);
- testDouble(1234.5678);
-
- }
-}
diff --git a/src/com/softsynth/util/RandomOutputStream.java b/src/com/softsynth/util/RandomOutputStream.java
deleted file mode 100644
index d4c182c..0000000
--- a/src/com/softsynth/util/RandomOutputStream.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.RandomAccessFile;
-
-/**
- * An OutputStream wrapper for a RandomAccessFile Needed by routines that output to an OutputStream.
- * <p>
- * Note that if you are overwriting a RandomAccessFile then you should clear it before you start.
- * This will prevent having the remainder of a longer file stuck at the end of a short file. In Java
- * 1.2 you can call setLength(0).
- */
-public class RandomOutputStream extends OutputStream {
- RandomAccessFile randomFile;
-
- public RandomOutputStream(RandomAccessFile randomFile) {
- this.randomFile = randomFile;
- }
-
- @Override
- public void write(int b) throws IOException {
- randomFile.write(b);
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- randomFile.write(b);
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- randomFile.write(b, off, len);
- }
-
- public void seek(long position) throws IOException {
- randomFile.seek(position);
- }
-
- public long getFilePointer() throws IOException {
- return randomFile.getFilePointer();
- }
-
-}
diff --git a/src/com/softsynth/util/Semaphore.java b/src/com/softsynth/util/Semaphore.java
deleted file mode 100644
index 879d4b6..0000000
--- a/src/com/softsynth/util/Semaphore.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-/**
- * Atomic sepahore.
- */
-public class Semaphore {
- boolean inUse = false;
-
- public synchronized boolean request() {
- boolean result = false;
- if (!inUse) {
- result = inUse = true;
- }
- return result;
- }
-
- public synchronized void free() {
- inUse = false;
- }
-}
diff --git a/src/com/softsynth/util/TextOutput.java b/src/com/softsynth/util/TextOutput.java
deleted file mode 100644
index 7f34965..0000000
--- a/src/com/softsynth/util/TextOutput.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright 1999 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.awt.BorderLayout;
-import java.awt.Button;
-import java.awt.Font;
-import java.awt.Frame;
-import java.awt.TextArea;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-
-/**
- * TextOutput sends text to System.out and/or a TextArea.
- *
- * @author Phil Burk (C) 1999 SoftSynth.com
- */
-public class TextOutput extends Frame {
- private static final long serialVersionUID = 1L;
- /** Maximum number of characters allowed in TextArea. */
- public int maxChars = (8 * 1024);
- int numChars = 0;
- static TextOutput staticTextOutput;
- static Logger logger;
- boolean isTextAreaEnabled = true;
- boolean isSystemOutEnabled = true;
- TextArea textArea;
- Button buttonClear;
- String lineTerminator = System.getProperty("line.separator", "\n");
-
- public TextOutput() {
- super("Text Output");
- setSize(620, 400);
- setLayout(new BorderLayout());
- textArea = new TextArea("", 30, 120, TextArea.SCROLLBARS_BOTH);
- textArea.setEditable(false);
- textArea.setFont(Font.getFont("Monospaced-18")); // FIXME - why doesn't this work???
- add("Center", textArea);
- add("South", buttonClear = new Button("Clear"));
- buttonClear.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- textArea.setText("");
- numChars = 0;
- }
- });
-
- /* If user tries to close window, hide dialog. */
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- hide();
- }
- });
-
- }
-
- public void setTextAreaEnable(boolean enabled) {
- isTextAreaEnabled = enabled;
- }
-
- public void setSystemOutEnable(boolean enabled) {
- isSystemOutEnabled = enabled;
- }
-
- /**
- * Append text to the display area. If the TextArea gets full, then remove 1/4 of the text.
- */
- private void append(String text) {
- int len = text.length();
- if ((numChars + len) > maxChars) {
- int numKill = maxChars / 4;
- /* Delete 1/4 the buffer. */
- textArea.replaceRange("", 0, numKill);
- numChars -= numKill;
- }
- textArea.append(text);
- numChars += len;
- }
-
- public void log(String msg) {
- if (isSystemOutEnabled)
- System.out.print(msg);
- if (isTextAreaEnabled)
- append(msg);
- }
-
- public void logln(String msg) {
- log(msg);
- logln();
- }
-
- /* Just output a new line. */
- public void logln() {
- if (isSystemOutEnabled)
- System.out.println();
- if (isTextAreaEnabled)
- append(lineTerminator);
- }
-
- /**
- * Set a Logger to be used for directing a copy of the output to a log file.
- */
- public static void setLogger(Logger lgr) {
- logger = lgr;
- }
-
- public static Logger getLogger() {
- return logger;
- }
-
- public static void print(String msg) {
- if (staticTextOutput != null)
- staticTextOutput.log(msg);
- else
- System.out.print(msg);
- if (logger != null)
- logger.log(msg);
- }
-
- public static void println(String msg) {
- if (staticTextOutput != null)
- staticTextOutput.logln(msg);
- else
- System.out.println(msg);
- if (logger != null)
- logger.logln(msg);
- }
-
- public static void println() {
- if (staticTextOutput != null)
- staticTextOutput.logln();
- else
- System.out.println();
- if (logger != null)
- logger.logln();
- }
-
- public static void error(String msg) {
- println("ERROR: " + msg);
- throw new RuntimeException(msg);
- }
-
- public static void setStaticLocation(int x, int y) {
- getStaticInstance().setLocation(x, y);
- }
-
- // TODO - why can't this be called from Wire?
- public static TextOutput getStaticInstance() {
- if (staticTextOutput == null) {
- staticTextOutput = new TextOutput();
- staticTextOutput.setLocation(30, 0);
- }
- return staticTextOutput;
- }
-
- public static void open() {
- getStaticInstance().setVisible(true);
- }
-
- public static void close() {
- if (staticTextOutput != null)
- staticTextOutput.setVisible(false);
- }
-
- public static void bringToFront() {
- if (staticTextOutput != null)
- staticTextOutput.toFront();
- }
-}
diff --git a/src/com/softsynth/util/XMLListener.java b/src/com/softsynth/util/XMLListener.java
deleted file mode 100644
index 94f9ec7..0000000
--- a/src/com/softsynth/util/XMLListener.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-/**
- * Listener for parsing an XML stream.
- *
- * @author (C) 1997 Phil Burk
- * @see XMLReader
- * @see XMLPrinter
- */
-
-public interface XMLListener {
- /** Handles the start of an element. The flag ifEmpty if there is no content or endTag. */
- void beginElement(String tag, java.util.Hashtable attributes, boolean ifEmpty);
-
- /** Handles the content of an element. */
- void foundContent(String content);
-
- /** Handles the end of an element. */
- void endElement(String tag);
-}
diff --git a/src/com/softsynth/util/XMLPrinter.java b/src/com/softsynth/util/XMLPrinter.java
deleted file mode 100644
index 2670b39..0000000
--- a/src/com/softsynth/util/XMLPrinter.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-/**
- * Pretty print an XML file.
- * Indent each nested element.
- *
- * @author (C) 1997 Phil Burk
- * @see XMLReader
- * @see XMLListener
- */
-
-/*********************************************************************************
- */
-public class XMLPrinter extends IndentingWriter implements XMLListener {
-
- public XMLPrinter() {
- this(System.out);
- }
-
- public XMLPrinter(OutputStream stream) {
- super(stream);
- }
-
- /**
- * Print a file passed as a command line argument.
- */
- public static void main(String args[]) {
- String fileName;
-
- fileName = (args.length > 0) ? args[0] : "xmlpatch.txt";
- try {
- File file = new File(fileName);
- System.out.println("File: " + file.getAbsolutePath());
- InputStream stream = (new FileInputStream(file));
- com.softsynth.util.XMLReader xmlr = new XMLReader(stream);
- xmlr.setXMLListener(new XMLPrinter());
- xmlr.parse();
- xmlr.close();
- stream.close();
- } catch (IOException e) {
- System.out.println("Error = " + e);
- } catch (SecurityException e) {
- System.out.println("Error = " + e);
- }
- }
-
- @Override
- public void beginElement(String tag, Hashtable attributes, boolean ifEmpty) {
- print("<" + tag);
- indent();
- Enumeration e = attributes.keys();
- if (e.hasMoreElements())
- println();
- while (e.hasMoreElements()) {
- String key = (String) e.nextElement();
- String value = (String) attributes.get(key);
- println(key + "=\"" + value + "\"");
- }
- if (ifEmpty) {
- undent();
- println("/>");
- } else {
- println(">");
- }
- }
-
- @Override
- public void foundContent(String content) {
- if (content != null)
- println(content);
- }
-
- @Override
- public void endElement(String tag) {
- undent();
- println("</" + tag + ">");
- }
-}
diff --git a/src/com/softsynth/util/XMLReader.java b/src/com/softsynth/util/XMLReader.java
deleted file mode 100644
index 181097c..0000000
--- a/src/com/softsynth/util/XMLReader.java
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.io.StreamCorruptedException;
-import java.util.Hashtable;
-
-/**
- * Parse an XML stream using a simple State Machine XMLReader does not buffer the input stream so
- * you may want to do that yourself using a BufferedInputStream.
- *
- * @author (C) 1997 Phil Burk
- * @see XMLListener
- * @see XMLPrinter
- */
-
-public class XMLReader extends PushbackInputStream {
- XMLListener listener;
- final static int IDLE = 0;
- final static int INTAG = 0;
- static int depth = 0;
-
- final static int STATE_TOP = 0;
- final static int STATE_TAG_NAME = 1;
- final static int STATE_TAG_FIND_ANGLE = 2;
- final static int STATE_TAG_ATTR_NAME = 3;
- final static int STATE_TAG_FIND_EQUAL = 4;
- final static int STATE_TAG_FIND_QUOTE = 5;
- final static int STATE_TAG_ATTR_VALUE = 6;
- final static int STATE_CONTENT = 7;
- final static int STATE_CHECK_END = 8;
- final static int STATE_TAG_SKIP = 9;
-
- public void setXMLListener(XMLListener listener) {
- this.listener = listener;
- }
-
- public XMLReader(InputStream stream) {
- super(stream);
- }
-
- /**
- * Read a unicode character from a UTF8 stream.
- *
- * @throws IOException
- */
- private int readChar() throws IOException {
- int c = read();
- if (c < 0)
- return c; // EOF
- else if (c < 128)
- return c; // regular ASCII char
- // We are probably starting a multi-byte character.
- {
- byte[] bar = null;
- if (c < 0xE0)
- bar = new byte[2];
- else if (c < 0xF0)
- bar = new byte[3];
- else if (c < 0xF8)
- bar = new byte[4];
- else if (c < 0xFC)
- bar = new byte[5];
- else if (c < 0xFE)
- bar = new byte[6];
- bar[0] = (byte) c;
- // Gather the rest of the bytes used to encode this character.
- for (int i = 1; i < bar.length; i++) {
- c = read();
- if ((c & 0xc0) != 0x80)
- throw new IOException("invalid UTF8 continuation " + Integer.toHexString(c));
- bar[i] = (byte) c;
- }
- return new String(bar, "UTF8").charAt(0);
- }
- }
-
- /*****************************************************************
- */
- public void parse() throws IOException {
- int i;
- char c;
-
- while (true) {
- i = readChar();
- if (i < 0)
- break; // got end of file
- c = (char) i;
-
- if (c == '<') {
- parseElement();
- } else if (!Character.isWhitespace(c)) {
- throw new StreamCorruptedException(
- "Unexpected character. This doesn't look like an XML file!");
- }
- }
- }
-
- String charToString(char c) {
- String s;
- switch (c) {
- case '\r':
- s = "\\r";
- break;
- case '\n':
- s = "\\n";
- break;
- case '\t':
- s = "\\t";
- break;
- default:
- if (Character.isWhitespace(c))
- s = " ";
- else
- s = "" + c;
- break;
- }
- return s;
- }
-
- boolean isStringWhite(String s) {
- if (s == null)
- return true;
- int len = s.length();
- for (int i = 0; i < len; i++) {
- if (!Character.isWhitespace(s.charAt(i))) {
- return false;
- }
- }
- return true;
- }
-
- /*****************************************************************
- */
- void parseElement() throws IOException {
- int state = STATE_TAG_NAME;
- int i;
- char c;
- String tagName = "";
- String name = null, value = null;
- boolean ifEmpty = false;
- boolean endTag = false;
- boolean done = false;
- boolean skipWhiteSpace = true;
- char endQuote = '"'; // may also be single quote
- String content = null;
- Hashtable attributes = new Hashtable();
-
- // System.out.println("\nparseElement() ---------- " + depth++);
- while (!done) {
- do {
- i = readChar();
- if (i < 0)
- throw new EOFException("EOF inside element!");
- c = (char) i;
- } while (skipWhiteSpace && Character.isWhitespace(c));
- skipWhiteSpace = false;
-
- // System.out.print("(" + charToString(c) + "," + state + ")" );
-
- switch (state) {
-
- case STATE_TAG_NAME:
- if (Character.isWhitespace(c)) {
- skipWhiteSpace = true;
- state = STATE_TAG_FIND_ANGLE;
- } else if (c == '/') // this tag has no matching end tag
- {
- ifEmpty = true;
- state = STATE_TAG_FIND_ANGLE;
- } else if (c == '>') // end of tag
- {
- if (endTag) {
- listener.endElement(tagName);
- done = true;
- } else {
- listener.beginElement(tagName, attributes, ifEmpty);
- state = STATE_CONTENT;
- }
- } else if (c == '?') {
- state = STATE_TAG_SKIP; // got version stuff so skip to end
- } else if (c == '!') // FIXME - parse for "--"
- {
- state = STATE_TAG_SKIP; // got comment
- } else {
- tagName += c;
- }
- break;
-
- case STATE_TAG_SKIP:
- if (c == '>') {
- done = true;
- }
- break;
-
- case STATE_TAG_FIND_ANGLE:
- if (c == '/') // this tag has no matching end tag
- {
- ifEmpty = true;
- } else if (c == '>') {
- if (endTag) {
- listener.endElement(tagName);
- done = true;
- } else {
- listener.beginElement(tagName, attributes, ifEmpty);
- state = STATE_CONTENT;
- done = ifEmpty;
- }
- } else {
- state = STATE_TAG_ATTR_NAME;
- name = "" + c;
- }
- break;
-
- case STATE_TAG_ATTR_NAME:
- if (Character.isWhitespace(c)) {
- skipWhiteSpace = true;
- state = STATE_TAG_FIND_EQUAL;
- } else if (c == '=') {
- skipWhiteSpace = true;
- state = STATE_TAG_FIND_QUOTE;
- } else {
- name += c;
- }
- break;
-
- case STATE_TAG_FIND_EQUAL:
- if (c == '=') {
- skipWhiteSpace = true;
- state = STATE_TAG_FIND_QUOTE;
- } else {
- throw new StreamCorruptedException("Found " + charToString(c)
- + ", expected =.");
- }
- break;
-
- case STATE_TAG_FIND_QUOTE:
- if (c == '"') {
- state = STATE_TAG_ATTR_VALUE;
- value = "";
- endQuote = '"';
- } else if (c == '\'') {
- state = STATE_TAG_ATTR_VALUE;
- value = "";
- endQuote = '\'';
- } else {
- throw new StreamCorruptedException("Found " + charToString(c)
- + ", expected '\"'.");
- }
- break;
-
- case STATE_TAG_ATTR_VALUE:
- if (c == endQuote) {
- attributes.put(name, value);
- // System.out.println("\ngot " + name + " = " + value );
- skipWhiteSpace = true;
- state = STATE_TAG_FIND_ANGLE;
- } else {
- value += c;
- }
- break;
-
- case STATE_CONTENT:
- if (c == '<') {
- state = STATE_CHECK_END;
- if (!isStringWhite(content)) {
- String unescaped = com.softsynth.util.XMLTools.unescapeText(content);
- listener.foundContent(unescaped);
- }
- content = null;
- } else {
- if (content == null)
- content = "";
- content += c;
- }
- break;
-
- case STATE_CHECK_END:
- if (c == '/') {
- endTag = true;
- state = STATE_TAG_NAME;
- tagName = "";
- } else {
- unread(c);
- parseElement();
- state = STATE_CONTENT;
- }
- break;
- }
- }
- // System.out.println("\nparseElement: returns, " + --depth );
- }
-
- /**
- * Get a single attribute from the Hashtable. Use the default if not found.
- */
- public static int getAttribute(Hashtable attributes, String key, int defaultValue) {
- String s = (String) attributes.get(key);
- return (s == null) ? defaultValue : Integer.parseInt(s);
- }
-
- /**
- * Get a single attribute from the Hashtable. Use the default if not found.
- */
- public static double getAttribute(Hashtable attributes, String key, double defaultValue) {
- String s = (String) attributes.get(key);
- return (s == null) ? defaultValue : Double.valueOf(s).doubleValue();
- }
-
-}
diff --git a/src/com/softsynth/util/XMLTools.java b/src/com/softsynth/util/XMLTools.java
deleted file mode 100644
index b997249..0000000
--- a/src/com/softsynth/util/XMLTools.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2002 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-/**
- * Tools for reading and writing XML files.
- *
- * @author Phil Burk, (C) 2002 Mobileer Inc, PROPRIETARY and CONFIDENTIAL
- * @see XMLListener
- * @see XMLPrinter
- */
-
-public class XMLTools {
- static public String replaceCharacters(String text, int ch, String newText) {
- // just return same string if character does not occur
- int index = text.indexOf(ch);
- if (index < 0)
- return text;
-
- StringBuffer buffer = new StringBuffer();
- index = 0;
- while (index < text.length()) {
- char cs = text.charAt(index);
- if (cs == ch) {
- buffer.append(newText);
- } else {
- buffer.append(cs);
- }
- index++;
- }
- return buffer.toString();
- }
-
-/** Convert a human readable string into an XML valid string with proper escape sequences.
- * Character like '<' must be converted to &lt;
- *
- * <pre>
- * & => &amp;
- * < => &lt;
- * > => &gt;
- * " => &quot;
- * ' => &apos;
- * </pre>
- */
- public static String escapeText(String text) {
- text = replaceCharacters(text, '&', "&amp;");
- text = replaceCharacters(text, '<', "&lt;");
- text = replaceCharacters(text, '>', "&gt;");
- text = replaceCharacters(text, '"', "&quot;");
- text = replaceCharacters(text, '\'', "&apos;");
- return text;
- }
-
- public static String unescapeText(String text) {
- int newchar;
- // just return same string if ampersand does not occur
- int index = text.indexOf('&');
- if (index < 0)
- return text;
-
- StringBuffer buffer = new StringBuffer();
- index = 0;
- while (index < text.length()) {
- char cs = text.charAt(index);
- if (cs == '&') {
- // find ending semicolon
- int indexSemiColon = text.indexOf(';', index);
- if (indexSemiColon >= 0) {
- // figure out replacement string
- String repStr = null;
- String escape = text.substring(index + 1, indexSemiColon);
- if (escape.equals("amp"))
- repStr = "&";
- else if (escape.equals("lt"))
- repStr = "<";
- else if (escape.equals("gt"))
- repStr = ">";
- else if (escape.equals("quot"))
- repStr = "\"";
- else if (escape.equals("apos"))
- repStr = "'";
- if (repStr != null)
- buffer.append(repStr);
- } else
- break; // FIXME - throw exception?
- index = indexSemiColon;
- } else {
- buffer.append(cs);
- }
- index++;
- }
- return buffer.toString();
- }
-
- public static void testText(String text1) {
- String text2, text3;
- text2 = escapeText(text1);
- text3 = unescapeText(text2);
- System.out.println("Convert \"" + text1 + "\"");
- System.out.println("to \"" + text2 + "\"");
- System.out.println("and back to \"" + text3 + "\"");
- }
-
- public static void main(String argv[]) {
- testText("Is 2 < 3 or is 2 > 3 ?");
- testText("Joe's & Fred's <<<wow>>> use quotes \"hey bob\"");
- }
-}
diff --git a/src/com/softsynth/util/XMLWriter.java b/src/com/softsynth/util/XMLWriter.java
deleted file mode 100644
index 5276085..0000000
--- a/src/com/softsynth/util/XMLWriter.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2000 Phil Burk, Mobileer Inc
- *
- * 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.
- */
-
-package com.softsynth.util;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.util.Stack;
-
-/**********************************************************************
- * Write XML formatted file.
- *
- * @author (C) 2000 Phil Burk, SoftSynth.com
- */
-
-public class XMLWriter extends IndentingWriter {
- Stack tagStack = new Stack();
- boolean hasContent = false;
-
- public XMLWriter(OutputStream stream) {
- super(stream);
- }
-
- public XMLWriter(Writer outputStreamWriter) {
- super(outputStreamWriter);
- }
-
- public void writeAttribute(String name, String value) {
- print(" " + name + "=\"" + XMLTools.escapeText(value) + "\"");
- }
-
- public void writeAttribute(String name, int value) {
- writeAttribute(name, Integer.toString(value));
- }
-
- public void writeAttribute(String name, long value) {
- writeAttribute(name, Long.toString(value));
- }
-
- public void writeAttribute(String name, double value) {
- writeAttribute(name, Double.toString(value));
- }
-
- public void writeAttribute(String name, boolean value) {
- writeAttribute(name, (value ? "1" : "0"));
- }
-
- public void writeHeader() {
- println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
- }
-
- public void startTag(String name) {
- beginTag(name);
- }
-
- public void beginTag(String name) {
- if (!hasContent && (tagStack.size() > 0)) {
- beginContent();
- println();
- }
- print("<" + name);
- tagStack.push(name);
- hasContent = false;
- indent();
- }
-
- public void endTag() {
- undent();
- String name = (String) tagStack.pop();
- if (hasContent) {
- println("</" + name + ">");
- } else {
- println(" />");
- }
- // If there are tags on the stack, then they obviously had content
- // because we are ending a nested tag.
- hasContent = !tagStack.isEmpty();
- }
-
- public void beginContent() {
- print(">");
- hasContent = true;
- }
-
- public void endContent() {
- }
-
- public void writeComment(String text) throws IOException {
- if (!hasContent && (tagStack.size() > 0)) {
- beginContent();
- println();
- }
- println("<!-- " + XMLTools.escapeText(text) + "-->");
- }
-
- public void writeContent(String string) {
- beginContent();
- print(XMLTools.escapeText(string));
- endContent();
- }
-
- public void writeTag(String tag, String content) {
- beginTag(tag);
- writeContent(content);
- endTag();
- }
-
-}