Ejemplo n.º 1
0
  /**
   * Before this call m_elementContext.m_elementURI is null, which means it is not yet known. After
   * this call it is non-null, but possibly "" meaning that it is in the default namespace.
   *
   * @return The URI of the element, never null, but possibly "".
   */
  private String getElementURI() {
    String uri = null;
    // At this point in processing we have received all the
    // namespace mappings
    // As we still don't know the elements namespace,
    // we now figure it out.

    String prefix = getPrefixPart(m_elemContext.m_elementName);

    if (prefix == null) {
      // no prefix so lookup the URI of the default namespace
      uri = m_prefixMap.lookupNamespace("");
    } else {
      uri = m_prefixMap.lookupNamespace(prefix);
    }
    if (uri == null) {
      // We didn't find the namespace for the
      // prefix ... ouch, that shouldn't happen.
      // This is a hack, we really don't know
      // the namespace
      uri = EMPTYSTRING;
    }

    return uri;
  }
Ejemplo n.º 2
0
  /**
   * Push a boolean state based on if the name of the current element is found in the list of
   * qnames. A state is only pushed if there were some cdata-section-names were specified.
   *
   * <p>Hidden parameters are the vector of qualified elements specified in cdata-section-names
   * attribute, and the m_cdataSectionStates stack onto which whether the current element is in the
   * list is pushed (true or false). Other hidden parameters are the current elements namespaceURI,
   * localName and qName
   */
  protected boolean isCdataSection() {

    boolean b = false;

    if (null != m_cdataSectionElements) {
      if (m_elemContext.m_elementLocalName == null)
        m_elemContext.m_elementLocalName = getLocalName(m_elemContext.m_elementName);
      if (m_elemContext.m_elementURI == null) {
        String prefix = getPrefixPart(m_elemContext.m_elementName);
        if (prefix != null) m_elemContext.m_elementURI = m_prefixMap.lookupNamespace(prefix);
      }

      if ((null != m_elemContext.m_elementURI) && m_elemContext.m_elementURI.length() == 0)
        m_elemContext.m_elementURI = null;

      int nElems = m_cdataSectionElements.size();

      // loop through 2 at a time, as these are pairs of URI and localName
      for (int i = 0; i < nElems; i += 2) {
        String uri = (String) m_cdataSectionElements.elementAt(i);
        String loc = (String) m_cdataSectionElements.elementAt(i + 1);
        if (loc.equals(m_elemContext.m_elementLocalName)
            && subPartMatch(m_elemContext.m_elementURI, uri)) {
          b = true;

          break;
        }
      }
    }
    return b;
  }
Ejemplo n.º 3
0
  /**
   * Returns the URI of an element or attribute. Note that default namespaces do not apply directly
   * to attributes.
   *
   * @param qname a qualified name
   * @param isElement true if the qualified name is the name of an element.
   * @return returns the namespace URI associated with the qualified name.
   */
  public String getNamespaceURI(String qname, boolean isElement) {
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement) {
      if (m_prefixMap != null) {
        uri = m_prefixMap.lookupNamespace(prefix);
        if (uri == null && !prefix.equals(XMLNS_PREFIX)) {
          throw new RuntimeException(
              Utils.messages.createMessage(
                  MsgKey.ER_NAMESPACE_PREFIX, new Object[] {qname.substring(0, col)}));
        }
      }
    }
    return uri;
  }
Ejemplo n.º 4
0
  /**
   * If at runtime, when the qname of the attribute is known, another prefix is specified for the
   * attribute, then we can patch or hack the name with this method. For a qname of the form
   * "ns?:otherprefix:name", this function patches the qname by simply ignoring "otherprefix". TODO:
   * This method is a HACK! We do not have access to the XML file, it sometimes generates a NS
   * prefix of the form "ns?" for an attribute.
   */
  protected String patchName(String qname) {

    final int lastColon = qname.lastIndexOf(':');

    if (lastColon > 0) {
      final int firstColon = qname.indexOf(':');
      final String prefix = qname.substring(0, firstColon);
      final String localName = qname.substring(lastColon + 1);

      // If uri is "" then ignore prefix
      final String uri = m_prefixMap.lookupNamespace(prefix);
      if (uri != null && uri.length() == 0) {
        return localName;
      } else if (firstColon != lastColon) {
        return prefix + ':' + localName;
      }
    }
    return qname;
  }
Ejemplo n.º 5
0
 /**
  * Returns the URI of prefix (if any)
  *
  * @param prefix the prefix whose URI is searched for
  * @return the namespace URI currently associated with the prefix, null if the prefix is
  *     undefined.
  */
 public String getNamespaceURIFromPrefix(String prefix) {
   String uri = null;
   if (m_prefixMap != null) uri = m_prefixMap.lookupNamespace(prefix);
   return uri;
 }
Ejemplo n.º 6
0
 /**
  * Returns the prefix currently pointing to the given URI (if any).
  *
  * @param namespaceURI the uri of the namespace in question
  * @return a prefix pointing to the given URI (if any).
  * @see ExtendedContentHandler#getPrefix(String)
  */
 public String getPrefix(String namespaceURI) {
   String prefix = m_prefixMap.lookupPrefix(namespaceURI);
   return prefix;
 }