mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged DEV/3.1_ENTERPRISE_ONLY to HEAD
12465: Supporting changes for enterprise-only monitoring code. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12495 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.alfresco.util;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ public class ApplicationContextHelper
|
||||
*
|
||||
* @return Returns a new application context
|
||||
*/
|
||||
public synchronized static ApplicationContext getApplicationContext()
|
||||
public synchronized static ConfigurableApplicationContext getApplicationContext()
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
|
62
source/java/org/alfresco/util/OpenOfficeConnectionEvent.java
Normal file
62
source/java/org/alfresco/util/OpenOfficeConnectionEvent.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* A class of event that notifies the listener of the status of the Open Office Connection. Useful for Monitoring
|
||||
* purposes.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class OpenOfficeConnectionEvent extends ApplicationEvent
|
||||
{
|
||||
private static final long serialVersionUID = 8834274840220309384L;
|
||||
|
||||
/**
|
||||
* The Constructor.
|
||||
*
|
||||
* @param metaData
|
||||
* the meta data map
|
||||
*/
|
||||
public OpenOfficeConnectionEvent(Map<String, Object> metaData)
|
||||
{
|
||||
super(metaData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the meta data map.
|
||||
*
|
||||
* @return the meta data map
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getMetaData()
|
||||
{
|
||||
return (Map<String, Object>) getSource();
|
||||
}
|
||||
}
|
@@ -24,8 +24,12 @@
|
||||
*/
|
||||
package org.alfresco.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.ConnectException;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.sf.jooreports.openoffice.connection.AbstractOpenOfficeConnection;
|
||||
import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -37,8 +41,14 @@ import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import com.sun.star.registry.RegistryValueType;
|
||||
import com.sun.star.registry.XRegistryKey;
|
||||
import com.sun.star.registry.XSimpleRegistry;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
/**
|
||||
* A bootstrap 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.
|
||||
@@ -47,6 +57,7 @@ import org.springframework.context.ApplicationEvent;
|
||||
*/
|
||||
public class OpenOfficeConnectionTester extends AbstractLifecycleBean
|
||||
{
|
||||
private static final String ATTRIBUTE_AVAILABLE = "available";
|
||||
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 final String ERR_CONNECTION_LOST = "system.openoffice.err.connection_lost";
|
||||
@@ -55,6 +66,7 @@ public class OpenOfficeConnectionTester extends AbstractLifecycleBean
|
||||
private static Log logger = LogFactory.getLog(OpenOfficeConnectionTester.class);
|
||||
|
||||
private OpenOfficeConnection connection;
|
||||
private Map<String, Object> openOfficeMetadata = new TreeMap<String, Object>();
|
||||
private boolean strict;
|
||||
|
||||
public OpenOfficeConnectionTester()
|
||||
@@ -87,6 +99,7 @@ public class OpenOfficeConnectionTester extends AbstractLifecycleBean
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
checkConnection();
|
||||
((ApplicationContext) event.getSource()).publishEvent(new OpenOfficeConnectionEvent(this.openOfficeMetadata));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +122,7 @@ public class OpenOfficeConnectionTester extends AbstractLifecycleBean
|
||||
* then a disconnected {@link #setConnection(OpenOfficeConnection) connection} will result in a
|
||||
* runtime exception being generated.
|
||||
*/
|
||||
private synchronized void checkConnection()
|
||||
private void checkConnection()
|
||||
{
|
||||
String connectedMessage = I18NUtil.getMessage(INFO_CONNECTION_VERIFIED);
|
||||
boolean connected = testAndConnect();
|
||||
@@ -134,24 +147,66 @@ public class OpenOfficeConnectionTester extends AbstractLifecycleBean
|
||||
|
||||
public boolean testAndConnect()
|
||||
{
|
||||
PropertyCheck.mandatory(this, "connection", connection);
|
||||
if (connection.isConnected())
|
||||
synchronized (this.openOfficeMetadata)
|
||||
{
|
||||
// the connection is fine
|
||||
return true;
|
||||
}
|
||||
// attempt to make the connection
|
||||
try
|
||||
{
|
||||
connection.connect();
|
||||
// that worked
|
||||
return true;
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
// No luck
|
||||
return false;
|
||||
PropertyCheck.mandatory(this, "connection", connection);
|
||||
if (!connection.isConnected())
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.connect();
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
// No luck
|
||||
this.openOfficeMetadata.clear();
|
||||
this.openOfficeMetadata.put(ATTRIBUTE_AVAILABLE, Boolean.FALSE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Let's try to get at the version metadata
|
||||
Boolean lastAvailability = (Boolean)this.openOfficeMetadata.get(ATTRIBUTE_AVAILABLE);
|
||||
if (lastAvailability == null || !lastAvailability.booleanValue())
|
||||
{
|
||||
this.openOfficeMetadata.put(ATTRIBUTE_AVAILABLE, Boolean.TRUE);
|
||||
try
|
||||
{
|
||||
// We have to peak inside the connection class to get the service we want!
|
||||
Method getServiceMethod = AbstractOpenOfficeConnection.class.getDeclaredMethod("getService",
|
||||
String.class);
|
||||
getServiceMethod.setAccessible(true);
|
||||
Object configurationRegistry = getServiceMethod.invoke(connection,
|
||||
"com.sun.star.configuration.ConfigurationRegistry");
|
||||
XSimpleRegistry registry = (XSimpleRegistry) UnoRuntime.queryInterface(
|
||||
com.sun.star.registry.XSimpleRegistry.class, configurationRegistry);
|
||||
registry.open("org.openoffice.Setup", true, false);
|
||||
XRegistryKey root = registry.getRootKey();
|
||||
XRegistryKey product = root.openKey("Product");
|
||||
for (XRegistryKey key : product.openKeys())
|
||||
{
|
||||
switch (key.getValueType().getValue())
|
||||
{
|
||||
case RegistryValueType.LONG_value:
|
||||
openOfficeMetadata.put(key.getKeyName(), key.getLongValue());
|
||||
break;
|
||||
case RegistryValueType.ASCII_value:
|
||||
openOfficeMetadata.put(key.getKeyName(), key.getAsciiValue());
|
||||
break;
|
||||
case RegistryValueType.STRING_value:
|
||||
openOfficeMetadata.put(key.getKeyName(), key.getStringValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
registry.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.warn("Error trying to query Open Office version information", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
92
source/java/org/alfresco/util/ResourceFinder.java
Normal file
92
source/java/org/alfresco/util/ResourceFinder.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
/**
|
||||
* Can be used in Spring configuration to search for all resources matching an array of patterns.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class ResourceFinder extends PathMatchingResourcePatternResolver
|
||||
{
|
||||
/**
|
||||
* Instantiates a new resource finder.
|
||||
*/
|
||||
public ResourceFinder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The Constructor.
|
||||
*
|
||||
* @param classLoader
|
||||
* the class loader
|
||||
*/
|
||||
public ResourceFinder(ClassLoader classLoader)
|
||||
{
|
||||
super(classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Constructor.
|
||||
*
|
||||
* @param resourceLoader
|
||||
* the resource loader
|
||||
*/
|
||||
public ResourceFinder(ResourceLoader resourceLoader)
|
||||
{
|
||||
super(resourceLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of resources matching the given location patterns.
|
||||
*
|
||||
* @param locationPatterns
|
||||
* the location patterns
|
||||
* @return the matching resources, ordered by locationPattern index and location in the classpath
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public Resource[] getResources(String[] locationPatterns) throws IOException
|
||||
{
|
||||
List<Resource> resources = new LinkedList<Resource>();
|
||||
for (String locationPattern : locationPatterns)
|
||||
{
|
||||
resources.addAll(Arrays.asList(getResources(locationPattern)));
|
||||
}
|
||||
Resource[] resourceArray = new Resource[resources.size()];
|
||||
resources.toArray(resourceArray);
|
||||
return resourceArray;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user