/* * ScannerTest.java * * Created on 25.11.2006 - 17:18:03 * */ import com.sun.star.uno.XComponentContext; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.comp.helper.Bootstrap; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.frame.XDesktop; import com.sun.star.frame.XModel; import com.sun.star.frame.XFrame; import com.sun.star.frame.XController; import com.sun.star.frame.XComponentLoader; //PatronCard creator in BeanShell import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XIndexAccess; import com.sun.star.container.XNamed; import com.sun.star.drawing.XDrawPagesSupplier; import com.sun.star.drawing.XDrawPages; import com.sun.star.drawing.XDrawPage; import com.sun.star.drawing.XShape; import com.sun.star.drawing.XShapes; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XEventListener; import com.sun.star.scanner.XScannerManager; import com.sun.star.scanner.ScannerContext; import com.sun.star.text.XText; import com.sun.star.text.XTextCursor; import com.sun.star.uno.AnyConverter; import com.sun.star.view.XPrintable; /** * * @author jmarton */ public class ScannerTest { /** Creates a new instance of ScannerTest */ public ScannerTest() { } public static int condition=0; /** * @param args the command line arguments */ public static void main(String[] args) { try { System.err.println("starting up"); // get the remote office component context XComponentContext xContext = Bootstrap.bootstrap(); System.err.println("running"); // get the remote office service manager XMultiComponentFactory xServiceManager = xContext.getServiceManager(); // get an instance of the remote office desktop UNO service Object desktop = xServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xContext ); assert desktop != null : "null desktop received"; XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface( XDesktop.class, desktop); XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime. queryInterface(XComponentLoader.class, xDesktop); System.err.println("loading a document"); PropertyValue notHidden = new PropertyValue(); notHidden.Name="Hidden"; notHidden.Value=new Boolean(false); PropertyValue[] myProps = new PropertyValue[1]; myProps[0]=notHidden; XComponent doc = xComponentLoader.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, myProps); assert doc!= null: "null after opening"; System.err.println("opened"); Object oScannerM = xServiceManager.createInstanceWithContext( "com.sun.star.scanner.ScannerManager", xContext); XScannerManager xScannerManager = (XScannerManager)UnoRuntime. queryInterface(XScannerManager.class, oScannerM); assert xScannerManager != null : "could not get XScannerManager"; ScannerContext[] sc = xScannerManager.getAvailableScanners(); System.err.println("Available scanner count: "+sc.length); final java.lang.Object o = new Object(); if (xScannerManager.configureScanner(new ScannerContext[] {sc[0]})) { System.err.print("waiting 10 seconds before trying to start scanning..."); synchronized (o) { o.wait(10000) ; } System.err.println("10 secs elapsed. continuing"); xScannerManager.startScan(sc[0], new XEventListener() { public void disposing (com.sun.star.lang.EventObject e) { System.err.print("disposing..."); ScannerTest.condition=1; synchronized (o) { o.notify(); } ; System.err.println(" notified."); return; } }); synchronized (o) { while(ScannerTest.condition==0) { System.err.println("Waiting..."); o.wait(); } }; } else { System.err.println("configureScanner failed for some reasons."); } } catch (java.lang.Exception e){ e.printStackTrace(); } System.exit( 0 ); } }