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 javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.w3c.dom.Node; 026 027import org.apache.camel.model.DataFormatDefinition; 028import org.apache.camel.spi.Metadata; 029 030/** 031 * TidyMarkup data format is used for parsing HTML and return it as pretty 032 * well-formed HTML. 033 */ 034@Metadata(firstVersion = "2.0.0", label = "dataformat,transformation", title = "TidyMarkup") 035@XmlRootElement(name = "tidyMarkup") 036@XmlAccessorType(XmlAccessType.FIELD) 037public class TidyMarkupDataFormat extends DataFormatDefinition { 038 @XmlAttribute(name = "dataObjectType") 039 @Metadata(defaultValue = "org.w3c.dom.Node") 040 private String dataObjectTypeName; 041 @XmlAttribute 042 private Boolean omitXmlDeclaration; 043 @XmlTransient 044 private Class<?> dataObjectType; 045 046 public TidyMarkupDataFormat() { 047 super("tidyMarkup"); 048 this.setDataObjectType(Node.class); 049 } 050 051 public TidyMarkupDataFormat(Class<?> dataObjectType) { 052 this(); 053 if (!dataObjectType.isAssignableFrom(String.class) && !dataObjectType.isAssignableFrom(Node.class)) { 054 throw new IllegalArgumentException("TidyMarkupDataFormat only supports returning a String or a org.w3c.dom.Node object"); 055 } 056 this.setDataObjectType(dataObjectType); 057 } 058 059 /** 060 * What data type to unmarshal as, can either be org.w3c.dom.Node or 061 * java.lang.String. 062 * <p/> 063 * Is by default org.w3c.dom.Node 064 */ 065 public void setDataObjectType(Class<?> dataObjectType) { 066 this.dataObjectType = dataObjectType; 067 } 068 069 public Class<?> getDataObjectType() { 070 return dataObjectType; 071 } 072 073 public String getDataObjectTypeName() { 074 return dataObjectTypeName; 075 } 076 077 /** 078 * What data type to unmarshal as, can either be org.w3c.dom.Node or 079 * java.lang.String. 080 * <p/> 081 * Is by default org.w3c.dom.Node 082 */ 083 public void setDataObjectTypeName(String dataObjectTypeName) { 084 this.dataObjectTypeName = dataObjectTypeName; 085 } 086 087 public Boolean getOmitXmlDeclaration() { 088 return omitXmlDeclaration; 089 } 090 091 /** 092 * When returning a String, do we omit the XML declaration in the top. 093 */ 094 public void setOmitXmlDeclaration(Boolean omitXmlDeclaration) { 095 this.omitXmlDeclaration = omitXmlDeclaration; 096 } 097 098}