Projects >> wro4j >>61f60a3eb51ab2da585efc005eeed7199a077b6b

Chunk
Conflicting content
    return schema;
  }

<<<<<<< HEAD
=======

>>>>>>> 545682710625a7fd8135c994c367f3790134d439
  /**
   * Initialize the map
   */
Solution content
    return schema;
  }

  /**
   * Initialize the map
   */
File
XmlModelFactory.java
Developer's decision
Version 1
Kind of conflict
Blank
Chunk
Conflicting content
import ro.isdc.wro.WroRuntimeException;
import ro.isdc.wro.model.WroModel;
<<<<<<< HEAD
import ro.isdc.wro.model.factory.WroModelFactory;
import ro.isdc.wro.model.resource.locator.ResourceLocator;
import ro.isdc.wro.model.resource.locator.support.ServletContextResourceLocator;
=======
import ro.isdc.wro.model.factory.AbstractWroModelFactory;
>>>>>>> 545682710625a7fd8135c994c367f3790134d439


/**
Solution content
import ro.isdc.wro.WroRuntimeException;
import ro.isdc.wro.model.WroModel;
import ro.isdc.wro.model.factory.AbstractWroModelFactory;


/**
File
GroovyWroModelFactory.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
    }
  }

<<<<<<< HEAD
  /**
   * Override this method, in order to provide different groovy model location.
   *
   * @return stream of the json representation of the model.
   * @throws java.io.IOException if the stream couldn't be read.
   */
  protected ResourceLocator getModelResourceLocator() {
    return new ServletContextResourceLocator(Context.get().getServletContext(), "/WEB-INF/" + DEFAULT_FILE_NAME);
  }


=======
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
  /**
   * {@inheritDoc}
   */
Solution content
    }
  }

  /**
   * {@inheritDoc}
   */
File
GroovyWroModelFactory.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
import ro.isdc.wro.WroRuntimeException;
import ro.isdc.wro.model.WroModel;
<<<<<<< HEAD
import ro.isdc.wro.model.factory.WroModelFactory;
import ro.isdc.wro.model.resource.locator.ResourceLocator;
import ro.isdc.wro.model.resource.locator.support.ServletContextResourceLocator;
=======
import ro.isdc.wro.model.factory.AbstractWroModelFactory;
>>>>>>> 545682710625a7fd8135c994c367f3790134d439

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
Solution content
import ro.isdc.wro.WroRuntimeException;
import ro.isdc.wro.model.WroModel;
import ro.isdc.wro.model.factory.AbstractWroModelFactory;
import ro.isdc.wro.model.resource.locator.ResourceLocator;
import ro.isdc.wro.model.resource.locator.support.ServletContextResourceLocator;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
File
JsonModelFactory.java
Developer's decision
Combination
Kind of conflict
Import
Chunk
Conflicting content
    }
  }

<<<<<<< HEAD
  protected ResourceLocator getModelResourceLocator() {
    return new ServletContextResourceLocator(Context.get().getServletContext(), "/WEB-INF/" + DEFAULT_FILE_NAME);
  }

=======
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
  /**
   * {@inheritDoc}
   */
Solution content
    }
  }

  /**
   * {@inheritDoc}
   */
File
JsonModelFactory.java
Developer's decision
Version 2
Kind of conflict
Method declaration
Chunk
Conflicting content
    Validate.notNull(context);
    final boolean autoDetectWroFile = FilenameUtils.normalize(context.getWroFile().getPath()).contains(
      FilenameUtils.normalize(DEFAULT_WRO_FILE));
<<<<<<< HEAD
=======
    if (!autoDetectWroFile) {
      LOG.info("autoDetect is " + autoDetectWroFile + " because wroFile: " + context.getWroFile()
        + " is not the same as the default one: " + DEFAULT_WRO_FILE);
    }
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
    return new SmartWroModelFactory().setWroFile(context.getWroFile()).setAutoDetectWroFile(autoDetectWroFile);
  }
Solution content
    Validate.notNull(context);
    final boolean autoDetectWroFile = FilenameUtils.normalize(context.getWroFile().getPath()).contains(
      FilenameUtils.normalize(DEFAULT_WRO_FILE));
    if (!autoDetectWroFile) {
      LOG.info("autoDetect is " + autoDetectWroFile + " because wroFile: " + context.getWroFile()
        + " is not the same as the default one: " + DEFAULT_WRO_FILE);
    }
    return new SmartWroModelFactory().setWroFile(context.getWroFile()).setAutoDetectWroFile(autoDetectWroFile);
  }
File
SmartWroModelFactory.java
Developer's decision
Version 2
Kind of conflict
If statement
Chunk
Conflicting content
   */
  protected List newWroModelFactoryFactoryList() {
    final List factoryList = new ArrayList();
<<<<<<< HEAD
    LOG.info("autoDetect wroFile: " + autoDetectWroFile);
=======
    LOG.debug("auto detect wroFile: " + autoDetectWroFile);
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
    factoryList.add(newXmlModelFactory());
    factoryList.add(newGroovyModelFactory());
    factoryList.add(newJsonModelFactory());
Solution content
   */
  protected List newWroModelFactoryFactoryList() {
    final List factoryList = new ArrayList();
    LOG.debug("auto detect wroFile: " + autoDetectWroFile);
    factoryList.add(newXmlModelFactory());
    factoryList.add(newGroovyModelFactory());
    factoryList.add(newJsonModelFactory());
File
SmartWroModelFactory.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Chunk
Conflicting content
  private XmlModelFactory newXmlModelFactory() {
    return new XmlModelFactory() {
      @Override
<<<<<<< HEAD
      protected ResourceLocator getModelResourceLocator() {
        return createAutoDetectingResourceLocator(super.getModelResourceLocator(), XmlModelFactory.DEFAULT_FILE_NAME);
=======
      protected InputStream getModelResourceAsStream()
        throws IOException {
        if (wroFile == null) {
          return super.getModelResourceAsStream();
        }
        return createAutoDetectedStream(getDefaultModelFilename());
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
      }
    };
  }
Solution content
  private XmlModelFactory newXmlModelFactory() {
    return new XmlModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        if (wroFile == null) {
          return super.getModelResourceLocator();
        }
        return createAutoDetectingResourceLocator(getDefaultModelFilename());
      }
    };
  }
File
SmartWroModelFactory.java
Developer's decision
Manual
Kind of conflict
If statement
Method invocation
Method signature
Return statement
Chunk
Conflicting content
  private GroovyWroModelFactory newGroovyModelFactory() {
    return new GroovyWroModelFactory() {
      @Override
<<<<<<< HEAD
      protected ResourceLocator getModelResourceLocator() {
        return createAutoDetectingResourceLocator(super.getModelResourceLocator(), GroovyWroModelFactory.DEFAULT_FILE_NAME);
=======
      protected InputStream getModelResourceAsStream()
        throws IOException {
        if (wroFile == null) {
          return super.getModelResourceAsStream();
        }
        return createAutoDetectedStream(getDefaultModelFilename());
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
      }
    };
  }
Solution content
  private GroovyWroModelFactory newGroovyModelFactory() {
    return new GroovyWroModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        if (wroFile == null) {
          return super.getModelResourceLocator();
        }
        return createAutoDetectingResourceLocator(getDefaultModelFilename());
      }
    };
  }
File
SmartWroModelFactory.java
Developer's decision
Manual
Kind of conflict
If statement
Method invocation
Method signature
Return statement
Chunk
Conflicting content
      @Override
      public InputStream getInputStream()
        throws IOException {
<<<<<<< HEAD
        if (autoDetectWroFile) {
          final File file = new File(wroFile.getParentFile(), defaultFileName);
          LOG.info("loading autodetected wro file: " + file);
          return new FileInputStream(file);
        }
        LOG.info("loading wroFile: " + wroFile);
        return new FileInputStream(wroFile);
      }
    };
=======
        if (wroFile == null) {
          return super.getModelResourceAsStream();
        }
        return createAutoDetectedStream(getDefaultModelFilename());
      }
    };
  }


  /**
   * Handles the resource model auto detection.
   */
  private InputStream createAutoDetectedStream(final String defaultFileName) throws IOException {
    try {
      Validate.notNull(wroFile, "Cannot call this method if wroFile is null!");
      if (autoDetectWroFile) {
        final File file = new File(wroFile.getParentFile(), defaultFileName);
        LOG.info("loading autodetected wro file: " + file);
        return new FileInputStream(file);
      }
      LOG.info("loading wroFile: " + wroFile);
      return new FileInputStream(wroFile);
    } catch (final FileNotFoundException e) {
      // When auto detect is turned on, do not skip trying.. because the auto detection assume that the wro file name
      // can be wrong.
      if (autoDetectWroFile) {
        throw e;
      }
      throw new WroRuntimeException("The wroFile doesn't exist. Skip trying with other wro model factories", e);
    }
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
  }

Solution content
      @Override
      public InputStream getInputStream()
        throws IOException {
        try {
          Validate.notNull(wroFile, "Cannot call this method if wroFile is null!");
          if (autoDetectWroFile) {
            final File file = new File(wroFile.getParentFile(), defaultFileName);
            LOG.info("loading autodetected wro file: " + file);
            return new FileInputStream(file);
          }
          LOG.info("loading wroFile: " + wroFile);
          return new FileInputStream(wroFile);
        } catch (final FileNotFoundException e) {
          // When auto detect is turned on, do not skip trying.. because the auto detection assume that the wro file name
          // can be wrong.
          if (autoDetectWroFile) {
            throw e;
          }
          throw new WroRuntimeException("The wroFile doesn't exist. Skip trying with other wro model factories", e);
        }
      }
    };
  }


  /**
   * {@inheritDoc}
   */
  @Override
  public WroModel create() {
    if (factoryList == null) {
      factoryList = newWroModelFactoryFactoryList();
    }
    for (final WroModelFactory factory : factoryList) {
      try {
        final Class factoryClass = factory.getClass().asSubclass(WroModelFactory.class);
        LOG.info("Trying to use {} for model creation", getClassName(factoryClass));
        return factory.create();
      } catch (final WroRuntimeException e) {
        LOG.info("Model creation using {} failed. Trying another ...", getClassName(factory.getClass()));
        LOG.debug("Exception occured while building the model using: " + getClassName(factory.getClass()), e);
        //stop trying with other factories if the reason is IOException
        if (!autoDetectWroFile && e.getCause() instanceof IOException) {
          throw e;
        }
      }
    }
    throw new WroRuntimeException("Cannot create model using any of provided factories");
  }


  /**
   * @return string representation of the factory name.
   */
  protected String getClassName(final Class factoryClass) {
    final String className = factoryClass.isAnonymousClass()
      ? factoryClass.getSuperclass().getSimpleName()
      : factoryClass.getSimpleName();
    return className;
  }


  /**
   * @param factoryList the factoryList to set
   */
  public SmartWroModelFactory setFactoryList(final List factoryList) {
    Validate.notNull(factoryList);
    this.factoryList = factoryList;
    return this;
  }


  /**
   * In order to keep backward compatibility for building the model . The idea is if this field is false, then the exact
   * file will be used to create the model, otherwise, wro model file is autodetected based on the parent folder where
   * the wroFile is located.
   *
   * @param autoDetectWroFile the autoDetectWroFile to set
   */
  public SmartWroModelFactory setAutoDetectWroFile(final boolean autoDetectWroFile) {
    this.autoDetectWroFile = autoDetectWroFile;
    return this;
  }


  /**
   * {@inheritDoc}
   */
  @Override
  protected String getDefaultModelFilename() {
    return DEFAULT_WRO_FILE;
  }


  /**
   * {@inheritDoc}
   */
  @Override
  protected InputStream getModelResourceAsStream()
    throws IOException {
    throw new IllegalStateException("This method should never be called!");
  }
}
File
SmartWroModelFactory.java
Developer's decision
Manual
Kind of conflict
Comment
If statement
Method invocation
Method signature
Return statement
Try statement
Chunk
Conflicting content
      } catch (final WroRuntimeException e) {
        LOG.info("Model creation using {} failed. Trying another ...", getClassName(factory.getClass()));
        LOG.debug("Exception occured while building the model using: " + getClassName(factory.getClass()), e);
<<<<<<< HEAD
=======
        //stop trying with other factories if the reason is IOException
        if (!autoDetectWroFile && e.getCause() instanceof IOException) {
          throw e;
        }
>>>>>>> 545682710625a7fd8135c994c367f3790134d439
      }
    }
    throw new WroRuntimeException("Cannot create model using any of provided factories");
Solution content
      } catch (final WroRuntimeException e) {
        LOG.info("Model creation using {} failed. Trying another ...", getClassName(factory.getClass()));
        LOG.debug("Exception occured while building the model using: " + getClassName(factory.getClass()), e);
        //stop trying with other factories if the reason is IOException
        if (!autoDetectWroFile && e.getCause() instanceof IOException) {
          throw e;
        }
      }
    }
    throw new WroRuntimeException("Cannot create model using any of provided factories");
File
SmartWroModelFactory.java
Developer's decision
Version 2
Kind of conflict
Comment
If statement