Commit 3cd73ed8dc98f7d2f29508e935e137a97d02609e

Authored by Derek Hulley
1 parent 264b8f4eed
Exists in master

Transfer code from svn to gitlab.alfresco.com

Showing 220 changed files with 32707 additions and 0 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 220 files displayed.

... ... @@ -0,0 +1,233 @@
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  2 + <modelVersion>4.0.0</modelVersion>
  3 +
  4 + <parent>
  5 + <groupId>org.alfresco</groupId>
  6 + <artifactId>alfresco-super-pom</artifactId>
  7 + <version>6</version>
  8 + </parent>
  9 + <artifactId>alfresco-core</artifactId>
  10 + <version>6.5-SNAPSHOT</version>
  11 + <name>Alfresco Core</name>
  12 + <description>Alfresco core libraries and utils</description>
  13 +
  14 + <scm>
  15 + <connection>scm:svn:https://svn.alfresco.com/repos/alfresco-open-mirror/services/alfresco-core/trunk/</connection>
  16 + <developerConnection>scm:svn:https://svn.alfresco.com/repos/alfresco-enterprise/services/alfresco-core/trunk/</developerConnection>
  17 + </scm>
  18 +
  19 + <distributionManagement>
  20 + <repository>
  21 + <id>alfresco-internal</id>
  22 + <url>https://artifacts.alfresco.com/nexus/content/repositories/releases</url>
  23 + </repository>
  24 + <snapshotRepository>
  25 + <id>alfresco-internal-snapshots</id>
  26 + <url>https://artifacts.alfresco.com/nexus/content/repositories/snapshots</url>
  27 + </snapshotRepository>
  28 + </distributionManagement>
  29 +
  30 + <properties>
  31 + <dependency.spring.version>3.2.16.RELEASE</dependency.spring.version>
  32 + <dependency.surf.version>6.8</dependency.surf.version>
  33 + </properties>
  34 +
  35 + <dependencies>
  36 + <dependency>
  37 + <groupId>commons-codec</groupId>
  38 + <artifactId>commons-codec</artifactId>
  39 + <version>1.10</version>
  40 + </dependency>
  41 + <dependency>
  42 + <groupId>commons-collections</groupId>
  43 + <artifactId>commons-collections</artifactId>
  44 + <version>3.2.2</version>
  45 + </dependency>
  46 + <dependency>
  47 + <groupId>commons-httpclient</groupId>
  48 + <artifactId>commons-httpclient</artifactId>
  49 + <version>3.1-HTTPCLIENT-1265</version>
  50 + </dependency>
  51 + <dependency>
  52 + <groupId>commons-logging</groupId>
  53 + <artifactId>commons-logging</artifactId>
  54 + <version>1.2</version>
  55 + </dependency>
  56 + <dependency>
  57 + <groupId>commons-io</groupId>
  58 + <artifactId>commons-io</artifactId>
  59 + <version>2.4</version>
  60 + </dependency>
  61 + <dependency>
  62 + <groupId>org.apache.commons</groupId>
  63 + <artifactId>commons-math3</artifactId>
  64 + <version>3.6.1</version>
  65 + </dependency>
  66 + <dependency>
  67 + <groupId>org.hibernate</groupId>
  68 + <artifactId>hibernate</artifactId>
  69 + <version>3.2.6-alf-20131023</version>
  70 + </dependency>
  71 + <dependency>
  72 + <groupId>org.safehaus.jug</groupId>
  73 + <artifactId>jug</artifactId>
  74 + <version>2.0.0</version>
  75 + <classifier>asl</classifier>
  76 + </dependency>
  77 + <dependency>
  78 + <groupId>org.mybatis</groupId>
  79 + <artifactId>mybatis</artifactId>
  80 + <version>3.3.0</version>
  81 + </dependency>
  82 + <dependency>
  83 + <groupId>org.mybatis</groupId>
  84 + <artifactId>mybatis-spring</artifactId>
  85 + <version>1.2.5</version>
  86 + <exclusions>
  87 + <exclusion>
  88 + <groupId>org.mybatis</groupId>
  89 + <artifactId>mybatis</artifactId>
  90 + </exclusion>
  91 + </exclusions>
  92 + </dependency>
  93 + <dependency>
  94 + <groupId>log4j</groupId>
  95 + <artifactId>log4j</artifactId>
  96 + <version>1.2.17</version>
  97 + </dependency>
  98 + <dependency>
  99 + <groupId>org.json</groupId>
  100 + <artifactId>json</artifactId>
  101 + <version>20160212</version>
  102 + </dependency>
  103 + <dependency>
  104 + <groupId>org.springframework</groupId>
  105 + <artifactId>spring-orm</artifactId>
  106 + <version>${dependency.spring.version}</version>
  107 + </dependency>
  108 + <dependency>
  109 + <groupId>org.springframework</groupId>
  110 + <artifactId>spring-context</artifactId>
  111 + <version>${dependency.spring.version}</version>
  112 + </dependency>
  113 + <dependency>
  114 + <groupId>org.springframework</groupId>
  115 + <artifactId>spring-context-support</artifactId>
  116 + <version>${dependency.spring.version}</version>
  117 + </dependency>
  118 + <dependency>
  119 + <groupId>org.quartz-scheduler</groupId>
  120 + <artifactId>quartz</artifactId>
  121 + <version>1.8.3-alfresco-patched</version>
  122 + </dependency>
  123 + <dependency>
  124 + <groupId>org.alfresco.surf</groupId>
  125 + <artifactId>spring-surf-core-configservice</artifactId>
  126 + <version>${dependency.surf.version}</version>
  127 + </dependency>
  128 + <dependency>
  129 + <groupId>com.sun.xml.bind</groupId>
  130 + <artifactId>jaxb-xjc</artifactId>
  131 + <version>2.2.7</version>
  132 + </dependency>
  133 + <dependency>
  134 + <groupId>com.sun.xml.bind</groupId>
  135 + <artifactId>jaxb-impl</artifactId>
  136 + <version>2.2.7</version>
  137 + </dependency>
  138 + <dependency>
  139 + <groupId>dom4j</groupId>
  140 + <artifactId>dom4j</artifactId>
  141 + <version>1.6.1</version>
  142 + </dependency>
  143 + <dependency>
  144 + <groupId>org.codehaus.guessencoding</groupId>
  145 + <artifactId>guessencoding</artifactId>
  146 + <version>1.4</version>
  147 + </dependency>
  148 + <dependency>
  149 + <groupId>javax.transaction</groupId>
  150 + <artifactId>jta</artifactId>
  151 + <version>1.0.1b</version>
  152 + </dependency>
  153 + <dependency>
  154 + <groupId>joda-time</groupId>
  155 + <artifactId>joda-time</artifactId>
  156 + <version>2.9.3</version>
  157 + </dependency>
  158 + <dependency>
  159 + <groupId>org.apache.httpcomponents</groupId>
  160 + <artifactId>httpclient</artifactId>
  161 + <version>4.5.2</version>
  162 + </dependency>
  163 +
  164 + <!-- provided dependencies -->
  165 + <dependency>
  166 + <groupId>javax.servlet</groupId>
  167 + <artifactId>servlet-api</artifactId>
  168 + <version>2.5</version>
  169 + <scope>provided</scope>
  170 + </dependency>
  171 +
  172 + <!-- Test only dependencies, as popped up while running mvn test -->
  173 + <dependency>
  174 + <groupId>org.slf4j</groupId>
  175 + <artifactId>slf4j-log4j12</artifactId>
  176 + <version>1.7.21</version>
  177 + <scope>test</scope>
  178 + </dependency>
  179 + <dependency>
  180 + <groupId>org.springframework</groupId>
  181 + <artifactId>spring-test</artifactId>
  182 + <version>${dependency.spring.version}</version>
  183 + <scope>test</scope>
  184 + </dependency>
  185 + <dependency>
  186 + <groupId>junit</groupId>
  187 + <artifactId>junit</artifactId>
  188 + <version>4.12</version>
  189 + <scope>test</scope>
  190 + </dependency>
  191 + <dependency>
  192 + <groupId>org.mockito</groupId>
  193 + <artifactId>mockito-all</artifactId>
  194 + <version>1.10.19</version>
  195 + <scope>test</scope>
  196 + </dependency>
  197 + <dependency>
  198 + <groupId>commons-dbcp</groupId>
  199 + <artifactId>commons-dbcp</artifactId>
  200 + <version>1.4-DBCP330</version>
  201 + <scope>test</scope>
  202 + </dependency>
  203 + </dependencies>
  204 +
  205 + <build>
  206 + <pluginManagement>
  207 + <plugins>
  208 + <plugin>
  209 + <artifactId>maven-release-plugin</artifactId>
  210 + <configuration>
  211 + <autoVersionSubmodules>true</autoVersionSubmodules>
  212 + <tagNameFormat>@{project.version}</tagNameFormat>
  213 + </configuration>
  214 + </plugin>
  215 + </plugins>
  216 + </pluginManagement>
  217 +
  218 + <plugins>
  219 + <plugin>
  220 + <artifactId>maven-jar-plugin</artifactId>
  221 + <version>2.6</version>
  222 + <executions>
  223 + <execution>
  224 + <goals>
  225 + <goal>test-jar</goal>
  226 + </goals>
  227 + </execution>
  228 + </executions>
  229 + </plugin>
  230 + </plugins>
  231 + </build>
  232 +
  233 +</project>
... ...
src/main/java/org/alfresco/api/AlfrescoPublicApi.java
... ... @@ -0,0 +1,41 @@
  1 +/*
  2 + * Copyright (C) 2005-2013 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.api;
  20 +
  21 +import java.lang.annotation.Documented;
  22 +import java.lang.annotation.ElementType;
  23 +import java.lang.annotation.Retention;
  24 +import java.lang.annotation.RetentionPolicy;
  25 +import java.lang.annotation.Target;
  26 +
  27 +/**
  28 + * This annotation is used to denote a class or method as part
  29 + * of the public API. When a class or method is so designated then
  30 + * we will not change it within a release in a way that would make
  31 + * it no longer backwardly compatible with an earlier version within
  32 + * the release.
  33 + *
  34 + * @author Greg Melahn
  35 + */
  36 +@Target( {ElementType.TYPE,ElementType.METHOD} )
  37 +@Retention(RetentionPolicy.RUNTIME)
  38 +@Documented
  39 +public @interface AlfrescoPublicApi
  40 +{
  41 +}
... ...
src/main/java/org/alfresco/config/AlfrescoPropertiesPersister.java
... ... @@ -0,0 +1,77 @@
  1 +/*
  2 + * Copyright (C) 2005-2012 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.io.IOException;
  22 +import java.io.InputStream;
  23 +import java.io.Reader;
  24 +import java.util.Enumeration;
  25 +import java.util.Properties;
  26 +
  27 +import org.apache.commons.logging.Log;
  28 +import org.apache.commons.logging.LogFactory;
  29 +import org.springframework.util.DefaultPropertiesPersister;
  30 +import org.springframework.util.StringUtils;
  31 +
  32 +/**
  33 + * Simple extension to the{@link DefaultPropertiesPersister} to strip trailing whitespace
  34 + * from incoming properties.
  35 + *
  36 + * @author shane frensley
  37 + * @see org.springframework.util.DefaultPropertiesPersister
  38 + */
  39 +public class AlfrescoPropertiesPersister extends DefaultPropertiesPersister
  40 +{
  41 +
  42 + private static Log logger = LogFactory.getLog(AlfrescoPropertiesPersister.class);
  43 +
  44 + @Override
  45 + public void load(Properties props, InputStream is) throws IOException
  46 + {
  47 + super.load(props, is);
  48 + strip(props);
  49 + }
  50 +
  51 + @Override
  52 + public void load(Properties props, Reader reader) throws IOException
  53 + {
  54 + super.load(props, reader);
  55 + strip(props);
  56 + }
  57 +
  58 + public void loadFromXml(Properties props, InputStream is) throws IOException
  59 + {
  60 + super.loadFromXml(props, is);
  61 + strip(props);
  62 + }
  63 +
  64 + private void strip(Properties props)
  65 + {
  66 + for (Enumeration<Object> keys = props.keys(); keys.hasMoreElements();)
  67 + {
  68 + String key = (String) keys.nextElement();
  69 + String val = StringUtils.trimTrailingWhitespace(props.getProperty(key));
  70 + if (logger.isTraceEnabled())
  71 + {
  72 + logger.trace("Trimmed trailing whitespace for property " + key + " = " + val);
  73 + }
  74 + props.setProperty(key, val);
  75 + }
  76 + }
  77 +}
... ...
src/main/java/org/alfresco/config/JndiObjectFactoryBean.java
... ... @@ -0,0 +1,68 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.sql.Connection;
  22 +
  23 +import javax.naming.NamingException;
  24 +import javax.sql.DataSource;
  25 +
  26 +/**
  27 + * An extended version of JndiObjectFactoryBean that actually tests a JNDI data source before falling back to its
  28 + * default object. Allows continued backward compatibility with old-style datasource configuration.
  29 + *
  30 + * @author dward
  31 + */
  32 +public class JndiObjectFactoryBean extends org.springframework.jndi.JndiObjectFactoryBean
  33 +{
  34 +
  35 + @Override
  36 + protected Object lookup() throws NamingException
  37 + {
  38 + Object candidate = super.lookup();
  39 + if (candidate instanceof DataSource)
  40 + {
  41 + Connection con = null;
  42 + try
  43 + {
  44 + con = ((DataSource) candidate).getConnection();
  45 + }
  46 + catch (Exception e)
  47 + {
  48 + NamingException e1 = new NamingException("Unable to get connection from " + getJndiName());
  49 + e1.setRootCause(e);
  50 + throw e1;
  51 + }
  52 + finally
  53 + {
  54 + try
  55 + {
  56 + if (con != null)
  57 + {
  58 + con.close();
  59 + }
  60 + }
  61 + catch (Exception e)
  62 + {
  63 + }
  64 + }
  65 + }
  66 + return candidate;
  67 + }
  68 +}
... ...
src/main/java/org/alfresco/config/JndiPropertiesFactoryBean.java
... ... @@ -0,0 +1,60 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.util.Properties;
  22 +
  23 +import javax.naming.NamingException;
  24 +
  25 +import org.springframework.jndi.JndiTemplate;
  26 +
  27 +/**
  28 + * An extended {@link SystemPropertiesFactoryBean} that allows properties to be set through JNDI entries in
  29 + * java:comp/env/properties/*. The precedence given to system properties is still as per the superclass.
  30 + *
  31 + * @author dward
  32 + */
  33 +public class JndiPropertiesFactoryBean extends SystemPropertiesFactoryBean
  34 +{
  35 + private JndiTemplate jndiTemplate = new JndiTemplate();
  36 +
  37 + @Override
  38 + protected void resolveMergedProperty(String propertyName, Properties props)
  39 + {
  40 + try
  41 + {
  42 + Object value = this.jndiTemplate.lookup("java:comp/env/properties/" + propertyName);
  43 + if (value != null)
  44 + {
  45 + String stringValue = value.toString();
  46 + if (stringValue.length() > 0)
  47 + {
  48 + // Unfortunately, JBoss 4 wrongly expects every env-entry declared in web.xml to have an
  49 + // env-entry-value (even though these are meant to be decided on deployment!). So we treat the empty
  50 + // string as null.
  51 + props.setProperty(propertyName, stringValue);
  52 + }
  53 + }
  54 + }
  55 + catch (NamingException e)
  56 + {
  57 + // Fall back to merged value in props
  58 + }
  59 + }
  60 +}
... ...
src/main/java/org/alfresco/config/JndiPropertyPlaceholderConfigurer.java
... ... @@ -0,0 +1,57 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.util.Properties;
  22 +
  23 +import javax.naming.NamingException;
  24 +
  25 +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
  26 +import org.springframework.jndi.JndiTemplate;
  27 +
  28 +/**
  29 + * An extended {@link PropertyPlaceholderConfigurer} that allows properties to be set through JNDI entries in
  30 + * java:comp/env/properties/*. The precedence given to system properties is still as per the superclass.
  31 + *
  32 + * @author dward
  33 + */
  34 +public class JndiPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer
  35 +{
  36 + private JndiTemplate jndiTemplate = new JndiTemplate();
  37 +
  38 + @Override
  39 + protected String resolvePlaceholder(String placeholder, Properties props)
  40 + {
  41 + String result = null;
  42 + try
  43 + {
  44 + Object value = this.jndiTemplate.lookup("java:comp/env/properties/" + placeholder);
  45 + if (value != null)
  46 + {
  47 + result = value.toString();
  48 + }
  49 + }
  50 + catch (NamingException e)
  51 + {
  52 + }
  53 + // Unfortunately, JBoss 4 wrongly expects every env-entry declared in web.xml to have an env-entry-value (even
  54 + // though these are meant to be decided on deployment!). So we treat the empty string as null.
  55 + return result == null || result.length() == 0 ? super.resolvePlaceholder(placeholder, props) : result;
  56 + }
  57 +}
... ...
src/main/java/org/alfresco/config/NonBlockingLazyInitTargetSource.java
... ... @@ -0,0 +1,67 @@
  1 +/*
  2 + * Copyright (C) 2005-2011 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.util.concurrent.locks.ReadWriteLock;
  22 +import java.util.concurrent.locks.ReentrantReadWriteLock;
  23 +
  24 +import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource;
  25 +import org.springframework.beans.BeansException;
  26 +
  27 +/**
  28 + * A non-blocking version of LazyInitTargetSource.
  29 + *
  30 + * @author dward
  31 + */
  32 +public class NonBlockingLazyInitTargetSource extends AbstractBeanFactoryBasedTargetSource
  33 +{
  34 +
  35 + private static final long serialVersionUID = 4509578245779492037L;
  36 + private Object target;
  37 + private ReadWriteLock lock = new ReentrantReadWriteLock();
  38 +
  39 + public Object getTarget() throws BeansException
  40 + {
  41 + this.lock.readLock().lock();
  42 + try
  43 + {
  44 + if (this.target != null)
  45 + {
  46 + return this.target;
  47 + }
  48 + }
  49 + finally
  50 + {
  51 + this.lock.readLock().unlock();
  52 + }
  53 + this.lock.writeLock().lock();
  54 + try
  55 + {
  56 + if (this.target == null)
  57 + {
  58 + this.target = getBeanFactory().getBean(getTargetBeanName());
  59 + }
  60 + return this.target;
  61 + }
  62 + finally
  63 + {
  64 + this.lock.writeLock().unlock();
  65 + }
  66 + }
  67 +}
... ...
src/main/java/org/alfresco/config/PathMatchingHelper.java
... ... @@ -0,0 +1,69 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.io.IOException;
  22 +import java.net.URL;
  23 +import java.util.Set;
  24 +
  25 +import org.springframework.core.io.Resource;
  26 +import org.springframework.util.PathMatcher;
  27 +
  28 +/**
  29 + * An interface for plug ins to JBossEnabledResourcePatternResolver that avoids direct dependencies on
  30 + * application server specifics.
  31 + *
  32 + * @author dward
  33 + */
  34 +public interface PathMatchingHelper
  35 +{
  36 + /**
  37 + * Indicates whether this helper is capable of searching the given URL (i.e. its protocol is supported).
  38 + *
  39 + * @param rootURL
  40 + * the root url to be searched
  41 + * @return <code>true</code> if this helper is capable of searching the given URL
  42 + */
  43 + public boolean canHandle(URL rootURL);
  44 +
  45 + /**
  46 + * Gets the resource at the given URL.
  47 + *
  48 + * @param url URL
  49 + * @return the resource at the given URL
  50 + * @throws IOException
  51 + * for any error
  52 + */
  53 + public Resource getResource(URL url) throws IOException;
  54 +
  55 + /**
  56 + * Gets the set of resources under the given URL whose path matches the given sub pattern.
  57 + *
  58 + * @param matcher
  59 + * the matcher
  60 + * @param rootURL
  61 + * the root URL to be searched
  62 + * @param subPattern
  63 + * the ant-style pattern to match
  64 + * @return the set of matching resources
  65 + * @throws IOException
  66 + * for any error
  67 + */
  68 + public Set<Resource> getResources(PathMatcher matcher, URL rootURL, String subPattern) throws IOException;
  69 +}
0 70 \ No newline at end of file
... ...
src/main/java/org/alfresco/config/SystemPropertiesFactoryBean.java
... ... @@ -0,0 +1,141 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.io.IOException;
  22 +import java.util.Collections;
  23 +import java.util.HashSet;
  24 +import java.util.Map;
  25 +import java.util.Properties;
  26 +import java.util.Set;
  27 +
  28 +import org.springframework.beans.factory.config.PropertiesFactoryBean;
  29 +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
  30 +import org.springframework.core.Constants;
  31 +
  32 +/**
  33 + * Like the parent <code>PropertiesFactoryBean</code>, but overrides or augments the resulting property set with values
  34 + * from VM system properties. As with the Spring {@link PropertyPlaceholderConfigurer} the following modes are
  35 + * supported:
  36 + * <ul>
  37 + * <li><b>SYSTEM_PROPERTIES_MODE_NEVER: </b>Don't use system properties at all.</li>
  38 + * <li><b>SYSTEM_PROPERTIES_MODE_FALLBACK: </b>Fallback to a system property only for undefined properties.</li>
  39 + * <li><b>SYSTEM_PROPERTIES_MODE_OVERRIDE: (DEFAULT)</b>Use a system property if it is available.</li>
  40 + * </ul>
  41 + * Note that system properties will only be included in the property set if defaults for the property have already been
  42 + * defined using {@link #setProperties(Properties)} or {@link #setLocations(org.springframework.core.io.Resource[])} or
  43 + * their names have been included explicitly in the set passed to {@link #setSystemProperties(Set)}.
  44 + *
  45 + * @author Derek Hulley
  46 + */
  47 +public class SystemPropertiesFactoryBean extends PropertiesFactoryBean
  48 +{
  49 + private static final Constants constants = new Constants(PropertyPlaceholderConfigurer.class);
  50 +
  51 + private int systemPropertiesMode = PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE;
  52 + private Set<String> systemProperties = Collections.emptySet();
  53 +
  54 + /**
  55 + * Set the system property mode by the name of the corresponding constant, e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE".
  56 + *
  57 + * @param constantName
  58 + * name of the constant
  59 + * @throws java.lang.IllegalArgumentException
  60 + * if an invalid constant was specified
  61 + * @see #setSystemPropertiesMode
  62 + */
  63 + public void setSystemPropertiesModeName(String constantName) throws IllegalArgumentException
  64 + {
  65 + this.systemPropertiesMode = SystemPropertiesFactoryBean.constants.asNumber(constantName).intValue();
  66 + }
  67 +
  68 + /**
  69 + * Set how to check system properties.
  70 + *
  71 + * @see PropertyPlaceholderConfigurer#setSystemPropertiesMode(int)
  72 + */
  73 + public void setSystemPropertiesMode(int systemPropertiesMode)
  74 + {
  75 + this.systemPropertiesMode = systemPropertiesMode;
  76 + }
  77 +
  78 + /**
  79 + * Set the names of the properties that can be considered for overriding.
  80 + *
  81 + * @param systemProperties
  82 + * a set of properties that can be fetched from the system properties
  83 + */
  84 + public void setSystemProperties(Set<String> systemProperties)
  85 + {
  86 + this.systemProperties = systemProperties;
  87 + }
  88 +
  89 + @SuppressWarnings("unchecked")
  90 + @Override
  91 + protected Properties mergeProperties() throws IOException
  92 + {
  93 + // First do the default merge
  94 + Properties props = super.mergeProperties();
  95 +
  96 + // Now resolve all the merged properties
  97 + if (this.systemPropertiesMode == PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_NEVER)
  98 + {
  99 + // If we are in never mode, we don't refer to system properties at all
  100 + for (String systemProperty : (Set<String>) (Set) props.keySet())
  101 + {
  102 + resolveMergedProperty(systemProperty, props);
  103 + }
  104 + }
  105 + else
  106 + {
  107 + // Otherwise, we allow unset properties to drift through from the systemProperties set and potentially set
  108 + // ones to be overriden by system properties
  109 + Set<String> propNames = new HashSet<String>((Set<String>) (Set) props.keySet());
  110 + propNames.addAll(this.systemProperties);
  111 + for (String systemProperty : propNames)
  112 + {
  113 + resolveMergedProperty(systemProperty, props);
  114 + if (this.systemPropertiesMode == PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK
  115 + && props.containsKey(systemProperty))
  116 + {
  117 + // It's already there
  118 + continue;
  119 + }
  120 + // Get the system value and assign if present
  121 + String systemPropertyValue = System.getProperty(systemProperty);
  122 + if (systemPropertyValue != null)
  123 + {
  124 + props.put(systemProperty, systemPropertyValue);
  125 + }
  126 + }
  127 + }
  128 + return props;
  129 + }
  130 +
  131 + /**
  132 + * Override hook. Allows subclasses to resolve a merged property from an alternative source, whilst still respecting
  133 + * the chosen system property fallback path.
  134 + *
  135 + * @param systemProperty String
  136 + * @param props Properties
  137 + */
  138 + protected void resolveMergedProperty(String systemProperty, Properties props)
  139 + {
  140 + }
  141 +}
... ...
src/main/java/org/alfresco/config/SystemPropertiesSetterBean.java
... ... @@ -0,0 +1,94 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.config;
  20 +
  21 +import java.util.HashMap;
  22 +import java.util.Map;
  23 +
  24 +import org.apache.commons.logging.Log;
  25 +import org.apache.commons.logging.LogFactory;
  26 +
  27 +/**
  28 + * Takes a set of properties and pushes them into the Java environment. Usually, VM properties
  29 + * are required by the system (see {@link SystemPropertiesFactoryBean} and
  30 + * Spring's <tt>PropertyPlaceholderConfigurer</tt>); sometimes it is necessary to take properties
  31 + * available to Spring and push them onto the VM.
  32 + * <p>
  33 + * For simplicity, the system property, if present, will NOT be modified. Also, property placeholders
  34 + * (<b>${...}</b>), empty values and null values will be ignored.
  35 + * <p>
  36 + * Use the {@link #init()} method to push the properties.
  37 + *
  38 + * @author Derek Hulley
  39 + * @since V3.1
  40 + */
  41 +public class SystemPropertiesSetterBean
  42 +{
  43 + private static Log logger = LogFactory.getLog(SystemPropertiesSetterBean.class);
  44 +
  45 + private Map<String, String> propertyMap;
  46 +
  47 + SystemPropertiesSetterBean()
  48 + {
  49 + propertyMap = new HashMap<String, String>(3);
  50 + }
  51 +
  52 + /**
  53 + * Set the properties that will be pushed onto the JVM.
  54 + *
  55 + * @param propertyMap a map of <b>property name</b> to <b>property value</b>
  56 + */
  57 + public void setPropertyMap(Map<String, String> propertyMap)
  58 + {
  59 + this.propertyMap = propertyMap;
  60 + }
  61 +
  62 + public void init()
  63 + {
  64 + for (Map.Entry<String, String> entry : propertyMap.entrySet())
  65 + {
  66 + String name = entry.getKey();
  67 + String value = entry.getValue();
  68 + // Some values can be ignored
  69 + if (value == null || value.length() == 0)
  70 + {
  71 + continue;
  72 + }
  73 + if (value.startsWith("${") && value.endsWith("}"))
  74 + {
  75 + continue;
  76 + }
  77 + // Check the system properties
  78 + if (System.getProperty(name) != null)
  79 + {
  80 + // It was already there
  81 + if (logger.isDebugEnabled())
  82 + {
  83 + logger.debug("\n" +
  84 + "Not pushing up system property: \n" +
  85 + " Property: " + name + "\n" +
  86 + " Value already present: " + System.getProperty(name) + "\n" +
  87 + " Value provided: " + value);
  88 + }
  89 + continue;
  90 + }
  91 + System.setProperty(name, value);
  92 + }
  93 + }
  94 +}
... ...
src/main/java/org/alfresco/encoding/AbstractCharactersetFinder.java
... ... @@ -0,0 +1,172 @@
  1 +/*
  2 + * Copyright (C) 2005-2010 Alfresco Software Limited.
  3 + *
  4 + * This file is part of Alfresco
  5 + *
  6 + * Alfresco is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published by
  8 + * the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * Alfresco is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU Lesser General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18 + */
  19 +package org.alfresco.encoding;
  20 +
  21 +import java.io.IOException;
  22 +import java.io.InputStream;
  23 +import java.nio.charset.Charset;
  24 +import java.util.Arrays;
  25 +
  26 +import org.alfresco.error.AlfrescoRuntimeException;
  27 +import org.apache.commons.logging.Log;
  28 +import org.apache.commons.logging.LogFactory;
  29 +
  30 +/**
  31 + * @since 2.1
  32 + * @author Derek Hulley
  33 + */
  34 +public abstract class AbstractCharactersetFinder implements CharactersetFinder
  35 +{
  36 + private static Log logger = LogFactory.getLog(AbstractCharactersetFinder.class);
  37 + private static boolean isDebugEnabled = logger.isDebugEnabled();
  38 +
  39 + private int bufferSize;
  40 +
  41 + public AbstractCharactersetFinder()
  42 + {
  43 + this.bufferSize = 8192;
  44 + }
  45 +
  46 + /**
  47 + * Set the maximum number of bytes to read ahead when attempting to determine the characterset.
  48 + * Most characterset detectors are efficient and can process 8K of buffered data very quickly.
  49 + * Some, may need to be constrained a bit.
  50 + *
  51 + * @param bufferSize the number of bytes - default 8K.
  52 + */
  53 + public void setBufferSize(int bufferSize)
  54 + {
  55 + this.bufferSize = bufferSize;
  56 + }
  57 +
  58 + /**
  59 + * {@inheritDoc}
  60 + * <p>
  61 + * The input stream is checked to ensure that it supports marks, after which
  62 + * a buffer is extracted, leaving the stream in its original state.
  63 + */
  64 + public final Charset detectCharset(InputStream is)
  65 + {
  66 + // Only support marking streams
  67 + if (!is.markSupported())
  68 + {
  69 + throw new IllegalArgumentException("The InputStream must support marks. Wrap the stream in a BufferedInputStream.");
  70 + }
  71 + try
  72 + {
  73 + int bufferSize = getBufferSize();
  74 + if (bufferSize < 0)
  75 + {
  76 + throw new RuntimeException("The required buffer size may not be negative: " + bufferSize);
  77 + }
  78 + // Mark the stream for just a few more than we actually will need
  79 + is.mark(bufferSize);
  80 + // Create a buffer to hold the data
  81 + byte[] buffer = new byte[bufferSize];
  82 + // Fill it
  83 + int read = is.read(buffer);
  84 + // Create an appropriately sized buffer
  85 + if (read > -1 && read < buffer.length)
  86 + {
  87 + byte[] copyBuffer = new byte[read];
  88 + System.arraycopy(buffer, 0, copyBuffer, 0, read);
  89 + buffer = copyBuffer;
  90 + }