コード例 #1
0
  /** Register a namespace prefix */
  private java.lang.String registerPrefix(
      javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
      throws javax.xml.stream.XMLStreamException {
    java.lang.String prefix = xmlWriter.getPrefix(namespace);

    if (prefix == null) {
      prefix = generatePrefix(namespace);

      javax.xml.namespace.NamespaceContext nsContext = xmlWriter.getNamespaceContext();

      while (true) {
        java.lang.String uri = nsContext.getNamespaceURI(prefix);

        if ((uri == null) || (uri.length() == 0)) {
          break;
        }

        prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
      }

      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
コード例 #2
0
  /** method to handle Qnames */
  private void writeQName(
      javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter)
      throws javax.xml.stream.XMLStreamException {
    java.lang.String namespaceURI = qname.getNamespaceURI();
    if (namespaceURI != null) {
      java.lang.String prefix = xmlWriter.getPrefix(namespaceURI);
      if (prefix == null) {
        prefix = generatePrefix(namespaceURI);
        xmlWriter.writeNamespace(prefix, namespaceURI);
        xmlWriter.setPrefix(prefix, namespaceURI);
      }

      if (prefix.trim().length() > 0) {
        xmlWriter.writeCharacters(
            prefix + ":" + org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
      } else {
        // i.e this is the default namespace
        xmlWriter.writeCharacters(
            org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
      }

    } else {
      xmlWriter.writeCharacters(
          org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
    }
  }
コード例 #3
0
ファイル: Integer.java プロジェクト: isuruw/wso2-axis2
  public void serialize(
      final javax.xml.namespace.QName parentQName, XMLStreamWriter xmlWriter, boolean serializeType)
      throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException {

    java.lang.String prefix = null;
    java.lang.String namespace = null;

    prefix = parentQName.getPrefix();
    namespace = parentQName.getNamespaceURI();

    if ((namespace != null) && (namespace.trim().length() > 0)) {
      java.lang.String writerPrefix = xmlWriter.getPrefix(namespace);
      if (writerPrefix != null) {
        xmlWriter.writeStartElement(namespace, parentQName.getLocalPart());
      } else {
        if (prefix == null) {
          prefix = generatePrefix(namespace);
        }

        xmlWriter.writeStartElement(prefix, parentQName.getLocalPart(), namespace);
        xmlWriter.writeNamespace(prefix, namespace);
        xmlWriter.setPrefix(prefix, namespace);
      }
    } else {
      xmlWriter.writeStartElement(parentQName.getLocalPart());
    }

    if (serializeType) {

      java.lang.String namespacePrefix =
          registerPrefix(xmlWriter, "http://www.w3.org/2001/XMLSchema");
      if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)) {
        writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            namespacePrefix + ":integer",
            xmlWriter);
      } else {
        writeAttribute(
            "xsi", "http://www.w3.org/2001/XMLSchema-instance", "type", "integer", xmlWriter);
      }
    }

    if (localInteger == null) {
      // write the nil attribute

      throw new org.apache.axis2.databinding.ADBException("integer cannot be null!!");

    } else {

      xmlWriter.writeCharacters(
          org.apache.axis2.databinding.utils.ConverterUtil.convertToString(localInteger));
    }

    xmlWriter.writeEndElement();
  }
コード例 #4
0
  public void serialize(XMLStreamWriter writer) throws XMLStreamException {

    String localName = getName().getLocalPart();
    String namespaceURI = getName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
      prefix = getName().getPrefix();
      writer.setPrefix(prefix, namespaceURI);
    }

    writer.writeStartElement(prefix, localName, namespaceURI);
    writer.writeNamespace(prefix, namespaceURI);

    // <wsp:Policy>
    writer.writeStartElement(
        SPConstants.POLICY.getPrefix(),
        SPConstants.POLICY.getLocalPart(),
        SPConstants.POLICY.getNamespaceURI());

    //
    writer.writeStartElement(prefix, getAlgoSuiteString(), namespaceURI);
    writer.writeEndElement();

    if (SPConstants.C14N.equals(getInclusiveC14n())) {
      writer.writeStartElement(prefix, SPConstants.INCLUSIVE_C14N, namespaceURI);
      writer.writeEndElement();
    }

    if (SPConstants.SNT.equals(getSoapNormalization())) {
      writer.writeStartElement(prefix, SPConstants.SOAP_NORMALIZATION_10, namespaceURI);
      writer.writeEndElement();
    }

    if (SPConstants.STRT10.equals(getStrTransform())) {
      writer.writeStartElement(prefix, SPConstants.STR_TRANSFORM_10, namespaceURI);
      writer.writeEndElement();
    }

    if (SPConstants.XPATH.equals(getXPath())) {
      writer.writeStartElement(prefix, SPConstants.XPATH10, namespaceURI);
      writer.writeEndElement();
    }

    if (SPConstants.XPATH20.equals(getXPath())) {
      writer.writeStartElement(prefix, SPConstants.XPATH_FILTER20, namespaceURI);
      writer.writeEndElement();
    }

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:AlgorithmSuite>
    writer.writeEndElement();
  }
コード例 #5
0
  public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getUserNameToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
      prefix = name.getPrefix();
      writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KeyValueToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
      writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (forceRsaKeyValue) {
      String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
      if (pPrefix == null) {
        writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
      }

      // <wsp:Policy>
      writer.writeStartElement(
          pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());

      writer.writeEmptyElement(prefix, "RsaKeyValue", namespaceURI);

      // </wsp:Policy>
      writer.writeEndElement();
    }
    writer.writeEndElement();
    // </sp:KeyValueToken>

  }
コード例 #6
0
 private void writeAttribute(
     final String prefix,
     final String namespace,
     final String attName,
     final String attValue,
     final XMLStreamWriter xmlWriter)
     throws XMLStreamException {
   if (xmlWriter.getPrefix(namespace) == null) {
     xmlWriter.writeNamespace(prefix, namespace);
     xmlWriter.setPrefix(prefix, namespace);
   }
   xmlWriter.writeAttribute(namespace, attName, attValue);
 }
コード例 #7
0
  public void writeMetadataDocument(final XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
    writer.setPrefix(PREFIX_EDMX, NS_EDMX);
    writer.setDefaultNamespace(NS_EDMX);
    writer.writeStartElement(PREFIX_EDMX, EDMX, NS_EDMX);
    writer.writeAttribute("Version", "4.0");
    writer.writeNamespace(PREFIX_EDMX, NS_EDMX);

    appendReference(writer);
    appendDataServices(writer);

    writer.writeEndDocument();
  }
コード例 #8
0
 /** Util method to write an attribute with the ns prefix */
 private void writeAttribute(
     java.lang.String prefix,
     java.lang.String namespace,
     java.lang.String attName,
     java.lang.String attValue,
     javax.xml.stream.XMLStreamWriter xmlWriter)
     throws javax.xml.stream.XMLStreamException {
   if (xmlWriter.getPrefix(namespace) == null) {
     xmlWriter.writeNamespace(prefix, namespace);
     xmlWriter.setPrefix(prefix, namespace);
   }
   xmlWriter.writeAttribute(namespace, attName, attValue);
 }
コード例 #9
0
  public void writeXmlns(String prefix, String uri) {
    try {
      if (prefix.length() == 0) {
        out.setDefaultNamespace(uri);
      } else {
        out.setPrefix(prefix, uri);
      }

      // this method handles "", null, and "xmlns" prefixes properly
      out.writeNamespace(prefix, uri);
    } catch (XMLStreamException e) {
      throw new TxwException(e);
    }
  }
コード例 #10
0
ファイル: XMLStreamMap.java プロジェクト: flyaruu/navajo
 // @Override
 public void load(Access access) throws MappableException, UserException {
   try {
     content = new Binary();
     OutputStream ob = content.getOutputStream();
     XMLOutputFactory xof = XMLOutputFactory.newInstance();
     OutputStreamWriter out = new OutputStreamWriter(ob, "UTF8");
     xtw = xof.createXMLStreamWriter(out);
     xtw.writeStartDocument("UTF-8", "1.0");
     xtw.setPrefix("", docSpecUrl);
     xtw.writeCharacters("\n");
   } catch (Exception e) {
     throw new UserException(450, e.getMessage());
   }
 }
コード例 #11
0
 /** Register a namespace prefix */
 private java.lang.String registerPrefix(
     javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
     throws javax.xml.stream.XMLStreamException {
   java.lang.String prefix = xmlWriter.getPrefix(namespace);
   if (prefix == null) {
     prefix = generatePrefix(namespace);
     while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
       prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
     }
     xmlWriter.writeNamespace(prefix, namespace);
     xmlWriter.setPrefix(prefix, namespace);
   }
   return prefix;
 }
コード例 #12
0
  private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);
    if (prefix == null) {
      prefix = OperationRequestType.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }

      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
コード例 #13
0
  public void serialize(XMLStreamWriter writer) throws XMLStreamException {

    String wspPrefix = writer.getPrefix(Constants.URI_POLICY_NS);

    if (wspPrefix == null) {
      wspPrefix = Constants.ATTR_WSP;
      writer.setPrefix(wspPrefix, Constants.URI_POLICY_NS);
    }

    writer.writeStartElement(wspPrefix, Constants.ELEM_POLICY_REF, Constants.URI_POLICY_NS);
    writer.writeNamespace(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
    writer.writeAttribute(Constants.ATTR_URI, getURI());

    writer.writeEndElement();
  }
コード例 #14
0
  public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getName().getLocalPart();
    String namespaceURI = getName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
      prefix = getName().getPrefix();
      writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RecipientToken>
    writer.writeStartElement(prefix, localName, namespaceURI);

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
      pPrefix = SPConstants.POLICY.getPrefix();
      writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(
        pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());

    Token token = getReceipientToken();
    if (token == null) {
      throw new RuntimeException("RecipientToken doesn't contain any token assertions");
    }
    token.serialize(writer);

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:RecipientToken>
    writer.writeEndElement();
  }
コード例 #15
0
ファイル: GetStatus.java プロジェクト: jeking3/rig-client
  @SuppressWarnings("unused")
  private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);
    if (prefix == null) {
      prefix = GetStatus.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }
      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
コード例 #16
0
  /**
   * Creates a new initialized writer.<br>
   * The writer's prefixes are initialized to the values of the prefixMap.
   *
   * @param out
   * @return Returns the initialized <code>XmlStreamWriter</code>X instance.
   * @throws javax.xml.stream.XMLStreamException
   */
  private XMLStreamWriter newInitializedWriter(final ByteArrayOutputStream out)
      throws XMLStreamException {

    final XMLStreamWriter writer = XmlUtility.createXmlStreamWriterNamespaceRepairing(out);
    if (this.namespaceMap != null && !namespaceMap.isEmpty()) {
      for (final Entry<String, String> stringStringEntry : namespaceMap.entrySet()) {
        final String prefix = stringStringEntry.getValue();
        if (prefix != null) {
          writer.setPrefix(prefix, stringStringEntry.getKey());
        } else {
          writer.setDefaultNamespace(stringStringEntry.getKey());
        }
      }
    }
    return writer;
  }
コード例 #17
0
  private void writeQNames(
      javax.xml.namespace.QName[] qnames, javax.xml.stream.XMLStreamWriter xmlWriter)
      throws javax.xml.stream.XMLStreamException {
    if (qnames != null) {
      // we have to store this data until last moment since it is not possible to write any
      // namespace data after writing the charactor data
      java.lang.StringBuffer stringToWrite = new java.lang.StringBuffer();
      java.lang.String namespaceURI = null;
      java.lang.String prefix = null;

      for (int i = 0; i < qnames.length; i++) {
        if (i > 0) {
          stringToWrite.append(" ");
        }

        namespaceURI = qnames[i].getNamespaceURI();

        if (namespaceURI != null) {
          prefix = xmlWriter.getPrefix(namespaceURI);

          if ((prefix == null) || (prefix.length() == 0)) {
            prefix = generatePrefix(namespaceURI);
            xmlWriter.writeNamespace(prefix, namespaceURI);
            xmlWriter.setPrefix(prefix, namespaceURI);
          }

          if (prefix.trim().length() > 0) {
            stringToWrite
                .append(prefix)
                .append(":")
                .append(
                    org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
          } else {
            stringToWrite.append(
                org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
          }
        } else {
          stringToWrite.append(
              org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
        }
      }

      xmlWriter.writeCharacters(stringToWrite.toString());
    }
  }
コード例 #18
0
 protected void writeAttributeWithNS(String namespaceURI, String localname, String value)
     throws XMLStreamException {
   if (namespaceURI == null || namespaceURI.length() == 0) {
     writer.writeAttribute(localname, value);
   } else {
     String prefix = writer.getNamespaceContext().getPrefix(namespaceURI);
     if (prefix == null) {
       prefix = nsToPrefix.get(namespaceURI);
       if (prefix != null) {
         writer.setPrefix(prefix, namespaceURI);
         writer.writeNamespace(prefix, namespaceURI);
       } else {
         LOG.warn(
             "No prefix for namespace '{}' configured. Depending on XMLStream auto-repairing.",
             namespaceURI);
       }
     }
     writer.writeAttribute(prefix, namespaceURI, localname, value);
   }
 }
コード例 #19
0
 /** Utility method to write an element start tag. */
 private void writeStartElement(
     java.lang.String prefix,
     java.lang.String namespace,
     java.lang.String localPart,
     javax.xml.stream.XMLStreamWriter xmlWriter)
     throws javax.xml.stream.XMLStreamException {
   java.lang.String writerPrefix = xmlWriter.getPrefix(namespace);
   if (writerPrefix != null) {
     xmlWriter.writeStartElement(namespace, localPart);
   } else {
     if ((namespace.length()) == 0) {
       prefix = "";
     } else if (prefix == null) {
       prefix = hr.ponge.pfa.axis.env.operations.UpdateUserResp.generatePrefix(namespace);
     }
     xmlWriter.writeStartElement(prefix, localPart, namespace);
     xmlWriter.writeNamespace(prefix, namespace);
     xmlWriter.setPrefix(prefix, namespace);
   }
 }
コード例 #20
0
    private void writeStartElement(
        java.lang.String prefix,
        final java.lang.String namespace,
        final java.lang.String localPart,
        final javax.xml.stream.XMLStreamWriter xmlWriter)
        throws javax.xml.stream.XMLStreamException {
      final java.lang.String writerPrefix = xmlWriter.getPrefix(namespace);
      if (writerPrefix != null) {
        xmlWriter.writeStartElement(namespace, localPart);
      } else {
        if (namespace.length() == 0) {
          prefix = "";
        } else if (prefix == null) {
          prefix = ConsultaCadastro2Result.generatePrefix(namespace);
        }

        xmlWriter.writeStartElement(prefix, localPart, namespace);
        xmlWriter.writeNamespace(prefix, namespace);
        xmlWriter.setPrefix(prefix, namespace);
      }
    }
コード例 #21
0
 private void writeQNames(
     javax.xml.namespace.QName[] qnames, javax.xml.stream.XMLStreamWriter xmlWriter)
     throws javax.xml.stream.XMLStreamException {
   if (qnames != null) {
     java.lang.StringBuffer stringToWrite = new java.lang.StringBuffer();
     java.lang.String namespaceURI = null;
     java.lang.String prefix = null;
     for (int i = 0; i < (qnames.length); i++) {
       if (i > 0) {
         stringToWrite.append(" ");
       }
       namespaceURI = qnames[i].getNamespaceURI();
       if (namespaceURI != null) {
         prefix = xmlWriter.getPrefix(namespaceURI);
         if ((prefix == null) || ((prefix.length()) == 0)) {
           prefix =
               hr.ponge.pfa.axis.core.operations.CreateDocumentReq.generatePrefix(namespaceURI);
           xmlWriter.writeNamespace(prefix, namespaceURI);
           xmlWriter.setPrefix(prefix, namespaceURI);
         }
         if ((prefix.trim().length()) > 0) {
           stringToWrite
               .append(prefix)
               .append(":")
               .append(
                   org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
         } else {
           stringToWrite.append(
               org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
         }
       } else {
         stringToWrite.append(
             org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qnames[i]));
       }
     }
     xmlWriter.writeCharacters(stringToWrite.toString());
   }
 }
コード例 #22
0
 /** method to handle Qnames */
 private void writeQName(
     javax.xml.namespace.QName qname, javax.xml.stream.XMLStreamWriter xmlWriter)
     throws javax.xml.stream.XMLStreamException {
   java.lang.String namespaceURI = qname.getNamespaceURI();
   if (namespaceURI != null) {
     java.lang.String prefix = xmlWriter.getPrefix(namespaceURI);
     if (prefix == null) {
       prefix = hr.ponge.pfa.axis.env.operations.UpdateUserResp.generatePrefix(namespaceURI);
       xmlWriter.writeNamespace(prefix, namespaceURI);
       xmlWriter.setPrefix(prefix, namespaceURI);
     }
     if ((prefix.trim().length()) > 0) {
       xmlWriter.writeCharacters(
           ((prefix + ":")
               + (org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname))));
     } else {
       xmlWriter.writeCharacters(
           org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
     }
   } else {
     xmlWriter.writeCharacters(
         org.apache.axis2.databinding.utils.ConverterUtil.convertToString(qname));
   }
 }
コード例 #23
0
  public boolean execute() {
    attributeModel = workspace.getLookup().lookup(AttributeModel.class);
    graphModel = workspace.getLookup().lookup(GraphModel.class);
    HierarchicalGraph graph = null;
    if (exportVisible) {
      graph = graphModel.getHierarchicalGraphVisible();
    } else {
      graph = graphModel.getHierarchicalGraph();
    }
    Progress.start(progress);
    graph.readLock();

    // Options
    if (normalize) {
      calculateMinMax(graph);
    }

    // Calculate progress units count
    int max = 0;
    if (exportHierarchy) {
      for (Node n : graph.getNodesTree()) {
        max++;
      }
      for (Edge e : graph.getEdgesTree()) {
        max++;
      }
    } else {
      max = graph.getNodeCount();
      for (Edge e : graph.getEdgesAndMetaEdges()) {
        max++;
      }
    }
    Progress.switchToDeterminate(progress, max);

    try {
      XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
      outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);

      XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
      xmlWriter = new IndentingXMLStreamWriter(xmlWriter);

      xmlWriter.writeStartDocument("UTF-8", "1.0");
      xmlWriter.setPrefix("", GEXF_NAMESPACE);
      xmlWriter.writeStartElement(GEXF_NAMESPACE, GEXF);
      xmlWriter.writeNamespace("", GEXF_NAMESPACE);
      xmlWriter.writeAttribute(GEXF_VERSION, "1.1");

      if (exportColors || exportPosition || exportSize) {
        xmlWriter.writeNamespace(VIZ, VIZ_NAMESPACE);
      }
      xmlWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      xmlWriter.writeAttribute("xsi:schemaLocation", GEXF_NAMESPACE_LOCATION);

      if (exportDynamic) {
        DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
        dynamicModel = dynamicController != null ? dynamicController.getModel(workspace) : null;
        visibleInterval =
            dynamicModel == null
                ? null
                : exportVisible
                    ? dynamicModel.getVisibleInterval()
                    : new TimeInterval(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
      }

      writeMeta(xmlWriter);
      writeGraph(xmlWriter, graph);

      xmlWriter.writeEndElement();
      xmlWriter.writeEndDocument();
      xmlWriter.close();

    } catch (Exception e) {
      graph.readUnlockAll();
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RuntimeException(e);
    }

    graph.readUnlock();

    Progress.finish(progress);
    return !cancel;
  }
コード例 #24
0
  @Override
  public StartElement startElement(final StartElement element) throws XMLStreamException {
    final String elementName = element.getLocalName();
    if ("component".equals(elementName)) {
      this.inComponent = true;
      if (this.pids != null) {
        this.componentId = pids.get(this.number);
        this.number++;
      } else {
        final int index = element.indexOfAttribute(null, "objid");
        if (index != -1) {
          final String value = element.getAttribute(index).getValue();
          if (value != null && value.length() > 0) {
            this.componentId = value;
          }
        }
      }
    }

    if (!this.inside) {
      final String currentPath = parser.getCurPath();
      if (paths.containsKey(currentPath)) {
        if (this.insideLevel != 0) {
          throw new XMLStreamException("insideLevel != 0: " + this.insideLevel);
        }

        this.inside = true;
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        this.writer = newInitializedWriter(out);

        final String attributeName = paths.get(currentPath);
        if (this.inComponent) {
          if (this.components == null) {
            this.components = new HashMap<String, Map>();
            outputStreams.put("components", this.components);
          }
          final Map<String, Object> component;
          if (components.containsKey(this.componentId)) {
            component = (HashMap) components.get(this.componentId);
          } else {
            component = new HashMap<String, Object>();
            components.put(this.componentId, component);
          }

          if (attributeName == null) {
            component.put(elementName, out);
          } else {
            final String attributeValue = getAttributeValue(element, null, attributeName);
            if ("md-record".equals(elementName)) {
              Map<String, OutputStream> mdRecords = components.get(this.components);
              if (mdRecords == null) {
                mdRecords = new HashMap<String, OutputStream>();
                component.put("md-records", mdRecords);
              }
              mdRecords.put(attributeValue, out);
            } else {
              component.put(attributeValue, out);
            }
          }
        } else {
          if (attributeName == null) {
            outputStreams.put(elementName, out);
          } else {
            final String attributeValue = getAttributeValue(element, null, attributeName);
            if ("md-record".equals(elementName)) {
              if (this.metadata == null) {
                this.metadata = new HashMap<String, OutputStream>();
                outputStreams.put("md-records", this.metadata);
              }
              metadata.put(attributeValue, out);
            } else {
              outputStreams.put(attributeValue, out);
            }
          }
        }
      }
    }

    // write start element with attributes (and implicit neccessary
    // namespace declarations due to the repairing xml writer
    if (this.inside) {
      String namespace = element.getNamespace();
      if (namespace != null && !namespaceMap.containsKey(namespace)) {
        final String prefix = element.getPrefix();
        if (prefix != null) {
          writer.setPrefix(prefix, element.getNamespace());
        } else {
          writer.setDefaultNamespace(element.getNamespace());
        }
      }

      if (!("md-record".equals(elementName) && paths.containsKey(parser.getCurPath()))) {
        writer.writeStartElement(element.getNamespace(), elementName);
      }
      final int attCount = element.getAttributeCount();
      for (int i = 0; i < attCount; i++) {
        final Attribute curAtt = element.getAttribute(i);
        namespace = curAtt.getNamespace();
        if (namespace != null && !namespaceMap.containsKey(namespace)) {
          // Prefix is not null. (FRS)
          writer.setPrefix(curAtt.getPrefix(), namespace);
        }
        if (!("md-record".equals(elementName) && paths.containsKey(parser.getCurPath()))) {
          writer.writeAttribute(namespace, curAtt.getLocalName(), curAtt.getValue());
        }
      }
      this.insideLevel++;
    }

    // this has to be the last handler
    return element;
  }
コード例 #25
0
  private void writeBindings(
      List<StringPair> classes,
      XMLStreamWriter writer,
      String referencedXSD,
      String namespace,
      String packageName)
      throws XMLStreamException {
    final String JAXB_NS = "http://java.sun.com/xml/ns/jaxb";
    final String XJC_NS = "http://java.sun.com/xml/ns/jaxb/xjc";
    writer.setPrefix("jaxb", JAXB_NS);
    writer.setPrefix("xjc", XJC_NS);
    writer.setPrefix("xs", "http://www.w3.org/2001/XMLSchema");
    writer.writeStartDocument();
    writer.writeStartElement(JAXB_NS, "bindings");
    writer.writeAttribute("version", "2.1");
    writer.writeStartElement(JAXB_NS, "bindings");
    // writer.writeAttribute( "schemaLocation", referencedXSD );
    writer.writeAttribute("scd", "x-schema::tns");
    writer.setPrefix("tns", namespace);
    writer.writeAttribute("map", "false");
    // writer.writeEmptyElement( XJC_NS, "noUnmarshaller" );
    // writer.writeEmptyElement( XJC_NS, "noMarshaller" );
    // writer.writeEmptyElement( XJC_NS, "noValidator" );
    // writer.writeEmptyElement( XJC_NS, "noValidatingUnmarshaller" );
    writer.writeStartElement(JAXB_NS, "schemaBindings");
    // <schemaBindings map="false">
    // <package name="org.deegree.dataaccess.configuration"></package>
    writer.writeStartElement(JAXB_NS, "package");
    writer.writeAttribute("name", packageName);
    // JAXB_NS, "package"
    writer.writeEndElement();

    // JAXB_NS, "schemaBindings"
    writer.writeEndElement();
    for (StringPair cl : classes) {
      if (cl != null) {
        int index = cl.first.lastIndexOf('.');
        if (index != -1) {
          String clName = cl.first.substring(index + 1);
          // If the class name doesn't have a Type in its name, it is probably a schema element...
          // *g*
          // http://www.w3.org/TR/xmlschema-ref/
          writer.writeStartElement(JAXB_NS, "bindings");
          // writer.writeAttribute( "scd", "/" + cl.second + "::tns:" + clName );
          // if ( cl.first.toLowerCase().contains( "type" ) ) {
          if ("type".equals(cl.second) || "simpleType".equals(cl.second)) {
            writer.writeAttribute("scd", "~tns:" + clName);
          } else {
            writer.writeAttribute("scd", "tns:" + clName);
          }
          writer.writeStartElement(JAXB_NS, "class");
          writer.writeAttribute("ref", cl.first);
          writer.writeEndElement(); // JAXB_NS, "class"
          writer.writeEndElement(); // JAXB_NS, "bindings"
        }
      }
    }

    writer.writeEndElement(); // JAXB_NS, "bindings"

    writer.writeEndElement(); // JAXB_NS, "bindings"
    writer.writeEndDocument();
  }
コード例 #26
0
 public void setPrefix(java.lang.String prefix, java.lang.String uri) throws XMLStreamException {
   baseWriter.setPrefix(prefix, uri);
 }
コード例 #27
0
  public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSamlToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
      prefix = name.getPrefix();
      writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KerberosToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
      writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
      pPrefix = SPConstants.POLICY.getPrefix();
      writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(
        pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());

    if (isRequireKeyIdentifierReference()) {
      // <sp:RequireKeyIdentifierReference />
      writer.writeStartElement(prefix, SPConstants.REQUIRE_KEY_IDENTIFIER_REFERENCE, namespaceURI);
      writer.writeEndElement();
    }

    if (isV5ApReqToken11()) {
      // <sp:WssKerberosV5ApReqToken11 />
      writer.writeStartElement(prefix, SPConstants.KERBEROS_V5_AP_REQ_TOKEN_11, namespaceURI);
      writer.writeEndElement();
    } else if (isGssV5ApReqToken11()) {
      // <sp:WssGssKerberosV5ApReqToken11 />
      writer.writeStartElement(prefix, SPConstants.KERBEROS_GSS_V5_AP_REQ_TOKEN_11, namespaceURI);
      writer.writeEndElement();
    }

    if (isDerivedKeys()) {
      // <sp:RequireDerivedKeys />
      writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
      writer.writeEndElement();
    }

    // </wsp:Policy>
    writer.writeEndElement();

    writer.writeEndElement();
    // </sp:KerberosToken>

  }
コード例 #28
0
  public void serialize(XMLStreamWriter writer) throws XMLStreamException {

    String localname = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();
    String prefix;

    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
      prefix = getRealName().getPrefix();
      writer.setPrefix(prefix, namespaceURI);
    } else {
      prefix = writerPrefix;
    }

    // <sp:SecureConversationToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
      // xmlns:sp=".."
      writer.writeNamespace(prefix, namespaceURI);
    }

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
      writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (issuerEpr != null) {
      // <sp:Issuer>
      writer.writeStartElement(prefix, SPConstants.ISSUER, namespaceURI);

      StaxUtils.copy(issuerEpr, writer);

      writer.writeEndElement();
    }

    if (isDerivedKeys()
        || isRequireExternalUriRef()
        || isSc10SecurityContextToken()
        || bootstrapPolicy != null) {

      String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

      String wspPrefix;

      String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

      if (wspWriterPrefix == null) {
        wspPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(wspPrefix, wspNamespaceURI);

      } else {
        wspPrefix = wspWriterPrefix;
      }

      // <wsp:Policy>
      writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

      if (wspWriterPrefix == null) {
        // xmlns:wsp=".."
        writer.writeNamespace(wspPrefix, wspNamespaceURI);
      }

      if (isDerivedKeys()) {
        // <sp:RequireDerivedKeys />
        writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
      }

      if (isRequireExternalUriRef()) {
        // <sp:RequireExternalUriReference />
        writer.writeEmptyElement(prefix, SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE, namespaceURI);
      }

      if (isSc10SecurityContextToken()) {
        // <sp:SC10SecurityContextToken />
        writer.writeEmptyElement(prefix, SPConstants.SC10_SECURITY_CONTEXT_TOKEN, namespaceURI);
      }

      if (bootstrapPolicy != null) {
        // <sp:BootstrapPolicy ..>
        writer.writeStartElement(prefix, SPConstants.BOOTSTRAP_POLICY, namespaceURI);
        bootstrapPolicy.serialize(writer);
        writer.writeEndElement();
      }

      // </wsp:Policy>
      writer.writeEndElement();
    }

    // </sp:SecureConversationToken>
    writer.writeEndElement();
  }
コード例 #29
0
 public void setPrefix(String prefix, String uri) throws XMLStreamException {
   writer.setPrefix(prefix, uri);
 }