001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import java.util.ArrayList; 020import java.util.HashMap; 021import java.util.List; 022import java.util.Map; 023 024import javax.xml.bind.annotation.XmlAccessType; 025import javax.xml.bind.annotation.XmlAccessorType; 026import javax.xml.bind.annotation.XmlAttribute; 027import javax.xml.bind.annotation.XmlElement; 028import javax.xml.bind.annotation.XmlRootElement; 029import javax.xml.bind.annotation.XmlTransient; 030 031import org.apache.camel.model.DataFormatDefinition; 032import org.apache.camel.model.PropertyDefinition; 033import org.apache.camel.spi.Metadata; 034 035/** 036 * Extract RDF data from HTML documents. 037 */ 038@Metadata(firstVersion = "3.0.0", label = "dataformat,transformation", title = "Any23") 039@XmlRootElement(name = "any23") 040@XmlAccessorType(XmlAccessType.FIELD) 041public class Any23DataFormat extends DataFormatDefinition { 042 043 @XmlAttribute 044 @Metadata(defaultValue = "RDF4JMODEL", enums = "NTRIPLES,TURTLE,NQUADS,RDFXML,JSONLD,RDFJSON,RDF4JMODEL", 045 javaType = "org.apache.camel.dataformat.any23.Any23OutputFormat") 046 private String outputFormat; 047 @XmlElement(name = "configuration") 048 private List<PropertyDefinition> configuration; 049 @XmlTransient 050 private Map<String, String> configurations; 051 @XmlElement 052 private List<String> extractors; 053 @XmlAttribute 054 private String baseURI; 055 056 public Any23DataFormat() { 057 super("any23"); 058 } 059 060 public Any23DataFormat(String baseuri) { 061 this(); 062 this.baseURI = baseuri; 063 } 064 065 public Any23DataFormat(String baseuri, Any23Type outputFormat) { 066 this(baseuri); 067 this.outputFormat = outputFormat.name(); 068 } 069 070 public Any23DataFormat(String baseuri, Any23Type outputFormat, Map<String, String> configurations) { 071 this(baseuri, outputFormat); 072 this.outputFormat = outputFormat.name(); 073 this.configurations = configurations; 074 } 075 076 public Any23DataFormat(String baseuri, Any23Type outputFormat, Map<String, String> configurations, List<String> extractors) { 077 this(baseuri, outputFormat, configurations); 078 this.outputFormat = outputFormat.name(); 079 this.configurations = configurations; 080 this.extractors = extractors; 081 } 082 083 public String getOutputFormat() { 084 return outputFormat; 085 } 086 087 /** 088 * What RDF syntax to unmarshal as, can be: NTRIPLES, TURTLE, NQUADS, 089 * RDFXML, JSONLD, RDFJSON, RDF4JMODEL. It is by default: RDF4JMODEL. 090 */ 091 public void setOutputFormat(String outputFormat) { 092 this.outputFormat = outputFormat; 093 } 094 095 public Map<String, String> getConfigurationAsMap() { 096 if (configurations == null && configuration != null) { 097 configurations = new HashMap<>(); 098 } 099 if (configuration != null) { 100 for (PropertyDefinition def : configuration) { 101 configurations.put(def.getKey(), def.getValue()); 102 } 103 } 104 return configurations; 105 } 106 107 public List<PropertyDefinition> getConfiguration() { 108 return configuration; 109 } 110 111 /** 112 * Configurations for Apache Any23 as key-value pairs in order to customize 113 * the extraction process. The list of supported parameters can be found 114 * <a href= 115 * "https://github.com/apache/any23/blob/master/api/src/main/resources/default-configuration.properties">here</a>. 116 * If not provided, a default configuration is used. 117 */ 118 public void setConfiguration(List<PropertyDefinition> configuration) { 119 this.configuration = configuration; 120 } 121 122 /** 123 * Configurations for Apache Any23 as key-value pairs in order to customize 124 * the extraction process. The list of supported parameters can be found 125 * <a href= 126 * "https://github.com/apache/any23/blob/master/api/src/main/resources/default-configuration.properties">here</a>. 127 * If not provided, a default configuration is used. 128 */ 129 public void setConfiguration(Map<String, String> configuration) { 130 this.configuration = new ArrayList<>(); 131 configuration.forEach((k, v) -> this.configuration.add(new PropertyDefinition(k, v))); 132 } 133 134 public List<String> getExtractors() { 135 return extractors; 136 } 137 138 /** 139 * List of Any23 extractors to be used in the unmarshal operation. A list of 140 * the available extractors can be found here 141 * <a href="https://any23.apache.org/getting-started.html">here</a>. If not 142 * provided, all the available extractors are used. 143 */ 144 public void setExtractors(List<String> extractors) { 145 this.extractors = extractors; 146 } 147 148 public String getBaseURI() { 149 return baseURI; 150 } 151 152 /** 153 * The URI to use as base for building RDF entities if only relative paths 154 * are provided. 155 */ 156 public void setBaseURI(String baseURI) { 157 this.baseURI = baseURI; 158 } 159 160}