diff options
Diffstat (limited to 'qadevOOo/runner/basicrunner/basichelper')
7 files changed, 1518 insertions, 0 deletions
diff --git a/qadevOOo/runner/basicrunner/basichelper/AttributeList.java b/qadevOOo/runner/basicrunner/basichelper/AttributeList.java new file mode 100644 index 000000000000..cdcba0f6f956 --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/AttributeList.java @@ -0,0 +1,138 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package basicrunner.basichelper; + +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.uno.Type; +import com.sun.star.lang.XTypeProvider; +import util.XMLTools; + +/** +* The class provides an implementation of the service +* <code>com.sun.star.xml.sax.XAttributeList</code>. +* @see com.sun.star.xml.sax.XAttributeList +* @see com.sun.star.lang.XServiceInfo +* @see com.sun.star.lang.XSingleServiceFactory +*/ +public class AttributeList implements XServiceInfo, XSingleServiceFactory { + /** The service name of this class **/ + static final String __serviceName = "basichelper.AttributeList"; + + /** + * Returns True, of the service is supported. + * @param name The service name. + * @return True, if the service is supported. + */ + public boolean supportsService(String name) { + return __serviceName.equals(name); + } + + /** + * Get all supported services. + * @return The supported services. + */ + public String[] getSupportedServiceNames() { + return new String[] {__serviceName}; + } + + /** + * Ask for the implementation name. + * @return The implementation name. + */ + public String getImplementationName() { + return getClass().getName(); + } + + /** + * Create an instance of the actual implementation of the AttributeList. + * Arguments are not supported, so they will bge ignored. + * @param args The arguments. + * @return A new instance of this class. + */ + public Object createInstanceWithArguments(Object[] args) { + return new AttributeListImpl(); + } + + /** + * Create an instance of this class. + * @return A new instance of this class. + */ + public Object createInstance() { + return createInstanceWithArguments(null); + } +} + +/** + * The actual implementation of the service + * <code>com.sun.star.xml.sax.XAttributeList</code>. + * Extends the class util.XMLTools.AttributeList. + * @see util.XMLTools.AttributeList + * @see com.sun.star.xml.sax.XAttributeList + * @see com.sun.star.lang.XTypeProvider + * @see com.sun.star.lang.XInitialization + */ +class AttributeListImpl extends XMLTools.AttributeList + implements XTypeProvider, XInitialization { + + /** + * Initialize this class. + * @param p0 An array of XML attributes that are added to the list. + * @throws Exception Initialize failed. + */ + public void initialize(Object[] p0) throws com.sun.star.uno.Exception { + for(int i = 0; i + 2 < p0.length; i += 3) { + add((String)p0[i], (String)p0[i + 1], (String)p0[i + 2]); + } + } + + /** + * Return all implemented types of this class. + * @return All UNO types of this class. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + Class superInterfaces[] = getClass().getSuperclass().getInterfaces(); + + Type types[] = new Type[interfaces.length + superInterfaces.length]; + int i = 0; + for(; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + for(; i < interfaces.length + superInterfaces.length; ++ i) + types[i] = new Type(superInterfaces[i - interfaces.length]); + return types; + } + + /** + * Get a unique id for this class + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } +} diff --git a/qadevOOo/runner/basicrunner/basichelper/Connector.java b/qadevOOo/runner/basicrunner/basichelper/Connector.java new file mode 100644 index 000000000000..cc219ac9f416 --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/Connector.java @@ -0,0 +1,272 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package basicrunner.basichelper; + +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import com.sun.star.connection.XConnector; +import com.sun.star.connection.XConnection; +import com.sun.star.connection.ConnectionSetupException; +import com.sun.star.connection.NoConnectException; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XSingleServiceFactory; + +/** + * This is a special service that is used in testing Acceptor + * component in BASIC. This componennt creates a separate thread + * that tries to connect to BASIC's acceptor. After successfull + * connection it writes a connectionString to XConnection. + */ + public class Connector implements XServiceInfo, XSingleServiceFactory { + /** The service name of this class **/ + static final String __serviceName = "basichelper.Connector"; + /** The Connector implementation **/ + static ConnectorImpl oConnector = null; + + /** Create a connector. + */ + public Connector() { + oConnector = new ConnectorImpl(); + } + + /** + * Returns an instance of the connector. + * Arguments are not supported here and will be ignored. + * @param args The arguments. + * @return The connector. + */ + public Object createInstanceWithArguments(Object[] args) { + return oConnector; + } + + /** + * Returns an instance of the connector. + * @return The connector. + */ + public Object createInstance() { + return createInstanceWithArguments(null); + } + + /** + * Get a unique id for this implementation. + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** + * Return all implemented types of this class. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + + return types; + } + + /** Is this servioce supported? + * @param name The service name. + * @return True, if the service is supported. + */ + public boolean supportsService(String name) { + return __serviceName.equals(name); + } + + /** + * Get all supported service names. + * @return All supported servcices. + */ + public String[] getSupportedServiceNames() { + return new String[] {__serviceName}; + } + + /** + * Get the implementation name of this class. + * @return The implementation name. + */ + public String getImplementationName() { + return getClass().getName(); + } +} + +/** + * The actual implementation of the connector + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.lang.XTypeProvider + * @see com.sun.star.container.XNameAccess + */ +class ConnectorImpl implements XInitialization, XTypeProvider, XNameAccess { + static String aState; + static Integer iTimeout; + + /** + * Construct a new connector. + */ + public ConnectorImpl() { + aState = "just created"; + iTimeout = new Integer(3000); + } + + /** + * Method initialize() creates a new thread that will try to connect to + * Acceptor for a few seconds. One should pass as parameters an array, + * where element 0 is an instance of Connector and element 1 is a + * connection string (the same as in Acceptor) + * @param parm1 An instance of XConnector. + * @see com.sun.star.connection.XConnector + * @throws Exception Is thrown, when initialize fails. + */ + public void initialize(Object[] parm1) throws com.sun.star.uno.Exception { + aState = "just initialized"; + XConnector cntr = (XConnector)UnoRuntime.queryInterface( + XConnector.class, parm1[0]); + ConnThread aThread = new ConnThread(cntr, (String)parm1[1]); + aThread.start(); + } + + /** + * Get the element names + * @return All element names. + */ + public String[] getElementNames() { + return new String[]{"State", "Timeout"}; + } + + /** + * Does this element exist? + * @param name The element name. + * @return True, if the name exists. + */ + public boolean hasByName(String name) { + return (name.equals("State") || name.equals("Timeout")); + } + + /** + * Get an element by its name. + * @param name The name of the element. + * @return The value of the element. + * @throws NoSuchElementException The element does not exist. + */ + public Object getByName(String name) throws NoSuchElementException{ + if (name.equals("State")) + return aState; + else if (name.equals("Timeout")) + return iTimeout; + else + throw new NoSuchElementException(); + } + + /** + * Are there elements + * @return Always true. + */ + public boolean hasElements() { + return true; + } + + /** + * Get element type. + * @return null. + */ + public Type getElementType() { + return null; + } + + /** + * Get a unique id for this implementation. + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** + * Return all implemented types of this class. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + + return types; + } +} + +/** + * A connector thread + */ +class ConnThread extends Thread { + String connStr; + XConnector oConnector; + + /**Construct the thread. + * @param oCntr A connector. + * @param cStr The conection string. + */ + public ConnThread(XConnector oCntr, String cStr){ + connStr = cStr; + oConnector = oCntr; + } + + /** + * Run the thread. + */ + public void run(){ + try { + Thread.sleep(ConnectorImpl.iTimeout.intValue()); + ConnectorImpl.aState = "before connection"; + XConnection oConnection = oConnector.connect(connStr); + if (oConnection != null) { + ConnectorImpl.aState = "connected"; + oConnection.write(connStr.getBytes()); + oConnection.write(new byte[]{0}); + } else + ConnectorImpl.aState = "XConnection is null"; + } catch (ConnectionSetupException e) { + ConnectorImpl.aState = "ConnectionSetupException"; + throw new RuntimeException(e.toString()); + } catch (NoConnectException e) { + ConnectorImpl.aState = "NoConnectException"; + throw new RuntimeException(e.toString()); + } catch (Exception e) { + ConnectorImpl.aState = "error"; + throw new RuntimeException("Can't sleep exception"); + } + } +} diff --git a/qadevOOo/runner/basicrunner/basichelper/DispatchProviderInterceptor.java b/qadevOOo/runner/basicrunner/basichelper/DispatchProviderInterceptor.java new file mode 100644 index 000000000000..f50a7d2eb470 --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/DispatchProviderInterceptor.java @@ -0,0 +1,194 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package basicrunner.basichelper; + +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import com.sun.star.frame.XDispatchProviderInterceptor; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.DispatchDescriptor; +import com.sun.star.util.URL; + +/** + * This implementation provides an implementation of an interceptor. + * @see com.sun.star.lang.XSingleServiceFactory + * @see com.sun.star.lang.XServiceInfo + */ +public class DispatchProviderInterceptor implements XServiceInfo, + XSingleServiceFactory { + /** The service name **/ + static final String __serviceName = + "basichelper.DispatchProviderInterceptor"; + + /** Create an instance of the interceptor + * Arguments are not supported here, so they will be ignored. + * @param args The arguments. + * @return A new instance of the interceptor. + **/ + public Object createInstanceWithArguments(Object[] args) { + return new InterceptorImpl(); + } + + /** Create an instance of the interceptor + * @return A new instance of the interceptor. + **/ + public Object createInstance() { + return createInstanceWithArguments(null); + } + + /** Get the unique id for this implementation + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** Get all implemented types. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + + return types; + } + + /** + * Is this service supported? + * @param name The name of a service. + * @return True, if the service is supported. + */ + public boolean supportsService(String name) { + return __serviceName.equals(name); + } + + /** + * Get all supported service names. + * @return All service names. + */ + public String[] getSupportedServiceNames() { + return new String[] {__serviceName}; + } + + /** + * Get the implementation name of this class. + * @return The name. + */ + public String getImplementationName() { + return getClass().getName(); + } +} + +/** + * The actual implementation of the interceptor. + * @see com.sun.star.lang.XTypeProvider + * @see com.sun.star.frame.XDispatchProviderInterceptor + * @see com.sun.star.frame.XDispatchProvider + */ +class InterceptorImpl implements XDispatchProvider, + XDispatchProviderInterceptor, XTypeProvider { + + /** A master dispatch provider **/ + public XDispatchProvider master = null; + /** A slave dispatch provider **/ + public XDispatchProvider slave = null; + + /** Get the slave dispatch provider + * @return The slave. + */ + public XDispatchProvider getSlaveDispatchProvider() { + return slave; + } + /** Get the master dispatch provider + * @return The master. + */ + public XDispatchProvider getMasterDispatchProvider() { + return master; + } + + /** Set the slave dispatch provider + * @param prov The new slave. + */ + public void setSlaveDispatchProvider(XDispatchProvider prov) { + slave = prov ; + } + + /** Set the master dispatch provider + * @param prov The new master. + */ + public void setMasterDispatchProvider(XDispatchProvider prov) { + master = prov ; + } + + /** Searches for an <type>XDispatch</type> for the specified URL within + * the specified target frame. + * @param url The URL. + * @param frame The target frame + * @param flags Optional search flags. + * @return The dispatch object which provides the queried functionality + * or null if no dispatch object is available. + * @see com.sun.star.frame.XDispatch + */ + public XDispatch queryDispatch(URL url, String frame, int flags) { + return master.queryDispatch(url, frame, flags) ; + } + + /** + * Query for an array of <type>XDispatch</type>. + * @param desc A list of dipatch requests. + * @return A list of dispatch objects. + */ + public XDispatch[] queryDispatches(DispatchDescriptor[] desc) { + return master.queryDispatches(desc) ; + } + + /** Get the unique id for this implementation + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** Get all implemented types. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + + return types; + } +} diff --git a/qadevOOo/runner/basicrunner/basichelper/DocumentHandler.java b/qadevOOo/runner/basicrunner/basichelper/DocumentHandler.java new file mode 100644 index 000000000000..62909f16dd4f --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/DocumentHandler.java @@ -0,0 +1,344 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package basicrunner.basichelper; + +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import com.sun.star.xml.sax.XDocumentHandler; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.NoSuchElementException; +import java.util.Vector; +import util.XMLTools.Tag; +import util.XMLTools; +import java.io.StringWriter; +import java.io.PrintWriter; + +/** + * This class provides a handler of the BASIC test document. + * @see com.sun.star.lang.XSingleServiceFactory + * @see com.sun.star.lang.XServiceInfo + */ +public class DocumentHandler implements XServiceInfo, XSingleServiceFactory { + /** The service name of this class **/ + static final String __serviceName = "basichelper.DocumentHandler"; + /** The actual handler of the document **/ + static DocumentHandlerImpl oDocumentHandler = null; + /** A string writer **/ + private StringWriter writer; + /** The log writer (just a wrapper around <code>writer</code>) **/ + private PrintWriter log; + + /** + * Create an instance of the document handler. + * @param args A boolean value as <codde>args[0]</code> determines, + * if checked XML data is printed to the log. + * Default is false. + * @return The document handler + */ + public Object createInstanceWithArguments(Object[] args) { + boolean printXML = false; + if (args != null && args.length!=0 && args[0] instanceof Boolean) + printXML = ((Boolean)args[0]).booleanValue(); + writer = new StringWriter(); + log = new PrintWriter(writer); + oDocumentHandler = new DocumentHandlerImpl(log, printXML, writer); + return oDocumentHandler; + } + + /** + * Create an instance of the document handler. + * @return The document handler + */ + public Object createInstance() { + return createInstanceWithArguments(null); + } + + /** Get the unique id for this implementation + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** Get all implemented types. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + return types; + } + + /** Is this servioce supported? + * @param name The service name. + * @return True, if the service is supported. + */ + public boolean supportsService(String name) { + return __serviceName.equals(name); + } + + /** + * Get all supported service names. + * @return All supported servcices. + */ + public String[] getSupportedServiceNames() { + return new String[] {__serviceName}; + } + + /** + * Get the implementation name of this class. + * @return The implementation name. + */ + public String getImplementationName() { + return getClass().getName(); + } +} + +/** + * The actual implementation of the document handler + * @see util.XMLTools.XMLChecker + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.xml.sax.XDocumentHandler + * @see com.sun.star.container.XNameAccess + * @see com.sun.star.lang.XTypeProvider + */ +class DocumentHandlerImpl extends XMLTools.XMLChecker + implements XInitialization, XDocumentHandler, + XNameAccess, XTypeProvider { + /** A string writer **/ + private StringWriter writer; + + /** + * Constructor + * @param log_ A log writer. + * @param printXML Should XML data be printed to the log? + * @param logWriter A wrapper around <code>log_</code> for convenience. + */ + public DocumentHandlerImpl(PrintWriter log_, + boolean printXML, StringWriter logWriter) { + super(log_, printXML); + writer = logWriter; + } + + /** + * Initialize this class with rules. + * @param parm1 An array of filter rules: + * <code>processAction()</code> is called for every rule. + * @throws com.sun.star.uno.Exception for an incorrect rule. + */ + public void initialize(Object[] parm1) throws com.sun.star.uno.Exception { + if (!(parm1[0] instanceof Object[])) return; + for (int i=0; i<parm1.length; i++) { + processActionForXMLChecker((Object[])parm1[i]); + } + } + + /** + * Method processes all filters received from basic tests. + * Called by initialize(). + * @param filterRule An array building one filter rule. + * @throws com.sun.star.uno.Exception for an incorrect rule. + */ + private void processActionForXMLChecker(Object[] filterRule) + throws com.sun.star.uno.Exception { + int arrLen = filterRule.length; + String oTagName; + Object[] oTags; + Object[] oTag; + int tagsNum = arrLen-1; + Vector allTags = new Vector(); + String CDATA = ""; + String action = ""; + + // First element of rule is RuleName and should be String + if (!(filterRule[0] instanceof String)) { + throw new com.sun.star.uno.Exception("Error: incorrect filter rule "+ + "received from basic test! Rule name must be a String."); + } else { + action = (String) filterRule[0]; + } + + // Searching for character data and defining amount of tags received. + for (int j=1; j<arrLen; j++) { + if ( (filterRule[j] instanceof String) && (j != 1) ) { + CDATA = (String) filterRule[j]; + tagsNum--; + } + } + + // Adding received tags to internal array. + oTags = new Object[tagsNum]; + for (int j=1; j<=tagsNum; j++) { + if (filterRule[j] instanceof Object[]) { + oTags[j-1] = (Object[]) filterRule[j]; + } + } + + // Process all received tags for a given filter rule + for (int i=0; i<oTags.length; i++) { + if (oTags[i] instanceof Object[]) { + oTag = (Object[]) oTags[i]; + oTagName = (String) oTag[0]; + } else if (oTags[i] instanceof Object) { + oTag = new Object[1]; + oTag[0] = (Object) oTags[i]; + oTagName = (String) oTag[0]; + } else { + throw new com.sun.star.uno.Exception("Error: invalid tag "+ + "received from basic test! Check tag " + +i+" in rule '"+action+"'."); + } + + // Action for constructor Tag(TagName, attrName, attrValue) + if (oTag.length == 3) { + if ((oTag[1] instanceof String)&&(oTag[2] instanceof String)) { + allTags.add(new Tag(oTagName, + (String) oTag[1], (String) oTag[2])); + } else { + throw new com.sun.star.uno.Exception("Error: invalid tag '"+ + oTagName+"' received from basic test!"); + } + + // Action for constructors: + // Tag(TagName, String[][] attrValues ) + // Tag(TagName, String[] attrNames) + // Tag(TagName, String attrName) + // + } else if (oTag.length == 2) { + if (oTag[1] instanceof String[][]) { + allTags.add(new Tag(oTagName, (String[][]) oTag[1])); + } else if (oTag[1] instanceof String[]) { + allTags.add(new Tag(oTagName, (String[]) oTag[1])); + } else if (oTag[1] instanceof String) { + allTags.add(new Tag(oTagName, (String) oTag[1])); + } else { + throw new com.sun.star.uno.Exception("Error: invalid tag '"+ + oTagName+"' received from basic test!"); + } + + // Action for constructor Tag(TagName) + } else if (oTag.length == 1) { + if (oTag[0] instanceof String) { + allTags.add(new Tag(oTagName)); + } else { + throw new com.sun.star.uno.Exception("Error: invalid tag '"+ + oTagName+"' received from basic test!"); + } + } else { + throw new com.sun.star.uno.Exception("Error: invalid tag '"+ + oTagName+"' received from basic test!"); + } + } + + // Adding tags to XMLChecker + if ( action.equals((String)"TagExists") ) { + for (int i=0; i<allTags.size(); i++) { + addTag((Tag)allTags.get(i)); + } + } else if (action.equals((String)"TagEnclosed")) { + addTagEnclosed((Tag) allTags.get(0), (Tag) allTags.get(1)); + } else if (action.equals((String)"CharsEnclosed")) { + addCharactersEnclosed(CDATA, (Tag) allTags.get(0)); + } else { + throw new com.sun.star.uno.Exception("Error: incorrect rule name '"+ + action+"' received from basic test!"); + } + } + + /** + * Get the names of the elements. + * @return element names. + */ + public String[] getElementNames() { + return new String[]{"XMLCode", "XMLIsCorrect"}; + } + + /** + * Is this an element? + * @param name Element name. + * @return true, if <code>name>/code> is the name of an element. + */ + public boolean hasByName(String name) { + return (name.equals("XMLCode") || name.equals("XMLIsCorrect")); + } + + /** + * Get an element by its name. + * @param name The element name. + * @return The element with the specified <code>name</code>. + * @throws NoSuchElementException Is thrown, if name does not exist. + */ + public Object getByName(String name) throws NoSuchElementException{ + if (name.equals("XMLIsCorrect")) + return new Boolean(this.check()); + else if (name.equals("XMLCode")) { + return writer.getBuffer().toString(); + } else + throw new NoSuchElementException(); + } + + /** + * Are there any elements? + * @return Always true. + */ + public boolean hasElements() { + return true; + } + + /** + * Get the element type. + * @return The type. + */ + public Type getElementType() { + return new Type(Object.class); + } + + /** + * Get a unique id for this implementation. + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** + * Return all implemented types of this class. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + return types; + } +} diff --git a/qadevOOo/runner/basicrunner/basichelper/Filter.java b/qadevOOo/runner/basicrunner/basichelper/Filter.java new file mode 100644 index 000000000000..d9616d30e5b2 --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/Filter.java @@ -0,0 +1,269 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package basicrunner.basichelper; + +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.document.XFilter; +import com.sun.star.beans.PropertyValue; + + +/** + * Provides an implementation of XFilter. + * @see com.sun.star.document.XFilter + * @see com.sun.star.lang.XServiceInfo + * @see com.sun.star.lang.XSingleServiceFactory + */ +public class Filter implements XServiceInfo, XSingleServiceFactory { + /** The service name of this class **/ + static final String __serviceName = "basichelper.Filter"; + /** The actual filter **/ + static FilterImpl oFilter = null; + + /** + * Construct a new filter + */ + public Filter() { + oFilter = new FilterImpl(); + } + + /** + * Returns an instance of the filter. + * Arguments are not supported here and will be ignored. + * @param args The arguments. + * @return The filter. + */ + public Object createInstanceWithArguments(Object[] args) { + return oFilter; + } + + /** + * Returns an instance of the filter. + * @return The filter. + */ + public Object createInstance() { + return createInstanceWithArguments(null); + } + + /** + * Get a unique id for this implementation. + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** + * Return all implemented types of this class. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + + return types; + } + + /** Is this servioce supported? + * @param name The service name. + * @return True, if the service is supported. + */ + public boolean supportsService(String name) { + return __serviceName.equals(name); + } + + /** + * Get all supported service names. + * @return All supported servcices. + */ + public String[] getSupportedServiceNames() { + return new String[] {__serviceName}; + } + + /** + * Get the implementation name of this class. + * @return The implementation name. + */ + public String getImplementationName() { + return getClass().getName(); + } +} + +/** + * The actual filter implementation + * @see com.sun.star.lang.XInitialization; + * @see com.sun.star.lang.XTypeProvider; + * @see com.sun.star.container.XNameAccess; + */ +class FilterImpl implements XInitialization, XTypeProvider, XNameAccess { + /** A state **/ + static String aState; + /** A result **/ + static boolean bResult; + + /** + * Constructs a new filter. + */ + public FilterImpl() { + aState = "just created"; + bResult = false; + } + + /** + * Get the element names + * @return All element names. + */ + public String[] getElementNames() { + return new String[]{"State", "Result"}; + } + + /** + * Does this element exist? + * @param name The element name. + * @return True, if the name exists. + */ + public boolean hasByName(String name) { + return (name.equals("State") || name.equals("Result")); + } + + /** + * Get an element by its name. + * @param name The name of the element. + * @return The value of the element. + * @throws NoSuchElementException The element does not exist. + */ + public Object getByName(String name) throws NoSuchElementException{ + if (name.equals("State")) + return aState; + else if (name.equals("Result")) + return new Boolean(bResult); + else + throw new NoSuchElementException(); + } + + /** + * Are there elements + * @return Always true. + */ + public boolean hasElements() { + return true; + } + + /** + * Get element type. + * @return null. + */ + public Type getElementType() { + return null; + } + + /** + * Get a unique id for this implementation. + * @return The id. + */ + public byte[] getImplementationId() { + return toString().getBytes(); + } + + /** + * Return all implemented types of this class. + * @return The implemented UNO types. + */ + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + + return types; + } + + + /** + * Method initialize() creates a new thread that will try to start + * filtering + * @param parm1 An instance of XFilter + * @see com.sun.star.document.XFilter + * @throws Exception Is thrown, when initialize fails. + */ + public void initialize(Object[] parm1) throws com.sun.star.uno.Exception { + XFilter oFilter = (XFilter)UnoRuntime.queryInterface( + XFilter.class, parm1[0]); +//? PropertyValue[] FilterDesc = (PropertyValue[])AnyConverter.toArray(parm1[1]); + PropertyValue[] FilterDesc = (PropertyValue[])UnoRuntime.queryInterface(PropertyValue[].class, parm1[1]); + aState = "just initialized"; + FilterThread aThread = new FilterThread(oFilter, FilterDesc); + aThread.start(); + } +} + +/** + * A thread for filtering. + */ +class FilterThread extends Thread { + /** The filter that is used **/ + XFilter oFilter = null; + /** Filter descriptions **/ + PropertyValue[] FilterDesc = null; + + /** + * Construct the thread. + * @param oObj The filter. + * @param Desc The descriptions. + */ + public FilterThread(XFilter oObj, PropertyValue[] Desc){ + oFilter = oObj; + FilterDesc = Desc; + } + + /** + * Let the thread run + */ + public void run(){ + boolean bOK; + try { + FilterImpl.aState = "before filtering"; + bOK = oFilter.filter(FilterDesc); + FilterImpl.aState = "filtering finished"; + FilterImpl.bResult = bOK; + } catch (Exception e) { + ConnectorImpl.aState = "error"; + throw new RuntimeException("Can't filtering exception" + + e.toString()); + } + } +} diff --git a/qadevOOo/runner/basicrunner/basichelper/ThreadRunner.java b/qadevOOo/runner/basicrunner/basichelper/ThreadRunner.java new file mode 100644 index 000000000000..ec8957e01a6f --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/ThreadRunner.java @@ -0,0 +1,254 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package basicrunner.basichelper; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XModel; +import com.sun.star.util.XURLTransformer; +import com.sun.star.frame.XController; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.URL; +import com.sun.star.lang.XMultiServiceFactory; +import util.utils; +import com.sun.star.lang.XComponent; +import lib.StatusException; +import lib.Status; +import util.SOfficeFactory; +import com.sun.star.ui.dialogs.XExecutableDialog; + + +public class ThreadRunner implements XServiceInfo, XSingleServiceFactory { + static final String __serviceName = "basichelper.ThreadRunner"; + static ThreadRunnerImpl oThreadRunner = null; + + public ThreadRunner(XMultiServiceFactory xMSF) { + oThreadRunner = new ThreadRunnerImpl(xMSF); + } + + public Object createInstanceWithArguments(Object[] args) { + return oThreadRunner; + } + + public Object createInstance() { + return createInstanceWithArguments(null); + } + + public byte[] getImplementationId() { + return toString().getBytes(); + } + + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + return types; + } + + public boolean supportsService(String name) { + return __serviceName.equals(name); + } + + public String[] getSupportedServiceNames() { + return new String[] {__serviceName}; + } + + public String getImplementationName() { + return getClass().getName(); + } +} + + +class ThreadRunnerImpl implements XInitialization, XTypeProvider { + Object oDoc = null; + String actionType = null; + String actionParm = null; + XMultiServiceFactory oMSF = null; + + public ThreadRunnerImpl(XMultiServiceFactory MSF) { + oMSF = MSF; + } + + public void initialize(Object[] params) throws com.sun.star.uno.Exception { + boolean parmsOK = false; + + if (!(params[0] instanceof String)) { + throw new StatusException(Status.failed( + "Wrong first parameter for ThreadRunner, allowed values:" + + "'OpenToolkitDialog', 'OpenDialogFromFile', 'ExecuteDialog'")); + } + + actionType = (String) params[0]; + + if (actionType.equals("OpenToolkitDialog")) { + if (params.length != 3 || !(params[2] instanceof Object) || + !(params[1] instanceof String) ) { + throw new StatusException(Status.failed("Expected the " + + "following type of parameters for 'OpenToolkitDialog': " + + "String, Object")); + } + actionParm = (String)params[1]; + oDoc = (Object)params[2]; + ToolkitDialogThread aThread = + new ToolkitDialogThread(oMSF, oDoc, actionParm); + aThread.start(); + } else if (actionType.equals("OpenDialogFromFile")) { + if (params.length != 2 || !(params[1] instanceof String) ) { + throw new StatusException(Status.failed("Expected the " + + "following type of parameters for 'OpenDialogFromFile': " + + "String")); + } + actionParm = (String)params[1]; + DialogFromFileThread bThread = + new DialogFromFileThread(oMSF, actionParm); + bThread.start(); + } else if ( actionType.equals("ExecuteDialog")) { + if (params.length != 2 || !(params[1] instanceof String)) { + throw new StatusException(Status.failed("Expected the " + + "following type of parameters for 'ExecuteDialog': " + + "String")); + } + ExecuteDialogThread cThread = + new ExecuteDialogThread(oMSF, (String)params[1]); + cThread.start(); + } else { + System.out.println("Error! ThreadRunnerImpl.initialize(): " + + "Incorrect parameters!"); + } + } + + public byte[] getImplementationId() { + return toString().getBytes(); + } + + public Type[] getTypes() { + Class interfaces[] = getClass().getInterfaces(); + Type types[] = new Type[interfaces.length]; + for(int i = 0; i < interfaces.length; ++ i) + types[i] = new Type(interfaces[i]); + return types; + } +} + + +class ToolkitDialogThread extends Thread { + Object oDoc = null; + String url = null; + XMultiServiceFactory msf = null; + + public ToolkitDialogThread(XMultiServiceFactory xMSF, Object doc, String sUrl) { + oDoc = doc; + url = sUrl; + msf = xMSF; + } + + public void run() { + XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, oDoc); + XController xController = aModel.getCurrentController(); + try { + XDispatchProvider xDispProv = (XDispatchProvider) + UnoRuntime.queryInterface( XDispatchProvider.class, xController ); + XURLTransformer xParser = (com.sun.star.util.XURLTransformer) + UnoRuntime.queryInterface(XURLTransformer.class, + msf.createInstance("com.sun.star.util.URLTransformer")); + URL[] aParseURL = new URL[1]; + aParseURL[0] = new URL(); + aParseURL[0].Complete = url; + xParser.parseStrict(aParseURL); + URL aURL = aParseURL[0]; + XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); + if( xDispatcher != null ) + xDispatcher.dispatch( aURL, null ); + } catch (com.sun.star.uno.Exception e) { + System.out.println("Couldn't open dialog!!!"); + throw new StatusException( "Couldn't open dialog!!!", e ); + } + } +} + + +class DialogFromFileThread extends Thread { + String url = null; + SOfficeFactory SOF = null; + XMultiServiceFactory myMSF = null; + + public DialogFromFileThread(XMultiServiceFactory xMSF, String sUrl) { + url = sUrl; + SOF = SOfficeFactory.getFactory(xMSF); + myMSF = xMSF; + } + + public void run() { + try { + PropertyValue[] args = new PropertyValue[1]; + args[0] = new PropertyValue(); + args[0].Name = "InteractionHandler"; + args[0].Value = myMSF.createInstance( + "com.sun.star.comp.uui.UUIInteractionHandler"); + + String testUrl= utils.getFullTestURL(url); + System.out.println("loading "+testUrl); + XComponent xDoc = SOF.loadDocument(testUrl, args); + } catch (com.sun.star.uno.Exception e) { + System.out.println("Couldn't create document!!!"); + throw new StatusException( "Couldn't create document!!!", e ); + } + } + +} + +class ExecuteDialogThread extends Thread { + XMultiServiceFactory xMSF = null; + String serviceName = null; + + public ExecuteDialogThread(XMultiServiceFactory xMSF, String serviceName) { + this.xMSF = xMSF; + this.serviceName = serviceName; + } + + public void run() { + Object dlg = null; + try { + dlg = xMSF.createInstance(serviceName); + } catch(com.sun.star.uno.Exception e) { + throw new StatusException(Status.failed("Couldn't create service")); + } + XExecutableDialog execDlg = (XExecutableDialog)UnoRuntime.queryInterface + (XExecutableDialog.class, dlg); + execDlg.execute(); + } +} + + diff --git a/qadevOOo/runner/basicrunner/basichelper/makefile.mk b/qadevOOo/runner/basicrunner/basichelper/makefile.mk new file mode 100644 index 000000000000..cc45b0014fb9 --- /dev/null +++ b/qadevOOo/runner/basicrunner/basichelper/makefile.mk @@ -0,0 +1,47 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME = OOoRunner +PACKAGE = basicrunner$/basichelper +TARGET = runner_basichelper + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +JARFILES = ridl.jar jurt.jar unoil.jar +JAVAFILES = AttributeList.java DocumentHandler.java Filter.java \ + Connector.java DispatchProviderInterceptor.java \ + ThreadRunner.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk |