001 /* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005 006 package org.util.xml.element; 007 008 /** 009 * 010 * @author masaru 011 */ 012 public class TextElement extends Element { 013 014 private String value_; 015 private boolean is_comment_; 016 private boolean is_cdata_; 017 private boolean is_tag_; 018 019 @Override public boolean isTagElement() { return false; } 020 @Override public boolean isTextElement() { return true; } 021 022 public TextElement(String value) { 023 setValue(value); 024 } 025 026 public boolean isCommentTag() { 027 return is_comment_; 028 } 029 public void setCommenTag(boolean is_comment) { 030 is_comment_ = is_comment; 031 is_cdata_ = false; 032 if(is_comment) is_tag_ = true; 033 } 034 035 public boolean isCDATATag() { 036 return is_cdata_; 037 } 038 public void setCDATATag(boolean is_cdata) { 039 is_cdata_ = is_cdata; 040 is_comment_ = !is_cdata; 041 if(is_cdata) is_tag_ = true; 042 } 043 044 public boolean isTag() { 045 return is_tag_; 046 } 047 public void setTag(boolean is_tag) { 048 is_tag_ = is_tag; 049 if(!is_tag) { 050 is_cdata_ = false; 051 is_comment_ = false; 052 } 053 } 054 055 public void setValue(String value) { 056 value_ = value; 057 } 058 public String getValue() { 059 return value_; 060 } 061 062 public String toString() { 063 if(is_cdata_) 064 return "<![CDATA["+getValue()+"]]>\n"; 065 else if(is_comment_) 066 return "<!--"+getValue()+"-->\n"; 067 else if(is_tag_) 068 return "<!"+getValue()+">\n"; 069 else 070 return getValue(); 071 } 072 }