public static String[] getPortForwarding(Session session)
 {
     java.util.Vector foo = new java.util.Vector();
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             Object[] bar = (Object[])(pool.elementAt(i));
             if (bar[0] != session)
             {
                 continue;
             }
             if (bar[3] == null)
             {
                 foo.addElement(bar[1] + ":" + bar[2] + ":");
             }
             else
             {
                 foo.addElement(bar[1] + ":" + bar[2] + ":" + bar[3]);
             }
         }
     }
     String[] bar2 = new String[foo.size()];
     for (int i = 0; i < foo.size(); i++)
     {
         bar2[i] = (String)(foo.elementAt(i));
     }
     return(bar2);
 }
Exemple #2
0
        /*
         * Method to add a long column name to the global Vector.  Note that
         * the entries are keyed by the short column name so that there is always
         * one and only one short name for any long name.
         */
        public static String addLongName(String inputColumnName)
        {
            String shortColumnName, countString;

            countString     = "0000" + java.lang.Integer.toString(longColumnNames.size() / 2);
            shortColumnName = "COL" + countString.substring(countString.length() - 5);
            if (debug)
            {
                java.lang.SystemJ.outJ.println("Add " + shortColumnName + "|" + inputColumnName);
            }
            longColumnNames.addElement(shortColumnName);
            longColumnNames.addElement(inputColumnName);
            return(shortColumnName);
        }
 public static void addPort(Session session, int port, String target, int lport, SocketFactory factory)
 {
     lock (pool)
     {
         if (getPort(session, port) != null)
         {
             throw new JSchException("PortForwardingR: remote port " + port + " is already registered.");
         }
         Object[] foo = new Object[5];
         foo[0] = session; foo[1] = new Integer(port);
         foo[2] = target; foo[3] = new Integer(lport);
         foo[4] = factory;
         pool.addElement(foo);
     }
 }
Exemple #4
0
        /*
         * Scan the given directory for files containing the substrMatch<br>
         * Small case extensions '.dbf' are recognized and returned as '.DBF'
         */
        public static java.util.Vector <Object> getAllFiles(String path, String suffix)
        {
            java.util.Vector <Object> vec = null;
            String[]     fileNameList;
            java.io.File currentDir, f;
            String       fileName, upperSuffix;
            int          i;

            upperSuffix  = suffix.toUpperCase();
            currentDir   = new java.io.File(path);
            fileNameList = currentDir.list();
            if (fileNameList == null)
            {
                java.lang.SystemJ.outJ.println("*** null for " + path);
            }
            else
            {
                vec = new java.util.Vector <Object>(fileNameList.Length);
                for (i = 0; i < fileNameList.Length; i++)
                {
                    f = new java.io.File(fileNameList[i]);
                    if (!f.isDirectory())
                    {
                        fileName = f.getPath().toString().toUpperCase();
                        //           lastModified = new java.util.Date(f.lastModified());
                        if (upperSuffix == null | fileName.endsWith(upperSuffix))
                        {
                            vec.addElement(f);
                        }
                    }
                }
            }
            return(vec);
        }
        /**
         *
         * Constructs a new tinySQLStatement object.
         * @param conn the tinySQLConnection object
         *
         */
        public TinySQLPreparedStatement(TinySQLConnection conn, String inputString)
        {
            int nextQuestionMark, startAt;

            connection      = conn;
            startAt         = 0;
            statementString = inputString;
            while ((nextQuestionMark = statementString.indexOf("?", startAt)) > -1)
            {
                if (substitute == (java.util.Vector <Object>)null)
                {
                    substitute = new java.util.Vector <Object>();
                }
                substitute.addElement("");
                startAt = nextQuestionMark + 1;
            }
            invalidIndex = " is not in the range 1 to "
                           + java.lang.Integer.toString(substitute.size());
            if (debug)
            {
                java.lang.SystemJ.outJ.println("Prepare statement has " + substitute.size()
                                               + " parameters.");
            }

            this.setPoolable(true); //Basties note: see Java documentation java.sql.SQLStatement.isPoolable
        }
Exemple #6
0
 public void addContext(String inputContext)
 {
     if (inputContext != (String)null)
     {
         contextList.addElement(inputContext);
     }
 }
Exemple #7
0
 internal Channel()
 {
     lock (pool)
     {
         id = index++;
         pool.addElement(this);
     }
 }
Exemple #8
0
 public Channel()
 {
     lock (pool)
     {
         id = index++;
         pool.addElement(this);
     }
 }
 /**
  * Constructs a new {@code SequenceInputStream} using the two streams
  * {@code s1} and {@code s2} as the sequence of streams to read from.
  *
  * @param s1
  *            the first stream to get bytes from.
  * @param s2
  *            the second stream to get bytes from.
  * @throws NullPointerException
  *             if {@code s1} is {@code null}.
  */
 public SequenceInputStream(InputStream s1, InputStream s2)
 {
     if (s1 == null) {
         throw new java.lang.NullPointerException ();
     }
     java.util.Vector<InputStream> inVector = new java.util.Vector<InputStream> (1);
     inVector.addElement (s2);
     e = inVector.elements ();
     inJ = s1;
 }
Exemple #10
0
 /**
  * Register an implementation.
  *
  * @param s The source to be registered, may not be <code>null</code>
  */
 public void addSource(DOMImplementationSource s)
 {
     if (s == null)
     {
         throw new java.lang.NullPointerException();
     }
     if (!sources.contains(s))
     {
         sources.addElement(s);
     }
 }
Exemple #11
0
 /**
  * Constructs a new {@code SequenceInputStream} using the two streams
  * {@code s1} and {@code s2} as the sequence of streams to read from.
  *
  * @param s1
  *            the first stream to get bytes from.
  * @param s2
  *            the second stream to get bytes from.
  * @throws NullPointerException
  *             if {@code s1} is {@code null}.
  */
 public SequenceInputStream(InputStream s1, InputStream s2)
 {
     if (s1 == null)
     {
         throw new java.lang.NullPointerException();
     }
     java.util.Vector <InputStream> inVector = new java.util.Vector <InputStream> (1);
     inVector.addElement(s2);
     e   = inVector.elements();
     inJ = s1;
 }
Exemple #12
0
        public static void readLongNames(String inputDataDir)
        {
            String fullPath, longNameRecord;

            String[]       fields;
            FieldTokenizer ft;

            java.io.File longColumnNameFile;
            dataDir = inputDataDir;
            java.io.BufferedReader longNameReader = (java.io.BufferedReader)null;
            fullPath           = dataDir + fileSep + "TINYSQL_LONG_COLUMN_NAMES.dat";
            longColumnNames    = new java.util.Vector <Object>();
            longColumnNameFile = new java.io.File(fullPath);
            if (longColumnNameFile.exists())
            {
                try
                {
                    longNameReader = new java.io.BufferedReader(new java.io.FileReader(fullPath));
                    while ((longNameRecord = longNameReader.readLine()) != null)
                    {
                        ft     = new FieldTokenizer(longNameRecord, '|', false);
                        fields = ft.getFields();
                        longColumnNames.addElement(fields[0]);
                        longColumnNames.addElement(fields[1]);
                    }
                    longNameReader.close();
                    longNamesInFileCount = longColumnNames.size() / 2;
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("Long Names read: " + longNamesInFileCount);
                    }
                }
                catch (Exception readEx)
                {
                    java.lang.SystemJ.outJ.println("Reader exception " + readEx.getMessage());
                    longNamesInFileCount = 0;
                }
            }
        }
Exemple #13
0
        /**
         *
         * Return a tinySQLTable object, given a table name.
         *
         * @param tableName
         * @see tinySQL#getTable
         *
         */
        internal override TinySQLTable getTable(String tableName) //throws tinySQLException
        {
            int          i, tableIndex;
            TinySQLTable nextTable;

            tableIndex = java.lang.Integer.MIN_VALUE;
            if (TinySQLGlobals.DEBUG)
            {
                java.lang.SystemJ.outJ.println("Trying to create table"
                                               + " object for " + tableName);
            }
            for (i = 0; i < tableList.size(); i++)
            {
                nextTable = (TinySQLTable)tableList.elementAt(i);
                if (nextTable.table.equals(tableName))
                {
                    if (nextTable.isOpen())
                    {
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Found in cache " + nextTable.toString());
                        }
                        return(nextTable);
                    }
                    tableIndex = i;
                    break;
                }
            }
            if (tableIndex == java.lang.Integer.MIN_VALUE)
            {
                tableList.addElement(new DBFFileTable(dataDir, tableName));
                nextTable = (TinySQLTable)tableList.lastElement();
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Add to cache "
                                                   + nextTable.toString());
                }
                return((TinySQLTable)tableList.lastElement());
            }
            else
            {
                tableList.setElementAt(new DBFFileTable(dataDir, tableName), tableIndex);
                nextTable = (TinySQLTable)tableList.elementAt(tableIndex);
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Update in cache "
                                                   + nextTable.toString());
                }
                return((TinySQLTable)tableList.elementAt(tableIndex));
            }
        }
Exemple #14
0
 /*
  * Return anjava.util.Enumeration&lt;Object&gt; of all prefixes for a given URI whose
  * declarations are active in the current context.
  * This includes declarations from parent contexts that have
  * not been overridden.
  *
  * <p/>This method returns prefixes mapped to a specific Namespace
  * URI.  The xml: prefix will be included.  If you want only one
  * prefix that's mapped to the Namespace URI, and you don't care
  * which one you get, use the {@link #getPrefix getPrefix}
  *  method instead.
  *
  * <p/><strong>Note:</strong> the empty (default) prefix is <em>never</em> included
  * in thisjava.util.Enumeration&lt;Object&gt;; to check for the presence of a default
  * Namespace, use the {@link #getURI getURI} method with an
  * argument of "".
  *
  * @param uri The Namespace URI.
  * @return Anjava.util.Enumeration&lt;Object&gt; of prefixes (never empty).
  * @see #getPrefix
  * @see #getDeclaredPrefixes
  * @see #getURI
  */
 public java.util.Enumeration <Object> getPrefixes(String uri)
 {
     java.util.Vector <Object>      prefixes    = new java.util.Vector <Object>();
     java.util.Enumeration <Object> allPrefixes = getPrefixes();
     while (allPrefixes.hasMoreElements())
     {
         String prefix = (String)allPrefixes.nextElement();
         if (uri.equals(getURI(prefix)))
         {
             prefixes.addElement(prefix);
         }
     }
     return(prefixes.elements());
 }
Exemple #15
0
        /**
         * Add a permission object to the permission collection.
         *
         * @param permission
         *            the FilePermission object to add to the collection.
         * @throws IllegalArgumentException
         *             if {@code permission} is not an instance of
         *             {@code FilePermission}.
         * @throws IllegalStateException
         *             if this collection is read-only.
         * @see java.security.PermissionCollection#add(java.security.Permission)
         */

        public override void add(java.security.Permission permission)
        {
            if (isReadOnly())
            {
                throw new java.lang.IllegalStateException();
            }
            if (permission is FilePermission)
            {
                permissions.addElement(permission);
            }
            else
            {
                throw new java.lang.IllegalArgumentException(permission.toString());
            }
        }
        public void addTable(TinySQLTable inputTable)
        {
            int          i;
            TinySQLTable nextTable;

            for (i = 0; i < tableList.size(); i++)
            {
                nextTable = (TinySQLTable)tableList.elementAt(i);
                if (nextTable.table.equals(inputTable.table))
                {
                    return;
                }
            }
            tableList.addElement(inputTable);
        }
Exemple #17
0
        /**
         * Obtain a new instance of a <code>DOMImplementationRegistry</code>.
         *
         *
         * The <code>DOMImplementationRegistry</code> is initialized by the
         * application or the implementation, depending on the context, by
         * first checking the value of the Java system property
         * <code>org.w3c.dom.DOMImplementationSourceList</code> and
         * the the service provider whose contents are at
         * "<code>META_INF/services/org.w3c.dom.DOMImplementationSourceList</code>"
         * The value of this property is a white-space separated list of
         * names of availables classes implementing the
         * <code>DOMImplementationSource</code> interface. Each class listed
         * in the class name list is instantiated and any exceptions
         * encountered are thrown to the application.
         *
         * @return an initialized instance of DOMImplementationRegistry
         * @throws ClassNotFoundException
         *     If any specified class can not be found
         * @throws InstantiationException
         *     If any specified class is an interface or abstract class
         * @throws IllegalAccessException
         *     If the default constructor of a specified class is not accessible
         * @throws ClassCastException
         *     If any specified class does not implement
         * <code>DOMImplementationSource</code>
         */
        public static DOMImplementationRegistry newInstance()
        {
            //throws     ClassNotFoundException,     InstantiationException,     IllegalAccessException,     ClassCastException {
            java.util.Vector <Object> sources = new java.util.Vector <Object>();

            java.lang.ClassLoader classLoader = getClassLoader();
            // fetch system property:
            String p = getSystemProperty(PROPERTY);

            //
            // if property is not specified then use contents of
            // META_INF/org.w3c.dom.DOMImplementationSourceList from classpath
            if (p == null)
            {
                p = getServiceValue(classLoader);
            }
            if (p == null)
            {
                //
                // DOM Implementations can modify here to add *additional* fallback
                // mechanisms to access a list of default DOMImplementationSources.
            }
            if (p != null)
            {
                java.util.StringTokenizer st = new java.util.StringTokenizer(p);
                while (st.hasMoreTokens())
                {
                    String sourceName = st.nextToken();
                    // Use context class loader, falling back to Class.forName
                    // if and only if this fails...
                    java.lang.Class sourceClass = null;
                    if (classLoader != null)
                    {
                        sourceClass = classLoader.loadClass(sourceName);
                    }
                    else
                    {
                        sourceClass = java.lang.Class.forName(sourceName);
                    }
                    DOMImplementationSource source =
                        (DOMImplementationSource)sourceClass.newInstance();
                    sources.addElement(source);
                }
            }
            return(new DOMImplementationRegistry(sources));
        }
Exemple #18
0
        /**
         * Return a list of implementations that support the
         * desired features.
         *
         * @param features
         *            A string that specifies which features are required. This is
         *            a space separated list in which each feature is specified by
         *            its name optionally followed by a space and a version number.
         *            This is something like: "XML 1.0 Traversal +Events 2.0"
         * @return A list of DOMImplementations that support the desired features.
         */
        public DOMImplementationList getDOMImplementationList(String features)
        {
            java.util.Vector <Object> implementations = new java.util.Vector <Object>();
            int size = sources.size();

            for (int i = 0; i < size; i++)
            {
                DOMImplementationSource source =
                    (DOMImplementationSource)sources.elementAt(i);
                DOMImplementationList impls =
                    source.getDOMImplementationList(features);
                for (int j = 0; j < impls.getLength(); j++)
                {
                    DOMImplementation impl = impls.item(j);
                    implementations.addElement(impl);
                }
            }
            return(new IAC_DOMImplementationList(implementations));
        }
Exemple #19
0
        public void addColumn(TsColumn col)
        {
            int          i;
            bool         addTable;
            TinySQLTable checkTable;

            rsColumns.addElement(col);
            if (col.getContext("SELECT"))
            {
                selectColumns.addElement(col);
            }
            if (col.getContext("ORDER"))
            {
                orderByColumns.addElement(col);
            }
            if (col.isGroupedColumn())
            {
                groupedColumns = true;
            }

            /*
             *    Add the table that this column belongs to if required
             */
            addTable = true;
            if (col.columnTable != (TinySQLTable)null)
            {
                for (i = 0; i < tables.size(); i++)
                {
                    checkTable = (TinySQLTable)tables.elementAt(i);
                    if (checkTable.table.equals(col.columnTable.table))
                    {
                        addTable = false;
                        break;
                    }
                }
                if (addTable)
                {
                    tables.addElement(col.columnTable);
                }
            }
        }
Exemple #20
0
 internal static String[] getPortForwarding(Session session)
 {
     java.util.Vector foo = new java.util.Vector();
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             PortWatcher p = (PortWatcher)(pool.elementAt(i));
             if (p.session == session)
             {
                 foo.addElement(p.lport + ":" + p.host + ":" + p.rport);
             }
         }
     }
     String[] bar = new String[foo.size()];
     for (int i = 0; i < foo.size(); i++)
     {
         bar[i] = (String)(foo.elementAt(i));
     }
     return(bar);
 }
		internal static String[] getPortForwarding(Session session)
		{
			java.util.Vector foo=new java.util.Vector();
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					PortWatcher p=(PortWatcher)(pool.elementAt(i));
					if(p.session==session)
					{
						foo.addElement(p.lport+":"+p.host+":"+p.rport);
					}
				}
			}
			String[] bar=new String[foo.size()];
			for(int i=0; i<foo.size(); i++)
			{
				bar[i]=(String)(foo.elementAt(i));
			}
			return bar;
		}
Exemple #22
0
        private static java.sql.Connection dbConnect(String tinySQLDir)// throws SQLException
        {
            java.sql.Connection       con = null;
            java.sql.DatabaseMetaData dbMeta;
            java.io.File   conPath;
            java.io.File[] fileList;
            String         tableName;

            java.sql.ResultSet tables_rs;
            conPath  = new java.io.File(tinySQLDir);
            fileList = conPath.listFiles();
            if (fileList == null)
            {
                java.lang.SystemJ.outJ.println(tinySQLDir + " is not a valid directory.");
                return((java.sql.Connection)null);
            }
            else
            {
                java.lang.SystemJ.outJ.println("Connecting to " + conPath.getAbsolutePath());
                con = java.sql.DriverManager.getConnection("jdbc:dbfFile:" + conPath, "", "");
            }
            dbMeta    = con.getMetaData();
            tables_rs = dbMeta.getTables(null, null, null, null);
            tableList = new java.util.Vector <Object>();
            while (tables_rs.next())
            {
                tableName = tables_rs.getString("TABLE_NAME");
                tableList.addElement(tableName);
            }
            if (tableList.size() == 0)
            {
                java.lang.SystemJ.outJ.println("There are no tinySQL tables in this directory.");
            }
            else
            {
                java.lang.SystemJ.outJ.println("There are " + tableList.size() + " tinySQL tables"
                                               + " in this directory.");
            }
            return(con);
        }
Exemple #23
0
        /*
         * This method sets up particular phrase elements for the SQL command.
         * Examples would be a list of selected columns and tables for a SELECT
         * statement, or a list of column definitions for a CREATE TABLE
         * statement.  These phrase elements will be added to the action list
         * once the entire statement has been parsed.
         */
        public void setPhrase(String inputKeyWord, String inputString)
        //throws TinySQLException
        {
            String nextField, upperField,
                   fieldString, tempString, columnName, columnAlias;

            java.lang.StringBuffer concatBuffer;
            FieldTokenizer         ft1, ft2, ft3;
            TsColumn createColumn;

/*
 *    Handle compound keywords.
 */
            if (inputString == (String)null)
            {
                lastKeyWord = inputKeyWord;
                return;
            }
            else if (inputString.trim().length() == 0)
            {
                lastKeyWord = inputKeyWord;
                return;
            }
            if (TinySQLGlobals.PARSER_DEBUG)
            {
                java.lang.SystemJ.outJ.println("setPhrase " + inputString);
            }
            ft1 = new FieldTokenizer(inputString, ',', false);
            while (ft1.hasMoreFields())
            {
                nextField = ft1.nextField().trim();
                if (TinySQLGlobals.PARSER_DEBUG)
                {
                    java.lang.SystemJ.outJ.println(inputKeyWord + " field is " + nextField);
                }
                upperField = nextField.toUpperCase();
                if (inputKeyWord.equals("SELECT"))
                {
/*
 *          Check for the keyword DISTINCT
 */
                    if (nextField.toUpperCase().startsWith("DISTINCT"))
                    {
                        distinct  = true;
                        nextField = nextField.substring(9).trim();
                    }

/*
 *          Check for and set column alias.
 */
                    ft2         = new FieldTokenizer(nextField, ' ', false);
                    columnName  = ft2.getField(0);
                    columnAlias = (String)null;

/*
 *          A column alias can be preceded by the keyword AS which will
 *          be ignored by tinySQL.
 */
                    if (ft2.countFields() == 2)
                    {
                        columnAlias = ft2.getField(1);
                    }
                    else if (ft2.countFields() == 3)
                    {
                        columnAlias = ft2.getField(2);
                    }

/*
 *          Check for column concatenation using the | symbol
 */
                    ft2 = new FieldTokenizer(columnName, '|', false);
                    if (ft2.countFields() > 1)
                    {
                        concatBuffer = new java.lang.StringBuffer("CONCAT(");
                        while (ft2.hasMoreFields())
                        {
                            if (concatBuffer.length() > 7)
                            {
                                concatBuffer.append(",");
                            }
                            concatBuffer.append(ft2.nextField());
                        }
                        columnName = concatBuffer.toString() + ")";
                    }
                    columnList.addElement(columnName);
                    columnAliasList.addElement(columnAlias);
                    contextList.addElement(inputKeyWord);
                }
                else if (inputKeyWord.equals("TABLE"))
                {
/*
 *          If the input keyword is TABLE, update the statement type to be a
 *          compound type such as CREATE_TABLE, DROP_TABLE, or ALTER_TABLE.
 */
                    if (!statementType.equals("INSERT"))
                    {
                        statementType = statementType + "_TABLE";
                    }
                    if (statementType.equals("CREATE_TABLE"))
                    {
/*
 *             Parse out the column definition.
 */
                        ft2 = new FieldTokenizer(nextField, '(', false);
                        if (ft2.countFields() != 2)
                        {
                            throwException(1);
                        }
                        tableName   = ft2.getField(0);
                        fieldString = ft2.getField(1);
                        ft2         = new FieldTokenizer(fieldString, ',', false);
                        while (ft2.hasMoreFields())
                        {
                            tempString   = ft2.nextField();
                            createColumn = parseColumnDefn(tempString);
                            if (createColumn != (TsColumn)null)
                            {
                                columnList.addElement(createColumn);
                            }
                        }
                    }
                    else if (statementType.equals("DROP_TABLE"))
                    {
/*
 *             Handle dropping of non-existent tables
 */
                        tableName = upperField;
                        try
                        {
                            validateTable(upperField, true);
                        } catch (Exception) {
                            throw new TinySQLException("Table " + tableName
                                                       + " does not exist.");
                        }
                    }
                    else
                    {
                        tableName = upperField;
                        validateTable(upperField, true);
                    }
                }
                else if (inputKeyWord.equals("BY"))
                {
/*
 *          Set up Group by and Order by columns.
 */
                    if (lastKeyWord == (String)null)
                    {
                        throwException(6);
                    }
                    else
                    {
                        ft3 = new FieldTokenizer(upperField, ' ', false);
                        columnList.addElement(ft3.getField(0));
                        if (ft3.countFields() == 2)
                        {
/*
 *                ASC or DESC are the only allowable directives after GROUP BY
 */
                            if (ft3.getField(1).startsWith("ASC") |
                                ft3.getField(1).startsWith("DESC"))
                            {
                                orderType = ft3.getField(1);
                            }
                            else
                            {
                                throwException(7);
                            }
                        }
                        if (lastKeyWord.equals("ORDER"))
                        {
                            defaultOrderBy = false;
                        }
                        contextList.addElement(lastKeyWord);
                    }
                }
                else if (inputKeyWord.equals("DROP"))
                {
/*
 *          Parse list of columns to be dropped.
 */
                    statementType = "ALTER_DROP";
                    ft2           = new FieldTokenizer(upperField, ' ', false);
                    while (ft2.hasMoreFields())
                    {
                        columnList.addElement(UtilString.removeQuotes(ft2.nextField()));
                    }
                }
                else if (inputKeyWord.equals("RENAME"))
                {
/*
 *          Parse old and new column name.
 */
                    statementType = "ALTER_RENAME";
                    ft2           = new FieldTokenizer(upperField, ' ', false);
                    oldColumnName = ft2.getField(0);
                    newColumnName = ft2.getField(1);
                    if (newColumnName.equals("TO") & ft2.countFields() == 3)
                    {
                        newColumnName = ft2.getField(2);
                    }
                    if (newColumnName.length() > 11)
                    {
                        newColumnName = TinySQLGlobals.getShortName(newColumnName);
                    }
                }
                else if (inputKeyWord.equals("ADD"))
                {
/*
 *          Parse definition of columns to be added.
 */
                    statementType = "ALTER_ADD";
                    createColumn  = parseColumnDefn(nextField);
                    if (createColumn != (TsColumn)null)
                    {
                        columnList.addElement(createColumn);
                    }
                }
                else if (inputKeyWord.equals("FROM"))
                {
/*
 *          Check for valid table
 */
                    tableName = upperField;
                    validateTable(tableName);
                }
                else if (inputKeyWord.equals("INTO"))
                {
                    ft2 = new FieldTokenizer(nextField, '(', false);
                    if (ft2.countFields() != 2)
                    {
                        throwException(3);
                    }
                    tableName = ft2.getField(0).toUpperCase();
                    validateTable(tableName);
                    fieldString = ft2.getField(1).toUpperCase();
                    ft2         = new FieldTokenizer(fieldString, ',', false);
                    while (ft2.hasMoreFields())
                    {
                        tempString = UtilString.removeQuotes(ft2.nextField());
                        columnList.addElement(tempString);
                        contextList.addElement(inputKeyWord);
                    }
                }
                else if (inputKeyWord.equals("VALUES"))
                {
                    ft2         = new FieldTokenizer(nextField, '(', false);
                    fieldString = ft2.getField(0);
                    ft2         = new FieldTokenizer(fieldString, ',', false);
                    while (ft2.hasMoreFields())
                    {
                        tempString = UtilString.removeQuotes(ft2.nextField());
                        tempString = UtilString.replaceAll(tempString, "''", "'");
                        valueList.addElement(tempString);
                    }
                }
                else if (inputKeyWord.equals("UPDATE"))
                {
                    tableName = nextField.toUpperCase();
                    validateTable(tableName);
                }
                else if (inputKeyWord.equals("SET"))
                {
/*
 *          Parse the update column name/value pairs
 */
                    ft2 = new FieldTokenizer(nextField, '=', false);
                    if (ft2.countFields() != 2)
                    {
                        throwException(4);
                    }
                    columnList.addElement(ft2.getField(0));
                    contextList.addElement(inputKeyWord);
                    valueList.addElement(UtilString.removeQuotes(ft2.getField(1)));
                }
                else if (inputKeyWord.equals("WHERE"))
                {
                    whereClause = new TinySQLWhere(nextField, tables);
                }
                else if (!inputKeyWord.equals("TABLE"))
                {
                    throwException(10);
                }
            }
            lastKeyWord = inputKeyWord;
        }
		internal static String[] getPortForwarding(Session session)
		{
			java.util.Vector foo=new java.util.Vector();
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					Object[] bar=(Object[])(pool.elementAt(i));
					if(bar[0]!=session) continue;
					if(bar[3]==null){ foo.addElement(bar[1]+":"+bar[2]+":"); }
					else{ foo.addElement(bar[1]+":"+bar[2]+":"+bar[3]); }
				}
			}
			String[] bar2=new String[foo.size()];
			for(int i=0; i<foo.size(); i++)
			{
				bar2[i]=(String)(foo.elementAt(i));
			}
			return bar2;
		}
Exemple #25
0
 /**
  * Return anjava.util.Enumeration&lt;Object&gt; of all prefixes for a given URI whose
  * declarations are active in the current context.
  * This includes declarations from parent contexts that have
  * not been overridden.
  *
  * <p/>This method returns prefixes mapped to a specific Namespace
  * URI.  The xml: prefix will be included.  If you want only one
  * prefix that's mapped to the Namespace URI, and you don't care
  * which one you get, use the {@link #getPrefix getPrefix}
  *  method instead.
  *
  * <p/><strong>Note:</strong> the empty (default) prefix is <em>never</em> included
  * in thisjava.util.Enumeration&lt;Object&gt;; to check for the presence of a default
  * Namespace, use the {@link #getURI getURI} method with an
  * argument of "".
  *
  * @param uri The Namespace URI.
  * @return Anjava.util.Enumeration&lt;Object&gt; of prefixes (never empty).
  * @see #getPrefix
  * @see #getDeclaredPrefixes
  * @see #getURI
  */
 public java.util.Enumeration<Object> getPrefixes(String uri)
 {
     java.util.Vector<Object> prefixes = new java.util.Vector<Object>();
     java.util.Enumeration<Object> allPrefixes = getPrefixes();
     while (allPrefixes.hasMoreElements()) {
     String prefix = (String)allPrefixes.nextElement();
     if (uri.equals(getURI(prefix))) {
     prefixes.addElement(prefix);
     }
     }
     return prefixes.elements();
 }
Exemple #26
0
        internal TsColumn(String s, java.util.Hashtable <Object, Object> tableDefs, String inputContext)
        //throws tinySQLException
        {
            FieldTokenizer ft, ftArgs;
            int            j, numericType, nameLength, dotAt, argIndex;
            String         upperName, checkName, nextArg;
            TinySQLTable   jtbl;
            TsColumn       tcol;

            java.util.Vector <Object>      t;
            java.util.Enumeration <Object> col_keys;
            name        = s;
            longName    = name;
            nameLength  = name.length();
            contextList = new java.util.Vector <Object>();
            contextList.addElement(inputContext);
            ft = new FieldTokenizer(name, '(', false);
            if (ft.countFields() == 2)
            {
                /*
                 *       This is a function rather than a simple column or constant
                 */
                functionName = ft.getField(0).toUpperCase();
                if (functionName.equals("COUNT"))
                {
                    type          = java.sql.Types.INTEGER;
                    size          = 10;
                    intValue      = java.lang.Integer.MIN_VALUE;
                    groupedColumn = true;
                }
                else if (functionName.equals("SUM"))
                {
                    type          = java.sql.Types.FLOAT;
                    size          = 10;
                    groupedColumn = true;
                }
                else if (functionName.equals("TO_DATE"))
                {
                    type = java.sql.Types.DATE;
                    size = 10;
                }
                else if (functionName.equals("CONCAT") |
                         functionName.equals("UPPER") |
                         functionName.equals("SUBSTR") |
                         functionName.equals("TRIM"))
                {
                    type = java.sql.Types.CHAR;
                }
                functionArgString = ft.getField(1);
                ftArgs            = new FieldTokenizer(functionArgString, ',', false);
                functionArgs      = new java.util.Vector <Object>();
                argIndex          = 0;
                while (ftArgs.hasMoreFields())
                {
                    nextArg = ftArgs.nextField();
                    tcol    = new TsColumn(nextArg, tableDefs, inputContext);
                    if (tcol.isGroupedColumn())
                    {
                        groupedColumn = true;
                    }

                    /*
                     *          MAX and MIN functions can be either FLOAT or CHAR types
                     *          depending upon the type of the argument.
                     */
                    if (functionName.equals("MAX") | functionName.equals("MIN"))
                    {
                        if (argIndex > 0)
                        {
                            throw new TinySQLException("Function can only have 1 argument");
                        }
                        groupedColumn = true;
                        type          = tcol.type;
                        size          = tcol.size;
                    }
                    else if (functionName.equals("CONCAT"))
                    {
                        type  = java.sql.Types.CHAR;
                        size += tcol.size;
                    }
                    else if (functionName.equals("UPPER"))
                    {
                        type = java.sql.Types.CHAR;
                        size = tcol.size;
                    }
                    else if (functionName.equals("TO_DATE"))
                    {
                        type = java.sql.Types.DATE;
                        size = 10;
                    }
                    else if (functionName.equals("TRIM"))
                    {
                        type = java.sql.Types.CHAR;
                        size = tcol.size;
                    }
                    else if (functionName.equals("SUBSTR"))
                    {
                        type = java.sql.Types.CHAR;
                        if (argIndex == 0 & tcol.type != java.sql.Types.CHAR)
                        {
                            throw new TinySQLException("SUBSTR first argument must be character");
                        }
                        else if (argIndex == 1)
                        {
                            if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1)
                            {
                                throw new TinySQLException("SUBSTR second argument "
                                                           + tcol.getString() + " must be integer > 0");
                            }
                        }
                        else if (argIndex == 2)
                        {
                            if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1)
                            {
                                throw new TinySQLException("SUBSTR third argument "
                                                           + tcol.getString() + " must be integer > 0");
                            }
                            size = tcol.intValue;
                        }
                    }
                    argIndex++;
                    functionArgs.addElement(tcol);
                }
            }
            else
            {
                /*
                 *       Check for SYSDATE
                 */
                if (name.toUpperCase().equals("SYSDATE"))
                {
                    isConstant = true;
                    type       = java.sql.Types.DATE;
                    size       = 10;
                    notNull    = true;
                    valueSet   = true;
                    //Basties mote: not really SimpleDateFormat needed... - need yyyy-MM-dd
                    // stringValue = fmtyyyyMMdd.format(today.getTime());
                    stringValue = System.DateTime.Today.ToString("yyyy-MM-dd");

                    /*
                     *          Check for a quoted string
                     */
                }
                else if (UtilString.isQuotedString(name))
                {
                    isConstant  = true;
                    type        = java.sql.Types.CHAR;
                    stringValue = UtilString.removeQuotes(name);
                    if (stringValue != (String)null)
                    {
                        size     = stringValue.length();
                        notNull  = true;
                        valueSet = true;
                    }
                }
                else
                {
                    /*
                     *          Check for a numeric constant
                     */
                    numericType = UtilString.getValueType(name);
                    if (numericType == java.sql.Types.INTEGER)
                    {
                        intValue   = java.lang.Integer.valueOf(name).intValue();
                        size       = 10;
                        type       = numericType;
                        isConstant = true;
                        notNull    = true;
                        valueSet   = true;
                    }
                    else if (numericType == java.sql.Types.FLOAT)
                    {
                        floatValue = java.lang.Float.valueOf(name).floatValue();
                        size       = 10;
                        type       = numericType;
                        isConstant = true;
                        notNull    = true;
                        valueSet   = true;
                    }
                    else
                    {
                        /*
                         *             This should be a column name.
                         */
                        columnTable = (TinySQLTable)null;
                        upperName   = name.toUpperCase();
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Trying to find table for " + upperName);
                        }
                        dotAt = upperName.indexOf(".");
                        if (dotAt > -1)
                        {
                            tableName = upperName.substring(0, dotAt);
                            if (tableDefs != (java.util.Hashtable <Object, Object>)null &
                                tableName.indexOf("->") < 0)
                            {
                                t         = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER");
                                tableName = UtilString.findTableAlias(tableName, t);
                            }
                            upperName = upperName.substring(dotAt + 1);

                            /*
                             *                Check to see if this column name has a short equivalent.
                             */
                            if (upperName.length() > 11)
                            {
                                longName  = name;
                                upperName = TinySQLGlobals.getShortName(upperName);
                            }
                            columnTable = (TinySQLTable)tableDefs.get(tableName);
                        }
                        else if (tableDefs != (java.util.Hashtable <Object, Object>)null)
                        {
                            /*
                             *                Check to see if this column name has a short equivalent.
                             */
                            if (upperName.length() > 11)
                            {
                                longName  = name;
                                upperName = TinySQLGlobals.getShortName(upperName);
                            }

                            /*
                             *                Use an enumeration to go through all of the tables to find
                             *                this column.
                             */
                            t = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER");
                            for (j = 0; j < t.size(); j++)
                            {
                                tableName = (String)t.elementAt(j);
                                jtbl      = (TinySQLTable)tableDefs.get(tableName);
                                col_keys  = jtbl.column_info.keys();

                                /*
                                 *                   Check all columns.
                                 */
                                while (col_keys.hasMoreElements())
                                {
                                    checkName = (String)col_keys.nextElement();
                                    if (checkName.equals(upperName))
                                    {
                                        upperName   = checkName;
                                        columnTable = jtbl;
                                        break;
                                    }
                                }
                                if (columnTable != (TinySQLTable)null)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (TinySQLGlobals.DEBUG)
                            {
                                java.lang.SystemJ.outJ.println("No table definitions.");
                            }
                        }
                        if (columnTable != (TinySQLTable)null)
                        {
                            name = columnTable.table + "->" + columnTable.tableAlias
                                   + "." + upperName;
                            type          = columnTable.ColType(upperName);
                            size          = columnTable.ColSize(upperName);
                            decimalPlaces = columnTable.ColDec(upperName);
                            tableName     = columnTable.table + "->" + columnTable.tableAlias;
                        }
                    }
                }
            }
        }
Exemple #27
0
        /*
         * The constructor builds a Where clause object from the input string.
         */
        public TinySQLWhere(String whereString, java.util.Hashtable <Object, Object> tableDefs)
        //throws tinySQLException
        {
            FieldTokenizer ft;

            java.util.Vector <Object> whereConditions;
            TsColumn leftColumn, rightColumn;
            Object   whereObj;

            java.lang.StringBuffer fieldBuffer;
            String nextField, upperField, wherePhrase, comp, left, right, andOr, lastWord;

            java.util.Vector <Object> whereCondition;
            String[] comparisons = { "<=",   "=<",       ">=", "=>", "=", "<>", "!=", ">", "<",
                                     "LIKE", "NOT LIKE", "IS" };
            String[] fields, keepFields;
            bool     inBrackets = false, foundFunction = false;
            int      i, j, foundKeyWord, foundComp, startAt, foundAnd, foundOr, keepCount;

            /*
             *    The whereClauseList is a Vector containing pointers to whereCondition
             *    Vectors or tinySQLWhere objects.
             */
            whereConditions = new java.util.Vector <Object>();
            whereClauseList = new java.util.Vector <Object>();

            /*
             *    Identify any phrases that are contained within brackets.  Note that
             *    the FieldTokenizer will catch function definitions as well as
             *    subPhrases so there has to be additional logic to reconstruct
             *    the functions.
             */
            ft            = new FieldTokenizer(whereString, '(', true);
            fields        = ft.getFields();
            keepFields    = new String[fields.Length];
            lastWord      = "NULL";
            fieldBuffer   = new java.lang.StringBuffer();
            foundFunction = false;
            keepCount     = 0;
            for (i = 0; i < fields.Length; i++)
            {
                keepFields[i] = "";
                if (fields[i].equals("("))
                {
                    /*
                     *          If this is a known function reconstruct the function definition
                     *          and save the entire string.
                     */
                    foundFunction = Utils.isFunctionName(lastWord);
                    if (foundFunction)
                    {
                        fieldBuffer.append("(");
                    }
                    else
                    {
                        if (fieldBuffer.length() > 0)
                        {
                            keepFields[keepCount] = fieldBuffer.toString();
                            keepCount++;
                            fieldBuffer.delete(0, fieldBuffer.length());
                        }
                        keepFields[keepCount] = "(";
                        keepCount++;
                    }
                }
                else if (fields[i].equals(")"))
                {
                    if (foundFunction)
                    {
                        fieldBuffer.append(") ");
                        foundFunction = false;
                    }
                    else
                    {
                        if (fieldBuffer.length() > 0)
                        {
                            keepFields[keepCount] = fieldBuffer.toString();
                            keepCount++;
                            fieldBuffer.delete(0, fieldBuffer.length());
                        }
                        keepFields[keepCount] = ")";
                        keepCount++;
                    }
                }
                else
                {
                    fieldBuffer.append(fields[i]);
                }
                lastWord = fields[i].substring(fields[i].lastIndexOf(" ") + 1);
            }

            /*
             *    Keep last subPhrase
             */
            if (fieldBuffer.length() > 0)
            {
                keepFields[keepCount] = fieldBuffer.toString();
                keepCount++;
            }
            for (i = 0; i < keepCount; i++)
            {
                if (TinySQLGlobals.WHERE_DEBUG)
                {
                    java.lang.SystemJ.outJ.println("keepFields[" + i + "]=" + keepFields[i]);
                }
                nextField  = keepFields[i];
                upperField = nextField.toUpperCase();
                if (nextField.equals("("))
                {
                    whereObj   = (Object)null;
                    inBrackets = true;
                }
                else if (nextField.equals(")"))
                {
                    inBrackets = false;
                    whereObj   = (Object)null;
                }
                else if (inBrackets)
                {
                    whereObj = new TinySQLWhere(nextField, tableDefs);
                    whereConditions.addElement(whereObj);
                }
                else
                {
                    /*
                     *          Look for AND/OR keywords - if none are found process the
                     *          entire string.
                     */
                    andOr   = "AND";
                    startAt = 0;
                    while (startAt < upperField.length())
                    {
                        if (upperField.startsWith("AND "))
                        {
                            foundAnd = 0;
                        }
                        else
                        {
                            foundAnd = upperField.indexOf(" AND", startAt);

                            /*
                             *                Make sure this is not just part of a longer string.
                             */
                            if (foundAnd > -1 & foundAnd < upperField.length() - 4)
                            {
                                if (upperField.charAt(foundAnd + 4) != ' ')
                                {
                                    foundAnd = -1;
                                }
                            }
                        }
                        if (upperField.startsWith("OR "))
                        {
                            foundOr = 0;
                        }
                        else
                        {
                            foundOr = upperField.indexOf(" OR", startAt);
                            if (foundOr > -1 & foundOr < upperField.length() - 3)
                            {
                                if (upperField.charAt(foundOr + 3) != ' ')
                                {
                                    foundOr = -1;
                                }
                            }
                        }
                        foundKeyWord = upperField.length();
                        if (foundAnd > -1)
                        {
                            foundKeyWord = foundAnd;
                        }
                        if (foundOr > -1 & foundOr < foundKeyWord)
                        {
                            foundKeyWord = foundOr;
                            andOr        = "OR";
                        }
                        if (foundKeyWord == 0)
                        {
                            startAt      = andOr.length() + 1;
                            foundKeyWord = upperField.length();
                        }
                        wherePhrase = nextField.substring(startAt, foundKeyWord);
                        if (TinySQLGlobals.WHERE_DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Where phrase is " + wherePhrase);
                        }
                        if (foundKeyWord < upperField.length() - 4)
                        {
                            andOr = upperField.substring(foundKeyWord + 1, foundKeyWord + 3);
                        }

                        /*
                         *             Build a whereCondition Vector.  The elements are
                         *             as follows:
                         *             0 - left column object
                         *             1 - comparison
                         *             2 - right column object
                         *             3 - status
                         *
                         *             The status values indicate which parts of the where
                         *             condition have been set.
                         */
                        whereCondition = new java.util.Vector <Object>();
                        for (j = 0; j < comparisons.Length; j++)
                        {
                            comp      = comparisons[j];
                            foundComp = wherePhrase.toUpperCase().indexOf(comp);
                            if (foundComp > -1)
                            {
                                left       = wherePhrase.substring(0, foundComp).trim();
                                leftColumn = new TsColumn(left, tableDefs, "WHERE");
                                whereCondition.addElement(leftColumn);
                                whereCondition.addElement(comp);
                                right = wherePhrase.substring(foundComp + comp.length()).trim();
                                if (comp.equals("IS"))
                                {
                                    right = "'" + right.toUpperCase() + "'";
                                }
                                rightColumn = new TsColumn(right, tableDefs, "WHERE");
                                whereCondition.addElement(rightColumn);
                                if (leftColumn.isConstant & rightColumn.isConstant)
                                {
                                    whereCondition.addElement("BOTH");
                                }
                                else if (leftColumn.isConstant)
                                {
                                    whereCondition.addElement("LEFT");
                                }
                                else if (rightColumn.isConstant)
                                {
                                    whereCondition.addElement("RIGHT");
                                }
                                else
                                {
                                    whereCondition.addElement("UNKNOWN");
                                }
                                break;
                            }
                        }
                        whereConditions.addElement(whereCondition);

                        /*
                         *             If this condition and the previous one are joined by an
                         *             AND keyword, add the condition to the existing Vector.
                         *             For an OR keyword, create a new entry in the whereClauseList.
                         */
                        if (andOr.equals("OR"))
                        {
                            whereClauseList.addElement(whereConditions);
                            whereConditions = new java.util.Vector <Object>();
                        }
                        startAt = foundKeyWord + andOr.length() + 2;
                    }
                }
            }

            /*
             *    Add the last where condition to the list.
             */
            if (whereConditions.size() > 0)
            {
                whereClauseList.addElement(whereConditions);
            }
            if (TinySQLGlobals.WHERE_DEBUG)
            {
                java.lang.SystemJ.outJ.println("Where clause is \n" + toString());
            }
        }
Exemple #28
0
        /*
         * Split an input string into fields based upon the input separator, ignoring
         * separators that might occur within brackets or quoted string.  If the
         * separator is (, return strings outside and inside of the brackets.  The
         * parameter returnSep indicates whether or not the actual separator characters
         * themselves should be returned.
         */
        public FieldTokenizer(String inputString, char separator, bool returnSep)
        {
            char quoteChar, nextChar, bracketQuoteChar;

            char[] charArray = { ' ' };
            java.util.Vector <Object> tempStrings;
            int    i, leftBracketCount, rightBracketCount, startPosn, endPosn;
            String tempString;
            bool   debug = false;

            if (inputString.indexOf(separator) < 0)
            {
                fields    = new String[1];
                fields[0] = inputString;
                if (inputString.trim().length() == 0)
                {
                    return;
                }
            }
            if (debug)
            {
                java.lang.SystemJ.outJ.println("FieldTokenizer: "
                                               + " separator is " + separator + " string is <" + inputString + ">");
            }
            charArray[0]      = separator;
            tempStrings       = new java.util.Vector <Object>();
            leftBracketCount  = 0;
            rightBracketCount = 0;
            quoteChar         = ' ';
            bracketQuoteChar  = ' ';
            startPosn         = 0;
            endPosn           = 0;
            for (i = 0; i < inputString.length(); i++)
            {
                nextChar = inputString.charAt(i);
                endPosn  = i;
                if (nextChar == '\'' | nextChar == '"')
                {
                    /*
                     *          Set the bracketQuoteChar for quotes within a bracket
                     *          delimited string.  This will allow handling of brackets
                     *          within quoted strings that are embedded within the brackets.
                     */
                    if (leftBracketCount > 0)
                    {
                        if (bracketQuoteChar == ' ')
                        {
                            bracketQuoteChar = nextChar;
                        }
                        else if (nextChar == bracketQuoteChar)
                        {
                            bracketQuoteChar = ' ';
                        }
                        continue;
                    }
                    if (quoteChar == ' ')
                    {
                        quoteChar = nextChar;
                    }
                    else if (nextChar == quoteChar)
                    {
                        /*
                         *             A matching quote character has been found.  Check for two
                         *             adjacent single quotes which represent an embedded single
                         *             quote.
                         */
                        if (i < inputString.length() - 1 & quoteChar == '\'')
                        {
                            if (inputString.charAt(i + 1) == '\'')
                            {
                                i++;
                            }
                            else
                            {
                                quoteChar = ' ';
                            }
                        }
                        else
                        {
                            quoteChar = ' ';
                        }
                    }
                }
                else if (nextChar == '(' | nextChar == ')')
                {
                    /*
                     *          Ignore brackets inside quoted strings.
                     */
                    if (quoteChar != ' ' | bracketQuoteChar != ' ')
                    {
                        continue;
                    }
                    if (nextChar == '(')
                    {
                        leftBracketCount++;

                        /*
                         *             If bracket is the separator, return the string before the
                         *             left bracket.
                         */
                        if (separator == '(' & leftBracketCount == 1)
                        {
                            tempString = "";
                            if (endPosn > startPosn)
                            {
                                tempString = inputString.substring(startPosn, endPosn);
                            }
                            if (tempString.trim().length() > 0)
                            {
                                tempStrings.addElement(tempString.trim());
                            }
                            if (returnSep)
                            {
                                tempStrings.addElement("(");
                            }
                            startPosn = endPosn + 1;
                        }
                    }
                    else if (nextChar == ')')
                    {
                        /*
                         *             Handle nested sets of brackets.
                         */
                        rightBracketCount++;
                        if (leftBracketCount > 0 &
                            leftBracketCount == rightBracketCount)
                        {
                            if (separator == '(')
                            {
                                /*
                                 *                   If bracket is the separator, return the string between the
                                 *                   brackets.
                                 */
                                tempString = "";
                                if (endPosn > startPosn)
                                {
                                    tempString = inputString.substring(startPosn, endPosn);
                                }
                                if (tempString.trim().length() > 0)
                                {
                                    tempStrings.addElement(tempString.trim());
                                }
                                if (returnSep)
                                {
                                    tempStrings.addElement(")");
                                }
                                startPosn = endPosn + 1;
                            }
                            leftBracketCount  = 0;
                            rightBracketCount = 0;
                        }
                    }

                    /*
                     *          If the separator character has been found and we are not within
                     *          brackets and we are not within a quoted string (as indicated
                     *          by a blank quoteChar value), then build the next output string.
                     */
                }
                else if (nextChar == separator & leftBracketCount == 0 &
                         quoteChar == ' ')
                {
                    tempString = "";
                    if (endPosn > startPosn)
                    {
                        tempString = inputString.substring(startPosn, endPosn).trim();
                    }
                    if (tempString.length() > 0)
                    {
                        tempStrings.addElement(tempString);
                    }
                    if (returnSep)
                    {
                        tempStrings.addElement(new String(charArray));
                    }
                    startPosn = endPosn + 1;
                }
            }

            /*
             *    Pick up the last string if there is one.
             */
            if (endPosn >= startPosn)
            {
                tempString = inputString.substring(startPosn, endPosn + 1).trim();
                if (tempString.length() > 0)
                {
                    tempStrings.addElement(tempString);
                }
            }

            /*
             *    Create output string array from Vector.
             */
            if (tempStrings.size() == 0)
            {
                fields    = new String[1];
                fields[0] = inputString;
                if (debug)
                {
                    java.lang.SystemJ.outJ.println("FieldTokenizer output: <" + inputString + ">");
                }
            }
            else
            {
                fields = new String[tempStrings.size()];
                for (i = 0; i < tempStrings.size(); i++)
                {
                    fields[i] = (String)tempStrings.elementAt(i);
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("FieldTokenizer output[" + i + "]: <"
                                                       + fields[i] + ">");
                    }
                }
            }
            fieldIndex = 0;
        }
Exemple #29
0
		public java.util.Vector ls(String path) 
		{ //throws SftpException{
			try
			{
				path=remoteAbsolutePath(path);

				String dir=path;
				byte[] pattern=null;
				SftpATTRS attr=null;
				if(isPattern(dir) || 
					((attr=stat(dir))!=null && !attr.isDir()))
				{
					int foo=path.lastIndexOf('/');
					dir=path.substring(0, ((foo==0)?1:foo));
					pattern=path.substring(foo+1).getBytes();
				}

				sendOPENDIR(dir.getBytes());

				Header _header=new Header();
				_header=header(buf, _header);
				int length=_header.length;
				int type=_header.type;
				buf.rewind();
				fill(buf.buffer, 0, length);

				if(type!=SSH_FXP_STATUS && type!=SSH_FXP_HANDLE)
				{
					throw new SftpException(SSH_FX_FAILURE, "");
				}
				if(type==SSH_FXP_STATUS)
				{
					int i=buf.getInt();
					throwStatusError(buf, i);
				}

				byte[] handle=buf.getString();         // filename

				java.util.Vector v=new java.util.Vector();
				while(true)
				{
					sendREADDIR(handle);

					_header=header(buf, _header);
					length=_header.length;
					type=_header.type;
					if(type!=SSH_FXP_STATUS && type!=SSH_FXP_NAME)
					{
						throw new SftpException(SSH_FX_FAILURE, "");
					}
					if(type==SSH_FXP_STATUS)
					{ 
						buf.rewind();
						fill(buf.buffer, 0, length);
						int i=buf.getInt();
						if(i==SSH_FX_EOF)
							break;
						throwStatusError(buf, i);
					}

					buf.rewind();
					fill(buf.buffer, 0, 4); length-=4;
					int count=buf.getInt();

					byte[] str;
					int flags;

					buf.reset();
					while(count>0)
					{
						if(length>0)
						{
							buf.shift();
							int j=(buf.buffer.Length>(buf.index+length)) ? length : (buf.buffer.Length-buf.index);
							int i=fill(buf.buffer, buf.index, j);
							buf.index+=i;
							length-=i;
						}
						byte[] filename=buf.getString();
						str=buf.getString();
						String longname=new String(str);

						SftpATTRS attrs=SftpATTRS.getATTR(buf);
						if(pattern==null || Util.glob(pattern, filename))
						{
							v.addElement(new LsEntry(new String(filename), longname, attrs));
						}

						count--; 
					}
				}
				_sendCLOSE(handle, _header);
				return v;
			}
			catch(Exception e)
			{
				if(e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, "");
			}
		}
Exemple #30
0
        /**
         * Creates new Columns in tableName, given a vector of
         * column definition (tsColumn) arrays.<br>
         * It is necessary to copy the whole file to do this task.
         *
         * ALTER TABLE table [ * ] ADD [ COLUMN ] column type
         *
         * @param tableName the name of the table
         * @param v a Vector containing arrays of column definitions.
         * @see tinySQL#AlterTableAddCol
         */
        internal override void AlterTableAddCol(String tableName, java.util.Vector <Object> v)
        {//throws IOException, tinySQLException {
            // rename the file ...
            String fullpath = dataDir + java.io.File.separator + tableName + DBFFileTable.dbfExtension;
            String tmppath  = dataDir + java.io.File.separator + tableName + "_tmp_tmp" + DBFFileTable.dbfExtension;

            if (Utils.renameFile(fullpath, tmppath) == false)
            {
                throw new TinySQLException("ALTER TABLE ADD COL error in renaming " + fullpath);
            }

            try
            {
                // open the old file ...
                java.io.RandomAccessFile ftbl_tmp = new java.io.RandomAccessFile(tmppath, "r");

                // read the first 32 bytes ...
                DBFHeader dbfHeader_tmp = new DBFHeader(ftbl_tmp);

                // read the column info ...
                java.util.Vector <Object> coldef_list = new java.util.Vector <Object>(dbfHeader_tmp.numFields + v.size());
                int locn = 0; // offset of the current column
                for (int i = 1; i <= dbfHeader_tmp.numFields; i++)
                {
                    TsColumn coldef = readColdef(ftbl_tmp, tableName, i, locn);
                    locn += coldef.size; // increment locn by the length of this field.
                    coldef_list.addElement(coldef);
                }

                // add the new column definitions to the existing ...
                for (int jj = 0; jj < v.size(); jj++)
                {
                    coldef_list.addElement(v.elementAt(jj));
                }

                // create the new table ...
                CreateTable(tableName, coldef_list);

                // copy the data from old to new

                // opening new created dBase file ...
                java.io.RandomAccessFile ftbl = new java.io.RandomAccessFile(fullpath, "rw");
                ftbl.seek(ftbl.length()); // go to end of file

                int numRec = 0;
                for (int iRec = 1; iRec <= dbfHeader_tmp.numRecords; iRec++)
                {
                    String str = GetRecord(ftbl_tmp, dbfHeader_tmp, iRec);

                    // Utils.log("Copy of record#" + iRec + " str='" + str + "' ...");

                    if (str == null)
                    {
                        continue;                           // record was marked as deleted, ignore it
                    }
                    ftbl.write(str.getBytes(Utils.encode)); // write original record
                    numRec++;

                    for (int iCol = 0; iCol < v.size(); iCol++) // write added columns
                    {
                        TsColumn coldef = (TsColumn)v.elementAt(iCol);

                        // enforce the correct column length
                        String value = Utils.forceToSize(coldef.defaultVal, coldef.size, " ");

                        // transform to byte and write to file
                        byte[] b = value.getBytes(Utils.encode);
                        ftbl.write(b);
                    }
                }

                ftbl_tmp.close();

                DBFHeader.writeNumRecords(ftbl, numRec);
                ftbl.close();

                Utils.delFile(tmppath);
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }
Exemple #31
0
        public SimpleXMLTag(String inputString, int startAt, java.util.Vector <Object> inputList)
        //throws Exception
        {
            char quoteChar, nextChar;

            char[]       charArray = { ' ' };
            SimpleXMLTag embeddedXML;
            int          i, j, startBodyAt, endBodyAt, tagNameEndAt, embeddedTagAt;
            String       testString, bodyString;

            tagList = inputList;
            if (inputString.length() == 0)
            {
                throw new Exception("XML record is null.");
            }

            /*
             *    Search the body for the ending tag, ignoring everything in quotes.
             */
            quoteChar     = ' ';
            embeddedTagAt = -1;
            tagName       = (String)null;
            tagNameEndAt  = java.lang.Integer.MIN_VALUE;
            startBodyAt   = java.lang.Integer.MIN_VALUE;
            for (i = startAt; i < inputString.length(); i++)
            {
                nextChar = inputString.charAt(i);
                if (nextChar == '\'' | nextChar == '"')
                {
                    if (quoteChar == ' ')
                    {
                        quoteChar = nextChar;
                    }
                    else if (nextChar == quoteChar)
                    {
                        quoteChar = ' ';
                    }
                }

                /*
                 *       Ignore all characters in quoted strings.
                 */
                if (quoteChar != ' ')
                {
                    continue;
                }
                if (nextChar == '<')
                {
                    if (tagName == (String)null)
                    {
                        /*
                         *             The tag has been found.  Save any text before the tag as a label.
                         */
                        tagNameEndAt = inputString.indexOf('>', i);
                        if (tagNameEndAt < 0)
                        {
                            throw new Exception("Tag is incomplete");
                        }
                        tagName = inputString.substring(i + 1, tagNameEndAt);
                        if (debug)
                        {
                            java.lang.SystemJ.outJ.println("Found tag " + tagName);
                        }
                        startBodyAt = tagNameEndAt + 1;
                        for (j = tagNameEndAt + 1; j < inputString.length(); j++)
                        {
                            if (inputString.charAt(j) == ' ')
                            {
                                continue;
                            }
                            startBodyAt = j;
                            if (debug)
                            {
                                java.lang.SystemJ.outJ.println("Start body at " + j);
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (i + tagName.length() + 1 > inputString.length() - 1)
                        {
                            throw new Exception("XML record ends prematurely.");
                        }

                        /*
                         *             Search for the end of the tag.
                         */
                        testString = inputString.substring(i + 1, i + tagName.length() + 2);
                        if (testString.equals("/" + tagName))
                        {
                            endBodyAt = i - 1;
                            if (debug)
                            {
                                java.lang.SystemJ.outJ.println("End body at " + endBodyAt);
                            }
                            bodyString = inputString.substring(startBodyAt, endBodyAt + 1);
                            tagEndAt   = i + tagName.length() + 2;
                            if (debug)
                            {
                                java.lang.SystemJ.outJ.println("Tag body is " + bodyString);
                            }
                            put("TAG_NAME", tagName);
                            tagList.addElement(this);
                            if (embeddedTagAt > -1)
                            {
                                /*
                                 *                   The tag body contains one or more embedded tags
                                 *                   which have to be parsed recursively.
                                 */
                                if (embeddedTagAt > startBodyAt)
                                {
                                    tagLabel = inputString.substring(startBodyAt, embeddedTagAt).trim();
                                    if (tagLabel.length() > 0)
                                    {
                                        if (debug)
                                        {
                                            java.lang.SystemJ.outJ.println("label " + tagLabel);
                                        }
                                        put("LABEL", tagLabel);
                                    }
                                }
                                while (embeddedTagAt < endBodyAt)
                                {
                                    embeddedXML = new SimpleXMLTag(inputString,
                                                                   embeddedTagAt, tagList);
                                    put(tagName, embeddedXML);
                                    if (debug)
                                    {
                                        java.lang.SystemJ.outJ.println("Tag "
                                                                       + embeddedXML.tagName + " ends at "
                                                                       + embeddedXML.tagEndAt);
                                    }
                                    embeddedTagAt = embeddedXML.tagEndAt + 1;
                                }
                            }
                            else
                            {
                                put(tagName, bodyString);
                            }
                            break;
                        }
                        else if (embeddedTagAt == -1)
                        {
                            embeddedTagAt = i;
                            if (debug)
                            {
                                java.lang.SystemJ.outJ.println("embeddedTagAt=" + embeddedTagAt);
                            }
                        }
                    }
                }
            }
        }
Exemple #32
0
        /**
         *
         * Deletes Columns from tableName, given a vector of
         * column definition (tsColumn) arrays.<br>
         *
         * ALTER TABLE table DROP [ COLUMN ] column { RESTRICT | CASCADE }
         *
         * @param tableName the name of the table
         * @param v a Vector containing arrays of column definitions.
         * @see tinySQL#AlterTableDropCol
         *
         */
        internal override void AlterTableDropCol(String tableName, java.util.Vector <Object> v)
        {//throws IOException, tinySQLException {
            // rename the file ...
            String fullpath = dataDir + java.io.File.separator + tableName + DBFFileTable.dbfExtension;
            String tmppath  = dataDir + java.io.File.separator + tableName + "-tmp" + DBFFileTable.dbfExtension;

            if (Utils.renameFile(fullpath, tmppath) == false)
            {
                throw new TinySQLException("ALTER TABLE DROP COL error in renaming " + fullpath);
            }

            try
            {
                // open the old file ...
                java.io.RandomAccessFile ftbl_tmp = new java.io.RandomAccessFile(tmppath, "r");

                // read the first 32 bytes ...
                DBFHeader dbfHeader_tmp = new DBFHeader(ftbl_tmp);

                // read the column info ...
                java.util.Vector <Object> coldef_list = new java.util.Vector <Object>(dbfHeader_tmp.numFields - v.size());
                int locn = 0; // offset of the current column

                nextCol : for (int i = 1; i <= dbfHeader_tmp.numFields; i++)
                {
                    TsColumn coldef = readColdef(ftbl_tmp, tableName, i, locn);

                    // remove the DROP columns from the existing cols ...
                    for (int jj = 0; jj < v.size(); jj++)
                    {
                        String colName = (String)v.elementAt(jj);
                        if (coldef.name.equals(colName))
                        {
                            Utils.log("Dropping " + colName);
                            goto nextCol;
                        }
                    }

                    locn += coldef.size; // increment locn by the length of this field.
                    // Utils.log("Recycling " + coldef.name);
                    coldef_list.addElement(coldef);
                }

                // create the new table ...
                CreateTable(tableName, coldef_list);

                // copy the data from old to new

                // opening new created dBase file ...
                java.io.RandomAccessFile ftbl = new java.io.RandomAccessFile(fullpath, "rw");
                ftbl.seek(ftbl.length()); // go to end of file

                int numRec = 0;
                for (int iRec = 1; iRec <= dbfHeader_tmp.numRecords; iRec++)
                {
                    if (DBFFileTable.isDeleted(ftbl_tmp, dbfHeader_tmp, iRec) == true)
                    {
                        continue;
                    }

                    numRec++;

                    ftbl.write(DBFFileTable.RECORD_IS_NOT_DELETED);  // write flag

                    // Read the whole column into the table's cache
                    String column = DBFFileTable._GetCol(ftbl_tmp, dbfHeader_tmp, iRec);

                    for (int iCol = 0; iCol < coldef_list.size(); iCol++) // write columns
                    {
                        TsColumn coldef = (TsColumn)coldef_list.elementAt(iCol);

                        // Extract column values from cache
                        String value = DBFFileTable.getColumn(coldef, column);
                        java.lang.SystemJ.outJ.println("From cache column value" + value);

                        value = Utils.forceToSize(value, coldef.size, " "); // enforce the correct column length

                        byte[] b = value.getBytes(Utils.encode);            // transform to byte and write to file
                        ftbl.write(b);
                    }
                }

                ftbl_tmp.close();

                // remove temp file
                java.io.File f = new java.io.File(tmppath);
                if (f.exists())
                {
                    f.delete();
                }

                DBFHeader.writeNumRecords(ftbl, numRec);
                ftbl.close();
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }
Exemple #33
0
        public bool addRow(TsRow row, bool sortRows)
        {
            int   i;
            bool  sortUp = true;
            TsRow sortRow;

            if (!sortRows)
            {
                rows.addElement(row);
                return(true);
            }
            if (orderType != (String)null)
            {
                if (orderType.startsWith("DESC"))
                {
                    sortUp = false;
                }
            }

            /*
             *    Pass the list of ORDER BY columns to the new row to enable
             *    compareTo method.
             */
            row.setOrderBy(orderByColumns);
            if (rows.size() > 0)
            {
                /*
                 *       Insert or append the row depending upon the ORDER BY
                 *       conditions and a comparison of the new and the existing row.
                 */
                if (sortUp)
                {
                    for (i = rows.size() - 1; i > -1; i--)
                    {
                        sortRow = (TsRow)rows.elementAt(i);
                        if (row.compareTo(sortRow) < 0)
                        {
                            continue;
                        }
                        if (row.compareTo(sortRow) == 0 & distinct)
                        {
                            return(true);
                        }
                        if (i == rows.size() - 1)
                        {
                            rows.addElement(row);
                        }
                        else
                        {
                            rows.insertElementAt(row, i + 1);
                        }
                        return(true);
                    }
                }
                else
                {
                    for (i = rows.size() - 1; i > -1; i--)
                    {
                        sortRow = (TsRow)rows.elementAt(i);
                        if (row.compareTo(sortRow) > 0)
                        {
                            continue;
                        }
                        if (row.compareTo(sortRow) == 0 & distinct)
                        {
                            return(true);
                        }
                        if (i == rows.size() - 1)
                        {
                            rows.addElement(row);
                        }
                        else
                        {
                            rows.insertElementAt(row, i + 1);
                        }
                        return(true);
                    }
                }
                rows.insertElementAt(row, 0);
                return(true);
            }
            rows.addElement(row);
            if ((fetchsize > 0) && (rows.size() >= fetchsize))
            {
                return(false);
            }
            return(true);
        }
Exemple #34
0
        /*
         * opens a DBF file. This is based on Pratap Pereira's
         * Xbase.pm perl module
         * @return column definition list (java.util.Hashtable<Object,Object>)
         *
         * @author Thomas Morgner <*****@*****.**> added check for
         * file exists, before the file is opened. Opening a non existing
         * file will create a new file, and we get errors while trying
         * to read the non-existend headers
         */
        java.util.Hashtable <Object, Object> open_dbf() //throws TinySQLException
        {
            try
            {
                java.io.File f = new java.io.File(fullPath);
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Try to open  " + f.getAbsolutePath());
                }
                if (!f.exists())
                {
                    throw new TinySQLException("Unable to open " + f.getAbsolutePath()
                                               + " - does not exist. or can't be read.");
                }
                else if (!f.canRead())
                {
                    throw new TinySQLException("Unable to open " + f.getAbsolutePath()
                                               + " - file can't be read (permissions?).");
                }
                if (f.canWrite())
                {
                    ftbl = new java.io.RandomAccessFile(f, "rw");
                }
                else
                {
                    /*
                     *          Open readonly if the file is not writeable. Needed for
                     *          databases on CD-Rom
                     */
                    ftbl = new java.io.RandomAccessFile(f, "r");
                }

                /*
                 *       Read the first 32 bytes ...
                 */
                dbfHeader = new DBFHeader(ftbl);

                /*
                 *       read the column info (each is a 32 byte bulk) ...
                 */
                java.util.Hashtable <Object, Object> coldef_list = new java.util.Hashtable <Object, Object>();
                columnNameKeys = new java.util.Vector <Object>();
                int locn = 0; // offset of the current column
                for (int i = 1; i <= dbfHeader.numFields; i++)
                {
                    TsColumn coldef = DBFFile.readColdef(ftbl, table, i, locn);
                    locn += coldef.size; // increment locn by the length of this field.
                    coldef_list.put(coldef.name, coldef);
                    columnNameKeys.addElement(coldef.name);
                }
                fileOpen = true;
                return(coldef_list);
            }
            catch (Exception e)
            {
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.err.println(e.ToString());                      // e.printStackTrace();
                }
                throw new TinySQLException(e.getMessage());
            }
        }