Skip to content

Commit

Permalink
Formatting / Java.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Jun 2, 2016
1 parent 377f07f commit cdb3f86
Show file tree
Hide file tree
Showing 1,572 changed files with 64,381 additions and 68,321 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.fzi.dbs.xml.transform;

import net.sf.saxon.TransformerFactoryImpl;

import org.apache.log4j.Logger;
import org.fao.geonet.utils.CachedTransformer;

Expand All @@ -9,6 +10,7 @@
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
Expand All @@ -17,23 +19,16 @@


/**
* Caching implementation of JAXP transformer factory.
* This implementation caches templates that were loaded from local files
* so that consequent calls to local stylesheets require stylesheet reparsing
* only if stylesheet was changed.
* Caching implementation of JAXP transformer factory. This implementation caches templates that
* were loaded from local files so that consequent calls to local stylesheets require stylesheet
* reparsing only if stylesheet was changed.
*/
public class CachingTransformerFactory extends TransformerFactoryImpl implements CachedTransformer {
/**
* Map to hold templates cache.
*/
private static Map<String, TemplatesCacheEntry> templatesCache = new HashMap<String, TemplatesCacheEntry>();

/**
* Factory logger.
*/
protected static final Logger logger =
Logger.getLogger(CachingTransformerFactory.class);

Logger.getLogger(CachingTransformerFactory.class);
/**
* Active readers count.
*/
Expand All @@ -42,11 +37,15 @@ public class CachingTransformerFactory extends TransformerFactoryImpl implements
* Active writers count.
*/
static int activeWriters = 0;
/**
* Map to hold templates cache.
*/
private static Map<String, TemplatesCacheEntry> templatesCache = new HashMap<String, TemplatesCacheEntry>();

/**
* Clear the stylesheet cache. This is not part of the
* JAXP TransformerFactoryImpl so users should test for existence of this
* method before calling otherwise JAXP compatibility will be broken.
* Clear the stylesheet cache. This is not part of the JAXP TransformerFactoryImpl so users
* should test for existence of this method before calling otherwise JAXP compatibility will be
* broken.
*/
public void clearCache() {
beforeWrite();
Expand All @@ -55,19 +54,19 @@ public void clearCache() {
}

/**
* Process the source into a Transformer object. If source is a StreamSource
* with <code>systemID</code> pointing to a file, transformer is produced
* from a cached templates object. Cache is done in soft references; cached
* objects are reloaded, when file's date of last modification changes.
* Process the source into a Transformer object. If source is a StreamSource with
* <code>systemID</code> pointing to a file, transformer is produced from a cached templates
* object. Cache is done in soft references; cached objects are reloaded, when file's date of
* last modification changes.
*
* @param source An object that holds a URI, input stream, etc.
* @return A Transformer object that may be used to perform a transformation
* in a single thread, never null.
* @throws TransformerConfigurationException - May throw this during the
* parse when it is constructing the Templates object and fails.
* @return A Transformer object that may be used to perform a transformation in a single thread,
* never null.
* @throws TransformerConfigurationException - May throw this during the parse when it is
* constructing the Templates object and fails.
*/
public Transformer newTransformer(final Source source)
throws TransformerConfigurationException {
throws TransformerConfigurationException {
// Check that source in a StreamSource
if (source instanceof StreamSource) {
try {
Expand All @@ -86,16 +85,15 @@ public Transformer newTransformer(final Source source)
}

/**
* Creates a transformer from a file (and caches templates) or from
* cached templates object.
* Creates a transformer from a file (and caches templates) or from cached templates object.
*
* @param file file to load transformer from.
* @return Transformer, built from given file.
* @throws TransformerConfigurationException if there was a problem loading
* transformer from the file.
* @throws TransformerConfigurationException if there was a problem loading transformer from the
* file.
*/
protected Transformer newTransformer(final File file)
throws TransformerConfigurationException {
throws TransformerConfigurationException {
// Search the cache for the templates entry
TemplatesCacheEntry templatesCacheEntry = read(file.getAbsolutePath());

Expand All @@ -112,14 +110,14 @@ protected Transformer newTransformer(final File file)
// If this file does not exists, throw the exception
if (!file.exists()) {
throw new TransformerConfigurationException(
"Requested transformation ["
"Requested transformation ["
+ file.getAbsolutePath()
+ "] does not exist.");
}

// Create new cache entry
templatesCacheEntry =
new TemplatesCacheEntry(newTemplates(new StreamSource(file)), file);
new TemplatesCacheEntry(newTemplates(new StreamSource(file)), file);

// Save this entry to the cache
write(file.getAbsolutePath(), templatesCacheEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
/**
* Holds the application context in a thread local.
*
* User: Jesse
* Date: 11/26/13
* Time: 11:04 AM
* User: Jesse Date: 11/26/13 Time: 11:04 AM
*/
public class ApplicationContextHolder {
private static InheritableThreadLocal<ConfigurableApplicationContext> holder = new InheritableThreadLocal<ConfigurableApplicationContext>();
Expand Down
79 changes: 34 additions & 45 deletions common/src/main/java/org/fao/geonet/JeevesJCS.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,96 +38,85 @@
/**
* @author jeichar
*/
public class JeevesJCS extends GroupCacheAccess
{
public class JeevesJCS extends GroupCacheAccess {

/** The manager returns cache instances. */
/**
* The manager returns cache instances.
*/
private static CompositeCacheManager cacheMgr;
private static Path configFilename;

protected JeevesJCS(CompositeCache cacheControl)
{
protected JeevesJCS(CompositeCache cacheControl) {
super(cacheControl);
}

/**
* Get a GeonetworkJCS which accesses the provided region.
* <p>
* Get a GeonetworkJCS which accesses the provided region. <p>
*
* @param region Region that return GeonetworkJCS will provide access to
* @return A GeonetworkJCS which provides access to a given region.
* @exception CacheException
*/
public static JeevesJCS getInstance( String region )
throws CacheException
{
public static JeevesJCS getInstance(String region)
throws CacheException {
ensureCacheManager();

return new JeevesJCS( cacheMgr.getCache( region ) );
return new JeevesJCS(cacheMgr.getCache(region));
}

/**
* Get a GeonetworkJCS which accesses the provided region.
* <p>
* Get a GeonetworkJCS which accesses the provided region. <p>
*
* @param region Region that return GeonetworkJCS will provide access to
* @param icca CacheAttributes for region
* @param icca CacheAttributes for region
* @return A GeonetworkJCS which provides access to a given region.
* @exception CacheException
*/
public static JeevesJCS getInstance( String region, ICompositeCacheAttributes icca )
throws CacheException
{
public static JeevesJCS getInstance(String region, ICompositeCacheAttributes icca)
throws CacheException {
ensureCacheManager();

return new JeevesJCS( cacheMgr.getCache( region, icca ) );
return new JeevesJCS(cacheMgr.getCache(region, icca));
}

/**
* Gets an instance of CompositeCacheManager and stores it in the cacheMgr class field, if it is
* not already set. Unlike the implementation in CacheAccess, the cache manager is a
* CompositeCacheManager. NOTE: This can will be moved up into GroupCacheAccess.
*/
protected static synchronized void ensureCacheManager()
{
if ( cacheMgr == null )
{
if ( configFilename == null )
{
protected static synchronized void ensureCacheManager() {
if (cacheMgr == null) {
if (configFilename == null) {
cacheMgr = CompositeCacheManager.getInstance();
}
else
{
} else {
cacheMgr = CompositeCacheManager.getUnconfiguredInstance();

configure( );
configure();
}
}
}


private static void configure()
{

private static void configure() {

Properties props = new Properties();

try (Reader is = IO.newBufferedReader(configFilename, Constants.CHARSET)) {
props.load( is );
props.load(is);
} catch (IOException e) {
throw new IllegalStateException( "Unable to load cache configuration from: "+configFilename, e);
throw new IllegalStateException("Unable to load cache configuration from: " + configFilename, e);
}

cacheMgr.configure( props );
cacheMgr.configure(props);

}

/**
* Set the filename that the cache manager will be initialized with. Only matters before the
* instance is initialized.
* <p>
* @param configFilename
* instance is initialized. <p>
*/
public static void setConfigFilename( Path configFilename )
{
cacheMgr=null;
public static void setConfigFilename(Path configFilename) {
cacheMgr = null;
JeevesJCS.configFilename = configFilename;
}


}
25 changes: 17 additions & 8 deletions common/src/main/java/org/fao/geonet/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@

//=============================================================================

public interface Logger
{
public interface Logger {
public boolean isDebugEnabled();
public void debug (String message);
public void info (String message);
public void warning(String message);
public void error (String message);
public void error (Throwable ex);
public void fatal (String message);

public void debug(String message);

public void info(String message);

public void warning(String message);

public void error(String message);

public void error(Throwable ex);

public void fatal(String message);

public String getModule();

public void setAppender(FileAppender fa);

public String getFileAppender();

public org.apache.log4j.Level getThreshold();

}
Expand Down
12 changes: 5 additions & 7 deletions common/src/main/java/org/fao/geonet/NodeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
/**
* Encapsulates information about the current node such as the node id.
*
* User: Jesse
* Date: 11/27/13
* Time: 2:35 PM
* User: Jesse Date: 11/27/13 Time: 2:35 PM
*/
public class NodeInfo implements Serializable {
private String id = "srv";
Expand All @@ -53,11 +51,11 @@ public void setDefaultNode(boolean defaultNode) {
this.defaultNode = defaultNode;
}

public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}

public boolean isReadOnly() {
return readOnly;
}

public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
Loading

0 comments on commit cdb3f86

Please sign in to comment.