001package com.hfg.xml; 002 003 004//------------------------------------------------------------------------------ 005/** 006 XMLName is a container for XML tag names that consists of a namespace and a local name. 007 008 @author J. Alex Taylor, hairyfatguy.com 009 */ 010//------------------------------------------------------------------------------ 011// com.hfg XML/HTML Coding Library 012// 013// This library is free software; you can redistribute it and/or 014// modify it under the terms of the GNU Lesser General Public 015// License as published by the Free Software Foundation; either 016// version 2.1 of the License, or (at your option) any later version. 017// 018// This library is distributed in the hope that it will be useful, 019// but WITHOUT ANY WARRANTY; without even the implied warranty of 020// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 021// Lesser General Public License for more details. 022// 023// You should have received a copy of the GNU Lesser General Public 024// License along with this library; if not, write to the Free Software 025// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026// 027// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 028// jataylor@hairyfatguy.com 029//------------------------------------------------------------------------------ 030 031 032public class XMLName 033{ 034 //########################################################################### 035 // PRIVATE FIELDS 036 //########################################################################### 037 038 private String mLocalName; 039 private XMLNamespace mNamespace; 040 041 //########################################################################### 042 // CONSTRUCTORS 043 //########################################################################### 044 045 //--------------------------------------------------------------------------- 046 public XMLName(String inName) 047 { 048 this(inName, null); 049 } 050 051 //--------------------------------------------------------------------------- 052 public XMLName(String inName, XMLNamespace inNamespace) 053 { 054 if (null == inNamespace 055 && inName.contains(":")) 056 { 057 int index = inName.indexOf(":"); 058 mLocalName = inName.substring(index + 1); 059 mNamespace = XMLNamespace.getNamespaceViaPrefix(inName.substring(0, index)); 060 } 061 else 062 { 063 mLocalName = inName; 064 mNamespace = inNamespace; 065 } 066 } 067 068 069 //########################################################################### 070 // PUBLIC METHODS 071 //########################################################################### 072 073 074 //--------------------------------------------------------------------------- 075 @Override 076 public String toString() 077 { 078 return getQualifiedName(); 079 } 080 081 //--------------------------------------------------------------------------- 082 public String getLocalName() 083 { 084 return mLocalName; 085 } 086 087 //--------------------------------------------------------------------------- 088 public String getQualifiedName() 089 { 090 return (mNamespace != null && mNamespace.getPrefix() != null ? mNamespace.getPrefix() + ":" : "") + mLocalName; 091 } 092 093 //--------------------------------------------------------------------------- 094 public XMLNamespace getNamespace() 095 { 096 return mNamespace; 097 } 098 099 //--------------------------------------------------------------------------- 100 public XMLName setNamespace(XMLNamespace inValue) 101 { 102 mNamespace = inValue; 103 return this; 104 } 105}