Moved samples

This commit is contained in:
2014-11-23 22:33:56 +00:00
parent b0cfd2584f
commit 1dfb020787
69 changed files with 711 additions and 913 deletions

View File

@@ -1,8 +0,0 @@
The ADO sample is a wrapper for the ADO classes. This demonstrates how
to write JACOB wrappers.
The applet sample shows how to use JACOB in an applet. The trick is to
initialize and use the COM object in the same thread.
The test directory has numerous tests that test various features
of the JACOB functionality.

View File

@@ -1,74 +0,0 @@
package com.jacob.samples.JavaWebStart;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import com.jacob.com.LibraryLoader;
/**
* It is sometimes necessary to run Jacob without being able to install the dll
* on the client machine. This is true in JavaWebStart (JWS) and possibly Applet
* (assuming security allows access to the file system). The obvious thing to do
* here is to jar up the Jacob.dll so that it can be downloaded the client along
* with the rest of the resources. This is simple except that the System.Load()
* function does not search jar files for DLLs. It searches the classpath. The
* work around to this problem is to write the DLL to a temporary file and then
* explicitly load the DLL calling passing the full path to the temporary file.
*
* The following code demonstrates this idea.
*
* @author joe
*
*/
public class DLLFromJARClassLoader {
/**
* Load the DLL from the classpath rather than from the java path. This code
* uses this class's class loader to find the dell in one of the jar files
* in this class's class path. It then writes the file as a temp file and
* calls Load() on the temp file. The temporary file is marked to be deleted
* on exit so the dll is deleted from the system when the application exits.
* <p>
* Derived from ample code found in Sun's java forums <p.
*
* @return true if the native library has loaded, false if there was a
* problem.
*/
public boolean loadLibrary() {
try {
// this assumes that the dll is in the root dir of the signed
// jws jar file for this application.
//
// Starting in 1.14M6, the dll is named by platform and architecture
// so the best thing to do is to ask the LibraryLoader what name we
// expect.
// this code might be different if you customize the name of
// the jacob dll to match some custom naming convention
InputStream inputStream = getClass().getResource(
"/" + LibraryLoader.getPreferredDLLName() + ".dll")
.openStream();
// Put the DLL somewhere we can find it with a name Jacob expects
File temporaryDll = File.createTempFile(LibraryLoader
.getPreferredDLLName(), ".dll");
FileOutputStream outputStream = new FileOutputStream(temporaryDll);
byte[] array = new byte[8192];
for (int i = inputStream.read(array); i != -1; i = inputStream
.read(array)) {
outputStream.write(array, 0, i);
}
outputStream.close();
temporaryDll.deleteOnExit();
// Ask LibraryLoader to load the dll for us based on the path we
// set
System.setProperty(LibraryLoader.JACOB_DLL_PATH, temporaryDll
.getPath());
LibraryLoader.loadJacobLibrary();
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
}

View File

@@ -1,75 +0,0 @@
package com.jacob.samples.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.jacob.com.*;
import com.jacob.activeX.*;
public class JacobScript extends javax.servlet.http.HttpServlet
{
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException
{
PrintWriter out = null;
try
{
res.setContentType("text/html");
out = res.getWriter();
// display a form
out.println("<h1>Enter a VBScript Expression</h1>");
out.println("<form method=\"POST\" action=\"/JacobScript\">");
out.println("<input name=\"expr\" type=\"text\" width=64>");
out.println("<input type=\"submit\">");
out.println("</form>");
} catch (Exception e) {
e.printStackTrace();
out.println("<H2>Error:"+e+"</H2>");
}
}
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException
{
PrintWriter out = null;
try
{
res.setContentType("text/html");
out = res.getWriter();
// get what they typed in
String expr = (String)req.getParameter("expr");
// make sure we have a session
HttpSession session = req.getSession(true);
Dispatch sControl = null;
if (session.isNew())
{
// initialize the control and store it on the session
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
sControl = sC.getObject();
Dispatch.put(sControl, "Language", lang);
session.putValue("control", sControl);
}
else
{
sControl = (Dispatch)session.getValue("control");
}
Variant result = Dispatch.call(sControl, "Eval", expr);
// display a form
out.println("<h1>Enter a VBScript Expression</h1>");
out.println("<form method=\"POST\" action=\"/JacobScript\">");
out.println("<input name=\"expr\" type=\"text\" value=\""+expr+"\" width=64>");
out.println("<input type=\"submit\">");
out.println("</form>");
out.println("<H1>Jacob Response:</H1>");
out.println("<H2>"+result+"</H2>");
} catch (Exception e) {
e.printStackTrace();
out.println("<H2>Error:"+e+"</H2>");
}
}
}

View File

@@ -1,45 +0,0 @@
This sample runs in Weblogic 5.1 as a servlet.
0. Rename JacobScript.java_nocompile to JacobScript.java
1. Compile this file (make sure you have jdk1.2 installed or the
javax.servlet.* classes in your classpath).
2. Make sure the weblogic policy file allows native access. The easiest
way is to replace the contents with this:
grant codeBase "file:d:/weblogic/-" {
permission java.security.AllPermission;
};
grant codeBase "file:/c:/classes/-" {
permission java.security.AllPermission;
};
grant codeBase "file:${java.home}/lib/ext/-" {
permission java.security.AllPermission;
};
grant {
permission java.security.AllPermission;
};
3. Add the servlet to the weblogic.properties file:
weblogic.httpd.register.JacobScript=JacobScript
4. Either add your CLASSPATH to weblogic.classpath in startWebLogic.cmd
or copy the com directory into weblogic/myserver/servletclasses
5. Copy the jacob/samples/servlet/* into weblogic/myserver/servletclasses
6. Start weblogic
7. Type the url: http://localhost:7001/JacobScript into the browser
(If you run on port 7001)
8. Enter a VBScript expression like:
1+2
Now
"hello" & " world"
etc.
and watch the MS Script control (which you must have installed)
evaluate and return the result.