Exemplo n.º 1
0
  public static void fixNamespaceForXsiType(final XmlObject object, final QName value) {
    final XmlCursor cursor = object.newCursor();
    while (cursor.hasNextToken()) {
      if (cursor.toNextToken().isStart()) {
        final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE);
        if (xsiType != null) {

          final String[] toks = xsiType.split(":");
          String localName;
          String prefix;
          if (toks.length > 1) {
            prefix = toks[0];
            localName = toks[1];
          } else {
            localName = toks[0];
          }
          if (localName.equals(value.getLocalPart())) {
            cursor.setAttributeText(
                W3CConstants.QN_XSI_TYPE,
                Joiner.on(Constants.COLON_CHAR)
                    .join(
                        XmlHelper.getPrefixForNamespace(object, value.getNamespaceURI()),
                        value.getLocalPart()));
          }
        }
      }
    }
    cursor.dispose();
  }
Exemplo n.º 2
0
 public static void fixNamespaceForXsiType(XmlObject content, Map<?, ?> namespaces) {
   final XmlCursor cursor = content.newCursor();
   while (cursor.hasNextToken()) {
     if (cursor.toNextToken().isStart()) {
       final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE);
       if (xsiType != null) {
         final String[] toks = xsiType.split(":");
         if (toks.length > 1) {
           String prefix = toks[0];
           String localName = toks[1];
           String namespace = (String) namespaces.get(prefix);
           if (Strings.isNullOrEmpty(namespace)) {
             namespace = CodingRepository.getInstance().getNamespaceFor(prefix);
           }
           if (StringHelper.isNotEmpty(namespace)) {
             cursor.setAttributeText(
                 W3CConstants.QN_XSI_TYPE,
                 Joiner.on(Constants.COLON_CHAR)
                     .join(
                         XmlHelper.getPrefixForNamespace(content, (String) namespaces.get(prefix)),
                         localName));
           }
         }
       }
     }
   }
   cursor.dispose();
 }
Exemplo n.º 3
0
 /**
  * Remove namespace declarations from an xml fragment (useful for moving all declarations to a
  * document root
  *
  * @param x The fragment to localize
  */
 public static void removeNamespaces(final XmlObject x) {
   final XmlCursor c = x.newCursor();
   while (c.hasNextToken()) {
     if (c.isNamespace()) {
       c.removeXml();
     } else {
       c.toNextToken();
     }
   }
   c.dispose();
 }