org.apache.sling.fileoptim.impl

## Class FileOptimizerServiceImpl

- java.lang.Object
- - org.apache.sling.fileoptim.impl.FileOptimizerServiceImpl

All Implemented Interfaces:
  EventListener, FileOptimizerService, org.osgi.framework.ServiceListener

    public class FileOptimizerServiceImpl
    extends Object
    implements FileOptimizerService, org.osgi.framework.ServiceListener

Implementation of the FileOptimizerService

### Nested Class Summary

Nested Classes
`static interface` `FileOptimizerServiceImpl.Config`

### Constructor Summary

Constructors
Constructor and Description
`FileOptimizerServiceImpl()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `activate(org.osgi.service.component.ComponentContext context, FileOptimizerServiceImpl.Config config)`
`boolean` `canOptimize(org.apache.sling.api.resource.Resource fileResource)` Returns true if the resource is a registered type, the CA Config for the resource is enabled and if an optimizer is registered for the file's meta type
`void` `deactivate(org.osgi.service.component.ComponentContext context)`
`Map<String,List<org.osgi.framework.ServiceReference<FileOptimizer>>>` `getFileOptimizers()`
`OptimizationResult` `getOptimizedContents(org.apache.sling.api.resource.Resource fileResource)` Gets the optimized contents of a file resource.
`boolean` `isOptimized(org.apache.sling.api.resource.Resource fileResource)` Returns true if the specified resource has already been optimized by the FileOptimizer.
`OptimizationResult` `optimizeFile(org.apache.sling.api.resource.Resource fileResource, boolean autoCommit)` Optimizes a file resource.
`void` `serviceChanged(org.osgi.framework.ServiceEvent event)`
`void` `setFileOptimizers(Map<String,List<org.osgi.framework.ServiceReference<FileOptimizer>>> fileOptimizers)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FileOptimizerServiceImpl

    public FileOptimizerServiceImpl()

### Method Detail

#### activate

    public void activate(org.osgi.service.component.ComponentContext context,
                         FileOptimizerServiceImpl.Config config)
                  throws org.osgi.framework.InvalidSyntaxException

Throws:
  `org.osgi.framework.InvalidSyntaxException`

#### canOptimize

    public boolean canOptimize(org.apache.sling.api.resource.Resource fileResource)

Description copied from interface: `FileOptimizerService`
Returns true if the resource is a registered type, the CA Config for the resource is enabled and if an optimizer is registered for the file's meta type

Specified by:
  `canOptimize` in interface `FileOptimizerService`
Parameters:
  `fileResource` - the resource to check if the optimizer is available
Returns:
  true if the file optimizer can optimize the file, false otherwise

#### deactivate

    public void deactivate(org.osgi.service.component.ComponentContext context)

#### getFileOptimizers

    public Map<String,List<org.osgi.framework.ServiceReference<FileOptimizer>>> getFileOptimizers()

Returns:
  the fileOptimizers

#### getOptimizedContents

    public OptimizationResult getOptimizedContents(org.apache.sling.api.resource.Resource fileResource)
                                            throws IOException

Description copied from interface: `FileOptimizerService`
Gets the optimized contents of a file resource. This will not update the underlying resource, but instead just returns the results of optimizing the resource.

Specified by:
  `getOptimizedContents` in interface `FileOptimizerService`
Parameters:
  `fileResource` - the resource to optimize
Returns:
  the results of the optimization
Throws:
  `IOException` - an exception occurs reading the original resource

#### isOptimized

    public boolean isOptimized(org.apache.sling.api.resource.Resource fileResource)

Description copied from interface: `FileOptimizerService`
Returns true if the specified resource has already been optimized by the FileOptimizer.

Specified by:
  `isOptimized` in interface `FileOptimizerService`
Parameters:
  `fileResource` - the resource to check
Returns:
  true if optimized by the file optimizer, false otherwise

#### optimizeFile

    public OptimizationResult optimizeFile(org.apache.sling.api.resource.Resource fileResource,
                                           boolean autoCommit)
                                    throws IOException

Description copied from interface: `FileOptimizerService`
Optimizes a file resource. This method will modify the underlying resource.

Specified by:
  `optimizeFile` in interface `FileOptimizerService`
Parameters:
  `fileResource` - the resource to optimize
  `autoCommit` - if true, the results will automatically be committed to the Sling Repo
Returns:
  the results of the optimization
Throws:
  `IOException` - an exception occurs reading the original resource

#### serviceChanged

    public void serviceChanged(org.osgi.framework.ServiceEvent event)

Specified by:
  `serviceChanged` in interface `org.osgi.framework.ServiceListener`

#### setFileOptimizers

    public void setFileOptimizers(Map<String,List<org.osgi.framework.ServiceReference<FileOptimizer>>> fileOptimizers)

Parameters:
  `fileOptimizers` - the fileOptimizers to set