Example #1
0
        static void Main()
        {
            try
            {
                String recipient = "*****@*****.**";
                String subject   = "Hello";
                String content   = "Hello JavApi user!";
                String from1     = "*****@*****.**";

                java.util.Properties props = new java.util.Properties();
                props.put("mail.smtp.host", "post.example.com");
                props.put("mail.smtp.port", "25");
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.user", "*****@*****.**");
                props.put("mail.smtp.password", "secret");
                javax.mail.Session session = javax.mail.Session.getDefaultInstance(props);
                javax.mail.Message msg     = new javax.mail.internet.MimeMessage(session);
                javax.mail.internet.InternetAddress addressFrom = new javax.mail.internet.InternetAddress(from1);
                msg.setFrom(addressFrom);
                javax.mail.internet.InternetAddress addressTo = new javax.mail.internet.InternetAddress(recipient);
                msg.setRecipient(javax.mail.Message.RecipientType.TO, addressTo);
                msg.setSubject(subject);
                msg.setContent(content, "text/plain");
                javax.mail.Transport.send(msg);
            }
            catch (javax.mail.SendFailedException)
            {
            }
            catch (javax.mail.MessagingException)
            {
            }
        }
        static void Main()
        {
            bool forms = true;

            if (forms)
            {
                // Step 0: Show system configuration
                java.lang.SystemJ.outJ.println("awt.toolkit=" + java.lang.SystemJ.getProperty("awt.toolkit"));
                java.lang.SystemJ.outJ.println("java.awt.headless=" + java.lang.SystemJ.getProperty("java.awt.headless"));

                // Step 1:
                java.awt.Frame formsFrame = new java.awt.Frame("Hello AWT over Windows Forms!");
                formsFrame.setSize(800, 600);
                formsFrame.setVisible(true);
            }
            else
            {
                // Step 2: Redirect to WPF
                java.util.Properties prop = java.lang.SystemJ.getProperties();
                prop.put("awt.toolkit", "biz.ritter.awt.wpf.WPFToolkit");

                // Step 3: Show system configuration
                java.lang.SystemJ.outJ.println("awt.toolkit=" + java.lang.SystemJ.getProperty("awt.toolkit"));
                java.lang.SystemJ.outJ.println("java.awt.headless=" + java.lang.SystemJ.getProperty("java.awt.headless"));

                // Step 4: we use Windows Presentation Framework
                java.awt.Frame wpfFrame = new java.awt.Frame("Hello AWT over Windows Presentation Framework");
                wpfFrame.setSize(400, 300);
                wpfFrame.setVisible(true);
            }
        }
Example #3
0
 /// <summary>
 /// Create new instance with given URL
 /// </summary>
 /// <param name="url"></param>
 protected internal Connection(java.net.URL url) : base(url)
 {
     this.url = url;
     this.requestProperties = new java.util.Properties();
     this.addRequestProperty("User-Agent", "Vampire/" + java.lang.SystemJ.getProperty("java.version"));
     this.addRequestProperty("Referer", "http://www.Ritter.biz");
 }
Example #4
0
        static void Main()
        {
            try
            {

                String recipient = "*****@*****.**";
                String subject = "Hello";
                String content = "Hello JavApi user!";
                String from1 = "*****@*****.**";

                java.util.Properties props = new java.util.Properties();
                props.put("mail.smtp.host", "post.example.com");
                props.put("mail.smtp.port", "25");
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.user", "*****@*****.**");
                props.put("mail.smtp.password", "secret");
                javax.mail.Session session = javax.mail.Session.getDefaultInstance(props);
                javax.mail.Message msg = new javax.mail.internet.MimeMessage(session);
                javax.mail.internet.InternetAddress addressFrom = new javax.mail.internet.InternetAddress(from1);
                msg.setFrom(addressFrom);
                javax.mail.internet.InternetAddress addressTo = new javax.mail.internet.InternetAddress(recipient);
                msg.setRecipient(javax.mail.Message.RecipientType.TO, addressTo);
                msg.setSubject(subject);
                msg.setContent(content, "text/plain");
                javax.mail.Transport.send(msg);
            }
            catch (javax.mail.SendFailedException/*sfe*/)
            {

            }
            catch (javax.mail.MessagingException/*me*/)
            {
            }
        }
Example #5
0
 static void flushFilePrefsImpl(java.io.File file, java.util.Properties prefs)
 {        //throws IOException {
     java.io.BufferedWriter     outJ  = null;
     java.nio.channels.FileLock lockJ = null;
     try {
         java.io.FileOutputStream ostream = new java.io.FileOutputStream(file);
         outJ = new java.io.BufferedWriter(new java.io.OutputStreamWriter(ostream, "UTF-8"));                   //$NON-NLS-1$
         java.nio.channels.FileChannel channel = ostream.getChannel();
         lockJ = channel.lockJ();
         outJ.write(HEADER);
         outJ.newLine();
         outJ.write(FILE_PREFS);
         outJ.newLine();
         if (prefs.size() == 0)
         {
             exportEntries(EMPTY_SARRAY, EMPTY_SARRAY, outJ);
         }
         else
         {
             String[] keys = prefs.keySet()
                             .toArray(new String[prefs.size()]);
             int      length = keys.Length;
             String[] values = new String[length];
             for (int i = 0; i < length; i++)
             {
                 values [i] = prefs.getProperty(keys [i]);
             }
             exportEntries(keys, values, outJ);
         }
         outJ.flush();
     } finally {
         releaseQuietly(lockJ);
         closeQuietly(outJ);
     }
 }
Example #6
0
        /**
         * Attempts to establish a connection to the given database URL.
         *
         * @param url
         *            a URL string representing the database target to connect with
         * @param info
         *            a set of properties to use as arguments to set up the
         *            connection. Properties are arbitrary string/value pairs.
         *            Normally, at least the properties {@code "user"} and {@code
         *            "password"} should be passed, with appropriate settings for
         *            the user ID and its corresponding password to get access to
         *            the corresponding database.
         * @return a {@code Connection} to the database identified by the URL.
         *         {@code null} if no connection can be established.
         * @throws SQLException
         *             if there is an error while attempting to connect to the
         *             database identified by the URL.
         */
        public static Connection getConnection(String url, java.util.Properties info)
        {//throws SQLException {
            // 08 - connection exception
            // 001 - SQL-client unable to establish SQL-connection
            String sqlState = "08001"; //$NON-NLS-1$

            if (url == null)
            {
                // sql.5=The url cannot be null
                throw new SQLException("The url cannot be null", sqlState); //$NON-NLS-1$
            }
            lock (theDrivers)
            {
                /*
                 * Loop over the drivers in the DriverSet checking to see if one can
                 * open a connection to the supplied URL - return the first
                 * connection which is returned
                 */
                foreach (Driver theDriver in theDrivers)
                {
                    Connection theConnection = theDriver.connect(url, info);
                    if (theConnection != null)
                    {
                        return(theConnection);
                    }
                }
            }
            // If we get here, none of the drivers are able to resolve the URL
            // sql.6=No suitable driver
            throw new SQLException("No suitable driver", sqlState); //$NON-NLS-1$
        }
Example #7
0
        /*
         * Substitutes all entries like ${some.key}, found in specified string,
         * for specified values.
         * If some key is unknown, throws ExpansionFailedException.
         * @param str the string to be expanded
         * @param properties available key-value mappings
         * @return expanded string
         * @throws ExpansionFailedException
         */
        public static String expand(String str, java.util.Properties properties)
        {//throws ExpansionFailedException {
            java.lang.StringBuilder result = new java.lang.StringBuilder(str);
            int start = result.indexOf(START_MARK);

            while (start >= 0)
            {
                int end = result.indexOf(END_MARK, start);
                if (end >= 0)
                {
                    String key   = result.substring(start + START_OFFSET, end);
                    String value = properties.getProperty(key);
                    if (value != null)
                    {
                        result.replace(start, end + END_OFFSET, value);
                        start += value.length();
                    }
                    else
                    {
                        throw new ExpansionFailedException("Unknown key: " + key); //$NON-NLS-1$
                    }
                }
                start = result.indexOf(START_MARK, start);
            }
            return(result.toString());
        }
Example #8
0
 public static Session getDefaultInstance(java.util.Properties prop)
 {
     if (null == instance)
     {
         instance       = new Session();
         instance.props = prop;
     }
     return(instance);
 }
Example #9
0
        public void Test_LoadProperties()
        {
            java.util.Properties p = java.lang.SystemJ.getProperties();
            p.list(java.lang.SystemJ.outJ);
            p.load(new java.io.FileInputStream(new java.io.File(this.rootDir + "tests/data/java.util.Properties.properties")));
            p.list(java.lang.SystemJ.outJ);
            Assert.AreEqual("world", p.getProperty("hello"), "Propertyfile load test");
//			Assert.AreEqual("Ägypten", p.getProperty("state"), "Propertyfile load test");
        }
Example #10
0
        /**
         *
         * Check the syntax of the URL.
         * @see java.sql.Driver#connect
         * @param url the URL for the database in question
         * @param info the properties object
         * @return null if the URL should be ignored, or a new Connection
         *         object if the URL is a valid tinySQL URL
         *
         */
        public java.sql.Connection connect(String url, java.util.Properties info)
        {//throws SQLException {
            if (!acceptsURL(url))
            {
                return(null);
            }

            // if it was a valid URL, return the new Connection
            //
            return(getConnection(info.getProperty("user"), url, this));
        }
Example #11
0
 /**
  * Attempts to establish a connection to the given database URL.
  *
  * @param url
  *            a URL string representing the database target to connect with.
  * @param user
  *            a user ID used to login to the database.
  * @param password
  *            a password for the user ID to login to the database.
  * @return a {@code Connection} to the database identified by the URL.
  *         {@code null} if no connection can be established.
  * @throws SQLException
  *             if there is an error while attempting to connect to the
  *             database identified by the URL.
  */
 public static Connection getConnection(String url, String user,
                                        String password)
 {//throws SQLException {
     java.util.Properties theProperties = new java.util.Properties();
     if (null != user)
     {
         theProperties.setProperty("user", user); //$NON-NLS-1$
     }
     if (null != password)
     {
         theProperties.setProperty("password", password); //$NON-NLS-1$
     }
     return(getConnection(url, theProperties));
 }
Example #12
0
        public void setClientInfo(java.util.Properties props)
        {
            java.util.HashMap <String, java.sql.ClientInfoStatus> errors = new java.util.HashMap <String, java.sql.ClientInfoStatus>();
            java.util.Enumeration <String> names = props.keys();
            String name = null;

            while (names.hasMoreElements())
            {
                try
                {
                    name = names.nextElement();
                    this.setClientInfo(name, props.get(name));
                }
                catch (java.sql.SQLClientInfoException) {
                    errors.put(name, java.sql.ClientInfoStatus.REASON_UNKNOWN);
                }
            }
            if (0 != errors.size())
            {
                throw new java.sql.SQLClientInfoException(errors);
            }
        }
Example #13
0
 /// <summary>
 /// Construct a reader passing a reference to a Hashtable (or JavaProperties) instance
 /// where the keys are to be stored.
 /// </summary>
 /// <param name="properties">A reference to a hashtable where the key-value pairs can be stored.</param>
 public JavaPropertyReader(java.util.Properties properties)
 {
     this.hashtable = hashtable;
 }
 // Conversion methods
 //-------------------------------------------------------------------------
 /**
  * Gets a new Properties object initialised with the values from a Map.
  * A null input will return an empty properties object.
  *
  * @param map  the map to convert to a Properties object, may not be null
  * @return the properties object
  */
 public static java.util.Properties toProperties(java.util.Map<Object, Object> map)
 {
     java.util.Properties answer = new java.util.Properties();
     if (map != null)
     {
         for (java.util.Iterator<java.util.MapNS.Entry<Object, Object>> iter = map.entrySet().iterator(); iter.hasNext(); )
         {
             java.util.MapNS.Entry<Object, Object> entry = iter.next();
             Object key = entry.getKey();
             Object value = entry.getValue();
             answer.put(key, value);
         }
     }
     return answer;
 }
Example #15
0
 /**
  *
  * The getPropertyInfo method is intended to allow a generic GUI tool to
  * discover what properties it should prompt a human for in order to get
  * enough information to connect to a database.  Note that depending on
  * the values the human has supplied so far, additional values may become
  * necessary, so it may be necessary to iterate though several calls
  * to getPropertyInfo.
  *
  * @param url The URL of the database to connect to.
  * @param info A proposed list of tag/value pairs that will be sent on
  *          connect open.
  * @return An array of DriverPropertyInfo objects describing possible
  *          properties.  This array may be an empty array if no properties
  *          are required.
  *
  */
 public java.sql.DriverPropertyInfo[] getPropertyInfo(String url,
                                                      java.util.Properties info)
 {//throws SQLException {
     return(new java.sql.DriverPropertyInfo[0]);
 }
Example #16
0
        // static initialization
        // - load security properties files
        // - load statically registered providers
        // - if no provider description file found then load default providers
        static Security()
        {
            bool loaded = false;
            java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home") //$NON-NLS-1$
                    + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$
                    + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
            if (f.exists())
            {
                try
                {
                    java.io.FileInputStream fis = new java.io.FileInputStream(f);
                    java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis);
                    secprops.load(isJ);
                    loaded = true;
                    isJ.close();
                }
                catch (java.io.IOException e)
                {
                    //                        System.err.println("Could not load Security properties file: "
                    //                                        + e);
                }
            }

            if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true")))
            { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$
                if (securityFile != null)
                {
                    if (securityFile.startsWith("="))
                    { // overwrite //$NON-NLS-1$
                        secprops = new java.util.Properties();
                        loaded = false;
                        securityFile = securityFile.substring(1);
                    }
                    try
                    {
                        securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties());
                    }
                    catch (PolicyUtils.ExpansionFailedException e)
                    {
                        //                            System.err.println("Could not load custom Security properties file "
                        //                                    + securityFile +": " + e);
                    }
                    f = new java.io.File(securityFile);
                    java.io.InputStreamReader isj;
                    try
                    {
                        if (f.exists())
                        {
                            java.io.FileInputStream fis = new java.io.FileInputStream(f);
                            isj = new java.io.InputStreamReader(fis);
                        }
                        else
                        {
                            java.net.URL url = new java.net.URL(securityFile);
                            isj = new java.io.InputStreamReader(url.openStream());
                        }
                        secprops.load(isj);
                        loaded = true;
                        isj.close();
                    }
                    catch (java.io.IOException e)
                    {
                        //                           System.err.println("Could not load custom Security properties file "
                        //                                   + securityFile +": " + e);
                    }
                }
            }
            if (!loaded)
            {
                registerDefaultProviders();
            }
            Engine.door = new SecurityDoor();
        }
Example #17
0
 /// <summary>
 /// Construct a reader passing a reference to a Hashtable (or JavaProperties) instance
 /// where the keys are to be stored.
 /// </summary>
 /// <param name="hashtable">A reference to a hashtable where the key-value pairs can be stored.</param>
 public JavaPropertyReader(java.util.Properties properties)
 {
     this.hashtable = hashtable;
 }
Example #18
0
        public static util.Properties getProperties()
        {
            if (null == systemProperties)
            {
                // Collect the informations
                IDictionary          env  = Environment.GetEnvironmentVariables();
                java.util.Properties prop = new java.util.Properties(env);
                int    osMajor            = System.Environment.OSVersion.Version.Major;
                int    osMinior           = System.Environment.OSVersion.Version.Minor;
                int    osVersion          = osMajor * 10 + osMinior;
                String osName             = "Unknown";
                switch (System.Environment.OSVersion.Platform)
                {
                case PlatformID.WinCE:
                    osName = "Windows CE";
                    break;

                case PlatformID.Xbox:
                    osName = "XBox";
                    break;

                case PlatformID.Unix:
                    osName = "Unix";
                    break;

                case PlatformID.MacOSX:
                    osName = "MacOS";
                    break;

                case PlatformID.Win32S:
                    osName = "Windows 32";
                    break;

                case PlatformID.Win32Windows:
                    osName = "Windows ";
                    switch (osVersion)
                    {
                    case 40:
                        osName += "95";
                        break;

                    case 50:
                        osName += "98";
                        break;

                    case 130:
                        osName += "ME";
                        break;
                    }
                    break;

                case PlatformID.Win32NT:
                    osName = "Windows ";
                    switch (osVersion)
                    {
                    case 40:
                        osName += "NT 4.0";
                        break;

                    case 50:
                        osName += "2000";
                        break;

                    case 51:
                        osName += "XP";
                        break;

                    case 52:
                        osName += "Server 2003";
                        break;

                    case 60:
                        osName += "Vista";
                        break;

                    case 61:
                        osName += "7";
                        break;
                    }
                    break;
                }

                // store some Java system specific environment
                prop.Add("file.encoding", Encoding.Default.WebName);
                prop.Add("file.separator", "" + System.IO.Path.DirectorySeparatorChar);
                prop.Add("line.separator", System.Environment.NewLine);
                prop.Add("os.arch", System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));
                prop.Add("os.name", osName);
                prop.Add("os.version", osMajor + "." + osMinior);
                prop.Add("path.separator", "" + System.IO.Path.PathSeparator);
                prop.Add("user.country", System.Globalization.CultureInfo.CurrentCulture.Name.Substring(3, 2));
                prop.Add("user.dir", System.Environment.CurrentDirectory);
                // Mono 2.6.4 BugFix:
                if (PlatformID.Unix == System.Environment.OSVersion.Platform)
                {
                    prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                }
                else
                { // UserProfile not exist in Mono 2.6.4
                    prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
                }
                prop.Add("user.language", System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
                prop.Add("user.name", System.Environment.UserName);
                prop.Add("user.timezone", null); // content???
                prop.Add("user.variant", null);  // content???
                // Java specific environment
                prop.Add("java.vendor", "Sebastian Ritter");
                prop.Add("java.version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                prop.Add("java.class.path", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
                // Java net environment
                prop.Add("java.protocol.handler.pkgs", "biz.ritter.net.protocol|");
                // GUI specific environment
                prop.Add("awt.toolkit", "biz.ritter.awt.forms.FormsToolkit");
                // XML SAX/DOM/JAXP specific environment
                prop.Add("org.xml.sax.parser", null);                       // include the class for the default SAX Parser for example: org.apache.xerces.parsers.SaxParser
                prop.Add("javax.xml.parsers.SAXParserFactory", null);       // include the class for SAXParser for example: org.apache.xerces.jaxp.SAXParserFactoryImpl
                prop.Add("javax.xml.parsers.DocumentBuilderFactory", null); // include the class for DOMParser for example: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
                prop.Add("jaxp.debug", "false");                            // see f.e. javax.xml.parsers.FactoryFinder
                // Logging properties (see java.util.logging.LogManager)
                prop.Add("java.util.logging.config.class", null);
                prop.Add("java.util.logging.config.file", null);
                prop.Add("java.util.logging.manager", null);
                // IO properties
                prop.Add("java.io.tmpdir", System.IO.Path.GetTempPath());                 //using in logging FileHandler
                //Security properties - see java.security package
                prop.Add("java.security.properties", null);
                // Preferences properties
                prop.Add("java.util.prefs.PreferencesFactory", null);
                // JDBC properties
                prop.Add("jdbc.drivers", null);
                // Apache properties
                prop.Add("org.apache.xml.namespace.QName.useCompatibleSerialVersionUID", null);
                // ICU properties
                prop.Add("ICUDebug", null);
                // own important environment

                // Here it is...
                systemProperties = prop;
            }
            return(systemProperties);
        }
Example #19
0
 /// <summary>
 /// Construct an instance of this class.
 /// </summary>
 /// <param name="hashtable">The Hashtable (or JavaProperties) instance 
 /// whose values are to be written.</param>
 public JavaPropertyWriter( java.util.Properties hashtable )
 {
     this.hashtable = hashtable;
 }
Example #20
0
        // static initialization
        // - load security properties files
        // - load statically registered providers
        // - if no provider description file found then load default providers
        static Security()
        {
            bool loaded = false;

            java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home")                //$NON-NLS-1$
                                              + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$
                                              + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
            if (f.exists())
            {
                try
                {
                    java.io.FileInputStream   fis = new java.io.FileInputStream(f);
                    java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis);
                    secprops.load(isJ);
                    loaded = true;
                    isJ.close();
                }
                catch (java.io.IOException)
                {
                    //                        System.err.println("Could not load Security properties file: "
                    //                                        + e);
                }
            }

            if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true")))
            {                                                                                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$
                if (securityFile != null)
                {
                    if (securityFile.startsWith("="))
                    { // overwrite //$NON-NLS-1$
                        secprops     = new java.util.Properties();
                        loaded       = false;
                        securityFile = securityFile.substring(1);
                    }
                    try
                    {
                        securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties());
                    }
                    catch (PolicyUtils.ExpansionFailedException)
                    {
                        //                            System.err.println("Could not load custom Security properties file "
                        //                                    + securityFile +": " + e);
                    }
                    f = new java.io.File(securityFile);
                    java.io.InputStreamReader isj;
                    try
                    {
                        if (f.exists())
                        {
                            java.io.FileInputStream fis = new java.io.FileInputStream(f);
                            isj = new java.io.InputStreamReader(fis);
                        }
                        else
                        {
                            java.net.URL url = new java.net.URL(securityFile);
                            isj = new java.io.InputStreamReader(url.openStream());
                        }
                        secprops.load(isj);
                        loaded = true;
                        isj.close();
                    }
                    catch (java.io.IOException)
                    {
                        //                           System.err.println("Could not load custom Security properties file "
                        //                                   + securityFile +": " + e);
                    }
                }
            }
            if (!loaded)
            {
                registerDefaultProviders();
            }
            Engine.door = new SecurityDoor();
        }
Example #21
0
 static void flushFilePrefs(java.io.File file, java.util.Properties prefs)
 {        //throws PrivilegedActionException {
     flushFilePrefsImpl(file, prefs);
 }
Example #22
0
        public static util.Properties getProperties()
        {
            if (null == systemProperties)
            {
                // Collect the informations
                IDictionary env = Environment.GetEnvironmentVariables();
                java.util.Properties prop = new java.util.Properties(env);
                int osMajor = System.Environment.OSVersion.Version.Major;
                int osMinior = System.Environment.OSVersion.Version.Minor;
                int osVersion = osMajor * 10 + osMinior;
                String osName = "Unknown";
                switch (System.Environment.OSVersion.Platform)
                {
                    case PlatformID.WinCE:
                        osName = "Windows CE";
                        break;
                    case PlatformID.Xbox :
                        osName = "XBox";
                        break;
                    case PlatformID.Unix:
                        osName = "Unix";
                        break;
                    case PlatformID.MacOSX:
                        osName = "MacOS";
                        break;
                    case PlatformID.Win32S:
                        osName = "Windows 32";
                        break;
                    case PlatformID.Win32Windows:
                        osName = "Windows ";
                        switch (osVersion)
                        {
                            case 40 :
                                osName += "95";
                                break;
                            case 50 :
                                osName += "98";
                                break;
                            case 130:
                                osName += "ME";
                                break;
                        }
                        break;
                    case PlatformID.Win32NT:
                        osName = "Windows ";
                        switch (osVersion)
                        {
                            case 40:
                                osName += "NT 4.0";
                                break;
                            case 50:
                                osName += "2000";
                                break;
                            case 51:
                                osName += "XP";
                                break;
                            case 52:
                                osName += "Server 2003";
                                break;
                            case 60:
                                osName += "Vista";
                                break;
                            case 61:
                                osName += "7";
                                break;
                        }
                        break;
                }

                // store some Java system specific environment
                prop.Add("file.encoding", Encoding.Default.WebName);
                prop.Add("file.separator", System.IO.Path.DirectorySeparatorChar);
                prop.Add("line.separator", System.Environment.NewLine);
                prop.Add("os.arch", System.Environment.GetEnvironmentVariable ("PROCESSOR_ARCHITEW6432"));
                prop.Add("os.name", osName);
                prop.Add("os.version", osMajor+"."+osMinior);
                prop.Add("path.separator", System.IO.Path.PathSeparator);
                prop.Add("user.country", System.Globalization.CultureInfo.CurrentCulture.Name.Substring(3, 2));
                prop.Add("user.dir", System.Environment.CurrentDirectory);
                // Mono 2.6.4 BugFix:
                if (PlatformID.Unix == System.Environment.OSVersion.Platform)
                {
                    prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                }
                else
                { // UserProfile not exist in Mono 2.6.4
                    //prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
                    //.net frame 3.4 has not Environment.SpecialFolder.UserProfile

                    prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.Personal));

                    //need 4.0 support
                    //prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
                }
                prop.Add("user.language", System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
                prop.Add("user.name", System.Environment.UserName);
                prop.Add("user.timezone", null); // content???
                prop.Add("user.variant", null); // content???
                // Java specific environment
                prop.Add("java.vendor","Sebastian Ritter");
                prop.Add("java.version",System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                prop.Add("java.class.path", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
                // own important environment

                // Here it is...
                systemProperties = prop;
            }
            return systemProperties;
        }
Example #23
0
 /// <summary>
 /// Construct an instance of this class.
 /// </summary>
 /// <param name="hashtable">The Hashtable (or JavaProperties) instance
 /// whose values are to be written.</param>
 public JavaPropertyWriter(java.util.Properties hashtable)
 {
     this.hashtable = hashtable;
 }
Example #24
0
 /**
  * Attempts to establish a connection to the given database URL.
  *
  * @param url
  *            a URL string representing the database target to connect with.
  * @param user
  *            a user ID used to login to the database.
  * @param password
  *            a password for the user ID to login to the database.
  * @return a {@code Connection} to the database identified by the URL.
  *         {@code null} if no connection can be established.
  * @throws SQLException
  *             if there is an error while attempting to connect to the
  *             database identified by the URL.
  */
 public static Connection getConnection(String url, String user,
         String password)
 {
     //throws SQLException {
     java.util.Properties theProperties = new java.util.Properties();
     if (null != user)
     {
         theProperties.setProperty("user", user); //$NON-NLS-1$
     }
     if (null != password)
     {
         theProperties.setProperty("password", password); //$NON-NLS-1$
     }
     return getConnection(url, theProperties);
 }
Example #25
0
        public static util.Properties getProperties()
        {
            if (null == systemProperties)
            {
                // Collect the informations
                IDictionary env = Environment.GetEnvironmentVariables();
                java.util.Properties prop = new java.util.Properties(env);
                int osMajor = System.Environment.OSVersion.Version.Major;
                int osMinior = System.Environment.OSVersion.Version.Minor;
                int osVersion = osMajor * 10 + osMinior;
                String osName = "Unknown";
                switch (System.Environment.OSVersion.Platform)
                {
                    case PlatformID.WinCE:
                        osName = "Windows CE";
                        break;
                    case PlatformID.Xbox :
                        osName = "XBox";
                        break;
                    case PlatformID.Unix:
                        osName = "Unix";
                        break;
                    case PlatformID.MacOSX:
                        osName = "MacOS";
                        break;
                    case PlatformID.Win32S:
                        osName = "Windows 32";
                        break;
                    case PlatformID.Win32Windows:
                        osName = "Windows ";
                        switch (osVersion)
                        {
                            case 40 :
                                osName += "95";
                                break;
                            case 50 :
                                osName += "98";
                                break;
                            case 130:
                                osName += "ME";
                                break;
                        }
                        break;
                    case PlatformID.Win32NT:
                        osName = "Windows ";
                        switch (osVersion)
                        {
                            case 40:
                                osName += "NT 4.0";
                                break;
                            case 50:
                                osName += "2000";
                                break;
                            case 51:
                                osName += "XP";
                                break;
                            case 52:
                                osName += "Server 2003";
                                break;
                            case 60:
                                osName += "Vista";
                                break;
                            case 61:
                                osName += "7";
                                break;
                        }
                        break;
                }

                // store some Java system specific environment
                prop.Add("file.encoding", Encoding.Default.WebName);
                prop.Add("file.separator", ""+System.IO.Path.DirectorySeparatorChar);
                prop.Add("line.separator", System.Environment.NewLine);
                prop.Add("os.arch", System.Environment.GetEnvironmentVariable ("PROCESSOR_ARCHITEW6432"));
                prop.Add("os.name", osName);
                prop.Add("os.version", osMajor+"."+osMinior);
                prop.Add("path.separator", ""+System.IO.Path.PathSeparator);
                prop.Add("user.country", System.Globalization.CultureInfo.CurrentCulture.Name.Substring(3, 2));
                prop.Add("user.dir", System.Environment.CurrentDirectory);
                // Mono 2.6.4 BugFix:
                if (PlatformID.Unix == System.Environment.OSVersion.Platform)
                {
                    prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                }
                else
                { // UserProfile not exist in Mono 2.6.4
                    prop.Add("user.home", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
                }
                prop.Add("user.language", System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
                prop.Add("user.name", System.Environment.UserName);
                prop.Add("user.timezone", null); // content???
                prop.Add("user.variant", null); // content???
                // Java specific environment
                prop.Add("java.vendor","Sebastian Ritter");
                prop.Add("java.version",System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                prop.Add("java.class.path", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
                // Java net environment
                prop.Add("java.protocol.handler.pkgs", "biz.ritter.net.protocol|");
                // GUI specific environment
                prop.Add("awt.toolkit", "biz.ritter.awt.forms.FormsToolkit");
                // XML SAX/DOM/JAXP specific environment
                prop.Add("org.xml.sax.parser", null);// include the class for the default SAX Parser for example: org.apache.xerces.parsers.SaxParser
                prop.Add("javax.xml.parsers.SAXParserFactory", null); // include the class for SAXParser for example: org.apache.xerces.jaxp.SAXParserFactoryImpl
                prop.Add("javax.xml.parsers.DocumentBuilderFactory", null); // include the class for DOMParser for example: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
                prop.Add ("jaxp.debug", "false"); // see f.e. javax.xml.parsers.FactoryFinder
                // Logging properties (see java.util.logging.LogManager)
                prop.Add("java.util.logging.config.class", null);
                prop.Add("java.util.logging.config.file", null);
                prop.Add("java.util.logging.manager", null);
                // IO properties
                prop.Add("java.io.tmpdir", System.IO.Path.GetTempPath()); //using in logging FileHandler
                //Security properties - see java.security package
                prop.Add("java.security.properties", null);
                // Preferences properties
                prop.Add("java.util.prefs.PreferencesFactory", null);
                // JDBC properties
                prop.Add("jdbc.drivers", null);
                // Apache properties
                prop.Add("org.apache.xml.namespace.QName.useCompatibleSerialVersionUID", null);
                // ICU properties
                prop.Add("ICUDebug", null);
                // own important environment

                // Here it is...
                systemProperties = prop;
            }
            return systemProperties;
        }