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    @Metadata(javaType = "java.lang.Boolean")
043    private String omitXmlDeclaration;
044    @XmlTransient
045    private Class<?> dataObjectType;
046
047    public TidyMarkupDataFormat() {
048        super("tidyMarkup");
049        this.setDataObjectType(Node.class);
050    }
051
052    public TidyMarkupDataFormat(Class<?> dataObjectType) {
053        this();
054        if (!dataObjectType.isAssignableFrom(String.class) && !dataObjectType.isAssignableFrom(Node.class)) {
055            throw new IllegalArgumentException("TidyMarkupDataFormat only supports returning a String or a org.w3c.dom.Node object");
056        }
057        this.setDataObjectType(dataObjectType);
058    }
059
060    /**
061     * What data type to unmarshal as, can either be org.w3c.dom.Node or
062     * java.lang.String.
063     * <p/>
064     * Is by default org.w3c.dom.Node
065     */
066    public void setDataObjectType(Class<?> dataObjectType) {
067        this.dataObjectType = dataObjectType;
068    }
069
070    public Class<?> getDataObjectType() {
071        return dataObjectType;
072    }
073
074    public String getDataObjectTypeName() {
075        return dataObjectTypeName;
076    }
077
078    /**
079     * What data type to unmarshal as, can either be org.w3c.dom.Node or
080     * java.lang.String.
081     * <p/>
082     * Is by default org.w3c.dom.Node
083     */
084    public void setDataObjectTypeName(String dataObjectTypeName) {
085        this.dataObjectTypeName = dataObjectTypeName;
086    }
087
088    public String getOmitXmlDeclaration() {
089        return omitXmlDeclaration;
090    }
091
092    /**
093     * When returning a String, do we omit the XML declaration in the top.
094     */
095    public void setOmitXmlDeclaration(String omitXmlDeclaration) {
096        this.omitXmlDeclaration = omitXmlDeclaration;
097    }
098
099}