1 28 29 package org.jibx.extras; 30 31 import org.jibx.runtime.IXMLWriter; 32 import org.jibx.runtime.JiBXException; 33 import org.jibx.runtime.impl.UnmarshallingContext; 34 35 43 44 public class DocumentModelMapperBase 45 { 46 47 public static final String XML_NAMESPACE = 48 "http://www.w3.org/XML/1998/namespace"; 49 50 51 public static final String XMLNS_NAMESPACE = 52 "http://www.w3.org/2000/xmlns/"; 53 54 55 protected IXMLWriter m_xmlWriter; 56 57 58 protected UnmarshallingContext m_unmarshalContext; 59 60 66 67 protected String getNamespaceUri(int index) { 68 String [] uris = m_xmlWriter.getNamespaces(); 69 if (index < uris.length) { 70 return uris[index]; 71 } else { 72 index -= uris.length; 73 String [][] uriss = m_xmlWriter.getExtensionNamespaces(); 74 if (uriss != null) { 75 for (int i = 0; i < uriss.length; i++) { 76 uris = uriss[i]; 77 if (index < uris.length) { 78 return uris[index]; 79 } else { 80 index -= uris.length; 81 } 82 } 83 } 84 } 85 return null; 86 } 87 88 93 94 protected int getNextNamespaceIndex() { 95 int count = m_xmlWriter.getNamespaces().length; 96 String [][] uriss = m_xmlWriter.getExtensionNamespaces(); 97 if (uriss != null) { 98 for (int i = 0; i < uriss.length; i++) { 99 count += uriss[i].length; 100 } 101 } 102 return count; 103 } 104 105 112 113 protected String accumulateText() throws JiBXException { 114 String text = m_unmarshalContext.getText(); 115 StringBuffer buff = null; 116 while (true) { 117 int cev = m_unmarshalContext.nextToken(); 118 if (cev == UnmarshallingContext.TEXT || 119 (cev == UnmarshallingContext.ENTITY_REF && 120 m_unmarshalContext.getText() != null)) { 121 if (buff == null) { 122 buff = new StringBuffer (text); 123 } 124 buff.append(m_unmarshalContext.getText()); 125 } else { 126 break; 127 } 128 } 129 if (buff == null) { 130 return text; 131 } else { 132 return buff.toString(); 133 } 134 } 135 136 142 143 protected boolean isWhitespace(char chr) { 144 if (chr <= 0x20) { 145 return chr == 0x20 || chr == 0x09 || chr == 0x0A || chr == 0x0D; 146 } else { 147 return false; 148 } 149 } 150 } | Popular Tags |