/*
 * Copyright (C) 2011.
 * All rights reserved.
 */
package ro.isdc.wro.examples.manager;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import ro.isdc.wro.config.Context;
import ro.isdc.wro.config.metadata.DefaultMetaDataFactory;
import ro.isdc.wro.config.metadata.MetaDataFactory;
import ro.isdc.wro.extensions.model.factory.GroovyModelFactory;
import ro.isdc.wro.extensions.processor.css.YUICssCompressorProcessor;
import ro.isdc.wro.manager.factory.BaseWroManagerFactory;
import ro.isdc.wro.model.factory.WroModelFactory;
import ro.isdc.wro.model.resource.processor.ResourcePreProcessor;
import ro.isdc.wro.model.resource.processor.factory.ProcessorsFactory;
import ro.isdc.wro.model.resource.processor.factory.SimpleProcessorsFactory;
import ro.isdc.wro.model.resource.processor.impl.PlaceholderProcessor;
import ro.isdc.wro.model.resource.processor.impl.css.CssImportPreProcessor;
import ro.isdc.wro.model.resource.processor.impl.css.CssUrlRewritingProcessor;
import ro.isdc.wro.model.resource.processor.impl.css.CssVariablesProcessor;
import ro.isdc.wro.model.resource.processor.impl.css.JawrCssMinifierProcessor;
import ro.isdc.wro.model.resource.processor.impl.js.SemicolonAppenderPreProcessor;
import ro.isdc.wro.util.ObjectFactory;

/**
 * @author Alex Objelean
 */
public class CustomWroManagerFactory
    extends BaseWroManagerFactory {

  /**
   * {@inheritDoc}
   */
  @Override
  protected WroModelFactory newModelFactory() {
    return new GroovyModelFactory() {
      @Override
      protected InputStream getModelResourceAsStream()
        throws IOException {
        return Context.get().getServletContext().getResourceAsStream("/WEB-INF/wro.groovy");
      }
    };
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected ProcessorsFactory newProcessorsFactory() {
    //preProcessors=bomStripper,cssImport,cssUrlRewriting,semicolonAppender,yuiJsMinAdvanced,yuiCssMin
    //postProcessors=cssVariables


    final SimpleProcessorsFactory factory = new SimpleProcessorsFactory();
    //factory.addPreProcessor(getPlaceholderProcessor());
    factory.addPreProcessor(new CssUrlRewritingProcessor());
    factory.addPreProcessor(new CssImportPreProcessor());
    factory.addPreProcessor(new SemicolonAppenderPreProcessor());
    //factory.addPreProcessor(new JSMinProcessor());
    factory.addPreProcessor(new YUICssCompressorProcessor());
    factory.addPostProcessor(new CssVariablesProcessor());

    factory.addPreProcessor(new JawrCssMinifierProcessor());

    return factory;
  }

  @Override
  protected MetaDataFactory newMetaDataFactory() {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put("jsHintOptions", "value");
    return new DefaultMetaDataFactory(map);
  }

  private ResourcePreProcessor getPlaceholderProcessor() {
    return new PlaceholderProcessor().setPropertiesFactory(new ObjectFactory<Properties>() {
      @Override
      public Properties create() {
        final Properties props = new Properties();
        props.put("GLOBAL_COLOR", "red");
        return props;
      }
    });
  }
}

@@ -220,16 +220,61 @@
 rties;%0A%0A
+import org.apache.commons.lang3.ArrayUtils;%0A%0A
 import r
@@ -300,16 +300,16 @@
 ontext;%0A
-
 import r
@@ -538,32 +538,92 @@
 essorProcessor;%0A
+import ro.isdc.wro.extensions.processor.js.JsHintProcessor;%0A
 import ro.isdc.w
@@ -706,32 +706,71 @@
 roModelFactory;%0A
+import ro.isdc.wro.model.group.Inject;%0A
 import ro.isdc.w
@@ -1578,16 +1578,86 @@
 tory %7B%0A%0A
+  private static final String KEY_JS_HINT_OPTIONS = %22jsHintOptions%22;%0A%0A
   /**%0A  
@@ -2776,24 +2776,348 @@
 rocessor());
+%0A    factory.addPreProcessor(new JsHintProcessor() %7B%0A      @Inject%0A      private MetaDataFactory metaDataFactory;%0A      @Override%0A      protected String%5B%5D getOptions() %7B%0A        //Not very safe, probably can validate it before cast%0A        return (String%5B%5D) metaDataFactory.create().get(KEY_JS_HINT_OPTIONS);%0A      %7D%0A    %7D);
 %0A%0A    return
@@ -3277,32 +3277,56 @@
 put(
-%22jsHintOptions%22, %22value%22
+KEY_JS_HINT_OPTIONS, ArrayUtils.toArray(%22undef%22)
 );%0A 

Use MetaDataFactory inside a custom processor to configure it (for sake of example)