} if (textContent.endsWith("]")) { textContent = textContent.substring(0, textContent.length() - 1);
if (textContent.endsWith("]")) { textContent = textContent.substring(0, textContent.length() - 1); }
   public static String getTextContent(Node n) throws XMLException   {      if (n.hasChildNodes())      {         StringBuffer sb = new StringBuffer();         NodeList nl = n.getChildNodes();         for(int i = 0; i < nl.getLength(); i++)         {            sb.append(XMLUtil.elementToString(nl.item(i)));            if (i < nl.getLength() - 1)            {               sb.append('\n');            }         }         String s = sb.toString();         if (s.length() != 0)         {            return s;         }      }      Method[] methods = Node.class.getMethods();      for(int i = 0; i < methods.length; i++)      {         if("getTextContent".equals(methods[i].getName()))         {            Method getTextContext = methods[i];            try            {               return (String)getTextContext.invoke(n, EMPTY_ARRAY);            }            catch(Exception e)            {               log.error("Failed to invoke getTextContent() on node " + n, e);               return null;            }         }      }      String textContent = null;      if (n.hasChildNodes())      {         NodeList nl = n.getChildNodes();         for(int i = 0; i < nl.getLength(); i++)         {            Node c = nl.item(i);            if (c.getNodeType() == Node.TEXT_NODE)            {               textContent = n.getNodeValue();               if (textContent == null)               {                  // TODO This is a hack. Get rid of it and implement this properly                  String s = c.toString();                  int idx = s.indexOf("#text:");                  if (idx != -1)                  {                     textContent = s.substring(idx + 6).trim();                  }                  if (textContent.endsWith("]"))                  {                     textContent = textContent.substring(0, textContent.length() - 1);                  }               }               if (textContent == null)               {                 break;               }            }         }         // TODO This is a hack. Get rid of it and implement this properly         String s = n.toString();         int i = s.indexOf('>');         int i2 = s.indexOf("</");         if (i != -1 && i2 != -1)         {            textContent = s.substring(i + 1, i2);         }      }      return textContent;   }