// 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/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.PostProcessingException;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;
import org.jsoup.nodes.Element;

/*
 * 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 FieldExtractor extends AbstractContentExtractor {

    public FieldExtractor(Element document, String source) {
        super.document = document;
        super.source = source;
    }

    @Override
    protected List run(List<ScrapableField> fields, FIELD_TYPE type) {
        ArrayList extractedFields = new ArrayList();

        Document temp_company = new Document();
        if (document != null) {
            for (int i = 0; i < fields.size(); i++) {
                try {
                    Document extracted_content = getSelectedElement(fields.get(i), document);

                    if (!extracted_content.getString("name").equals("") && !extracted_content.get("value").toString().equals("") && extracted_content.get("value") != null) {

                        if (type.equals(FIELD_TYPE.COMPANY_INFO)) {
                            temp_company.append(extracted_content.getString("name"), extracted_content.getString("value"));
                        } else {
                            extracted_content.append("source", source);
                            extractedFields.add(extracted_content);
                        }
                    }                    

// 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/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/FieldExtractor.java
import certh.iti.mklab.easie.FIELD_TYPE;
import certh.iti.mklab.easie.configuration.Configuration.ScrapableField;
import certh.iti.mklab.easie.exception.PostProcessingException;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;
import org.jsoup.nodes.Element;

/*
 * 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 FieldExtractor extends AbstractContentExtractor {

    public FieldExtractor(Element document, String source) {
        super.document = document;
        super.source = source;
    }

    @Override
    protected List run(List<ScrapableField> fields, FIELD_TYPE type) {
        ArrayList extractedFields = new ArrayList();

        Document temp_company = new Document();
        if (document != null) {
            for (int i = 0; i < fields.size(); i++) {
                try {
                    Document extracted_content = getSelectedElement(fields.get(i), document);

                    if (!extracted_content.getString("name").equals("") && !extracted_content.get("value").toString().equals("") && extracted_content.get("value") != null) {

                        if (type.equals(FIELD_TYPE.COMPANY_INFO)) {
                            temp_company.append(extracted_content.getString("name"), extracted_content.getString("value"));
                        } else {
                            extracted_content.append("source", source);
                            extractedFields.add(extracted_content);
                        }
                    }                    

                } catch (PostProcessingException ex) {
