mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merge 1.4 to HEAD
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4340 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4350 . svn resolved root\projects\3rd-party\.classpath svn resolved root\projects\repository\source\java\org\alfresco\repo\workflow\WorkflowInterpreter.java svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4379 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4380 . svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4420 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4421 . svn resolved root\projects\3rd-party\.classpath git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4655 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
106
source/java/org/alfresco/util/OpenOfficeConnectionTester.java
Normal file
106
source/java/org/alfresco/util/OpenOfficeConnectionTester.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.util;
|
||||
|
||||
import java.net.ConnectException;
|
||||
|
||||
import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Simple class that checks for the presence of a valid <b>OpenOffice</b>
|
||||
* connection, as provided by the
|
||||
* <code>net.sf.jooreports.openoffice.connection.OpenOfficeConnection</code> implementations.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class OpenOfficeConnectionTester
|
||||
{
|
||||
private static final String INFO_CONNECTION_VERIFIED = "system.openoffice.info.connection_verified";
|
||||
private static final String ERR_CONNECTION_FAILED = "system.openoffice.err.connection_failed";
|
||||
|
||||
private static Log logger = LogFactory.getLog(OpenOfficeConnectionTester.class);
|
||||
|
||||
private OpenOfficeConnection connection;
|
||||
private boolean strict;
|
||||
|
||||
public OpenOfficeConnectionTester()
|
||||
{
|
||||
this.strict = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param connection the <b>OpenOffice</b> connection.
|
||||
*/
|
||||
public void setConnection(OpenOfficeConnection connection)
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strict set to <tt>true</tt> to generate a failure if the connection is not connected
|
||||
* during the {@link #checkConnection() connection check}, or false to just issue
|
||||
* a warning. The default is <tt>false</tt>.
|
||||
*/
|
||||
public void setStrict(boolean strict)
|
||||
{
|
||||
this.strict = strict;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual connection check. If this component is {@link #setStrict(boolean) strict},
|
||||
* then a disconnected {@link #setConnection(OpenOfficeConnection) connection} will result in a
|
||||
* runtime exception being generated.
|
||||
*/
|
||||
public synchronized void checkConnection()
|
||||
{
|
||||
PropertyCheck.mandatory(this, "connection", connection);
|
||||
String connectedMessage = I18NUtil.getMessage(INFO_CONNECTION_VERIFIED);
|
||||
if (connection.isConnected())
|
||||
{
|
||||
// the connection is fine
|
||||
logger.info(connectedMessage);
|
||||
return;
|
||||
}
|
||||
// attempt to make the connection
|
||||
try
|
||||
{
|
||||
connection.connect();
|
||||
// that worked
|
||||
logger.info(connectedMessage);
|
||||
return;
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
// no luck
|
||||
}
|
||||
// now we have to either fail or report the connection
|
||||
String msg = I18NUtil.getMessage(ERR_CONNECTION_FAILED);
|
||||
if (strict)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn(msg);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user