<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

package pt.webdetails.cpf;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.platform.api.engine.IParameterProvider;
import org.pentaho.platform.api.repository.IContentItem;
import org.pentaho.platform.engine.services.solution.BaseContentGenerator;
import pt.webdetails.cpf.annotations.AccessLevel;
import pt.webdetails.cpf.annotations.Exposed;

/**
 *
 * @author pdpi
 */
public class SimpleContentGenerator extends BaseContentGenerator {


  private static final long serialVersionUID = 1L;
    Log logger = LogFactory.getLog(this.getClass());

    @Override
    public void createContent() {
        IParameterProvider pathParams = parameterProviders.get("path");
                //requestParams = parameterProviders.get("request");
        final IContentItem contentItem = outputHandler.getOutputContentItem("response", "content", "", instanceId, "text/html");

        try {
            final OutputStream out = contentItem.getOutputStream(null);
            final Class<?>[] params = {OutputStream.class};

            String[] pathSections = StringUtils.split(pathParams.getStringParameter("path", null),"/");
            
            if(pathSections != null && pathSections.length > 1){
              
              final String method = StringUtils.lowerCase(pathSections[1]);
  
              try {
                  final Method mthd = this.getClass().getMethod(method, params);
                  boolean exposed = mthd.isAnnotationPresent(Exposed.class);
                  boolean accessible = exposed && mthd.getAnnotation(Exposed.class).accessLevel() == AccessLevel.PUBLIC;
                  if (accessible) {
                      mthd.invoke(this, out);
                  } else {
                      throw new IllegalAccessException("Method " + method + " has the wrong access level");
                  }
              } catch (NoSuchMethodException e) {
                  logger.warn("could't locate method: " + method);
              } catch (InvocationTargetException e) {
                  logger.error(e.toString());
  
              } catch (IllegalAccessException e) {
                  logger.warn(e.toString());
  
              } catch (IllegalArgumentException e) {
  
                  logger.error(e.toString());
              }
            }<commit_msg>SimpleContentGenerator correct change for split<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

package pt.webdetails.cpf;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.platform.api.engine.IParameterProvider;
import org.pentaho.platform.api.repository.IContentItem;
import org.pentaho.platform.engine.services.solution.BaseContentGenerator;
import pt.webdetails.cpf.annotations.AccessLevel;
import pt.webdetails.cpf.annotations.Exposed;

/**
 *
 * @author pdpi
 */
public class SimpleContentGenerator extends BaseContentGenerator {


  private static final long serialVersionUID = 1L;
    Log logger = LogFactory.getLog(this.getClass());

    @Override
    public void createContent() {
        IParameterProvider pathParams = parameterProviders.get("path");
                //requestParams = parameterProviders.get("request");
        final IContentItem contentItem = outputHandler.getOutputContentItem("response", "content", "", instanceId, "text/html");

        try {
            final OutputStream out = contentItem.getOutputStream(null);
            final Class<?>[] params = {OutputStream.class};

            String[] pathSections = StringUtils.split(pathParams.getStringParameter("path", null),"/");
            
            if(pathSections != null && pathSections.length > 0){
              
              final String method = StringUtils.lowerCase(pathSections[0]);
  
              try {
                  final Method mthd = this.getClass().getMethod(method, params);
                  boolean exposed = mthd.isAnnotationPresent(Exposed.class);
                  boolean accessible = exposed && mthd.getAnnotation(Exposed.class).accessLevel() == AccessLevel.PUBLIC;
                  if (accessible) {
                      mthd.invoke(this, out);
                  } else {
                      throw new IllegalAccessException("Method " + method + " has the wrong access level");
                  }
              } catch (NoSuchMethodException e) {
                  logger.warn("could't locate method: " + method);
              } catch (InvocationTargetException e) {
                  logger.error(e.toString());
  
              } catch (IllegalAccessException e) {
                  logger.warn(e.toString());
  
              } catch (IllegalArgumentException e) {
  
                  logger.error(e.toString());
              }
            }
{'fraction_non_alphanumeric': 0.10408384531984098, 'fraction_numerical': 0.002529815684857246, 'mean_word_length': 2.4789440603394093, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5557012', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1385, 'n_words': 326}