// Path: src/main/java/certh/iti/mklab/easie/FIELD_TYPE.java
// public enum FIELD_TYPE {
//     METRIC,
//     COMPANY_INFO
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class ScrapableField {
// 
//     public Object label;
// 
//     public Object value;
// 
//     public Object citeyear;
// 
//     public void setLabel(ExtractionProperties ep) {
//         label = ep;
//     }
// 
//     public void setValue(ExtractionProperties ep) {
//         value = ep;
//     }
// 
//     public void setCiteyear(ExtractionProperties ep) {
//         citeyear = ep;
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/exception/HTMLElementNotFoundException.java
// public class HTMLElementNotFoundException extends Exception {
// 
//     public HTMLElementNotFoundException() {
//     }
// 
//     public HTMLElementNotFoundException(String message) {
//         super(message);
//     }
// 
//     public HTMLElementNotFoundException(Throwable cause) {
//         super(cause);
//     }
// 
//     public HTMLElementNotFoundException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/exception/PostProcessingException.java
// public class PostProcessingException extends Exception {
//    public PostProcessingException(){
//       
//    }
//    
//    public PostProcessingException(String message){
//       super(message);
//    }
//    
//    public PostProcessingException(Throwable cause){
//       super(cause);
//    }
//    
//    public PostProcessingException(String message, Throwable cause){
//       super(message, cause);
//    }
// }


import certh.iti.mklab.easie.FIELD_TYPE;
import certh.iti.mklab.easie.configuration.Configuration.ScrapableField;
import certh.iti.mklab.easie.exception.HTMLElementNotFoundException;
import certh.iti.mklab.easie.exception.PostProcessingException;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/*
 * Copyright 2016 vasgat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package certh.iti.mklab.easie.extractors;


/**
 *
 * @author vasgat
 */
public class TableFieldExtractor extends AbstractContentExtractor {

    private String table_selector;

    public TableFieldExtractor(Element document, String table_selector, String source) {
        super.document = document;
        this.table_selector = table_selector;
        super.source = source;
    }

    @Override
    public List run(List<ScrapableField> fields, FIELD_TYPE type) throws HTMLElementNotFoundException {
        ArrayList extractedContent = new ArrayList();
        if (document != null) {
            Elements table = document.select(table_selector);

            if (table.size() == 0) {
                throw new HTMLElementNotFoundException("WARNING: The defined table element was not found. Check the correctness of your table selector |" + table_selector + "| or for possible changes in the structure of your source.");
            }

            for (int i = 0; i < table.size(); i++) {
                try {
                    ArrayList temp = new ArrayList();
                    if (type.equals(type.COMPANY_INFO)) {
                        extractedContent.add(extractTableFields(fields, table.get(i), type));
                    } else {
                        temp.addAll((List) extractTableFields(fields, table.get(i), type));
                        extractedContent.add(temp);
                    }


// Path: src/main/java/certh/iti/mklab/easie/FIELD_TYPE.java
// public enum FIELD_TYPE {
//     METRIC,
//     COMPANY_INFO
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class ScrapableField {
// 
//     public Object label;
// 
//     public Object value;
// 
//     public Object citeyear;
// 
//     public void setLabel(ExtractionProperties ep) {
//         label = ep;
//     }
// 
//     public void setValue(ExtractionProperties ep) {
//         value = ep;
//     }
// 
//     public void setCiteyear(ExtractionProperties ep) {
//         citeyear = ep;
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/exception/HTMLElementNotFoundException.java
// public class HTMLElementNotFoundException extends Exception {
// 
//     public HTMLElementNotFoundException() {
//     }
// 
//     public HTMLElementNotFoundException(String message) {
//         super(message);
//     }
// 
//     public HTMLElementNotFoundException(Throwable cause) {
//         super(cause);
//     }
// 
//     public HTMLElementNotFoundException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/exception/PostProcessingException.java
// public class PostProcessingException extends Exception {
//    public PostProcessingException(){
//       
//    }
//    
//    public PostProcessingException(String message){
//       super(message);
//    }
//    
//    public PostProcessingException(Throwable cause){
//       super(cause);
//    }
//    
//    public PostProcessingException(String message, Throwable cause){
//       super(message, cause);
//    }
// }


// Path: src/main/java/certh/iti/mklab/easie/extractors/TableFieldExtractor.java
import certh.iti.mklab.easie.FIELD_TYPE;
import certh.iti.mklab.easie.configuration.Configuration.ScrapableField;
import certh.iti.mklab.easie.exception.HTMLElementNotFoundException;
import certh.iti.mklab.easie.exception.PostProcessingException;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/*
 * Copyright 2016 vasgat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package certh.iti.mklab.easie.extractors;


/**
 *
 * @author vasgat
 */
public class TableFieldExtractor extends AbstractContentExtractor {

    private String table_selector;

    public TableFieldExtractor(Element document, String table_selector, String source) {
        super.document = document;
        this.table_selector = table_selector;
        super.source = source;
    }

    @Override
    public List run(List<ScrapableField> fields, FIELD_TYPE type) throws HTMLElementNotFoundException {
        ArrayList extractedContent = new ArrayList();
        if (document != null) {
            Elements table = document.select(table_selector);

            if (table.size() == 0) {
                throw new HTMLElementNotFoundException("WARNING: The defined table element was not found. Check the correctness of your table selector |" + table_selector + "| or for possible changes in the structure of your source.");
            }

            for (int i = 0; i < table.size(); i++) {
                try {
                    ArrayList temp = new ArrayList();
                    if (type.equals(type.COMPANY_INFO)) {
                        extractedContent.add(extractTableFields(fields, table.get(i), type));
                    } else {
                        temp.addAll((List) extractTableFields(fields, table.get(i), type));
                        extractedContent.add(temp);
                    }


                } catch (PostProcessingException ex) {
