Пример #1
0
  public Element getSchemaElement(Document document) {
    Element complexElement =
        document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:complexType");
    complexElement.setPrefix("xsd");
    complexElement.setAttribute("name", this.name);

    Element sequenceElement =
        document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:sequence");
    sequenceElement.setPrefix("xsd");

    complexElement.appendChild(sequenceElement);
    return complexElement;
  }
  private Element writeBounds(final Envelope bounds, final Document document) {
    if (bounds != null) {

      String srsName = null;
      if (bounds.getCoordinateReferenceSystem() != null) {
        try {
          srsName =
              IdentifiedObjects.lookupIdentifier(
                  Citations.URN_OGC, bounds.getCoordinateReferenceSystem(), true);
        } catch (FactoryException ex) {
          LOGGER.log(Level.WARNING, null, ex);
        }
      }
      final Element boundElement = document.createElementNS(Namespaces.GML, "boundedBy");
      boundElement.setPrefix("gml");
      final Element envElement = document.createElementNS(Namespaces.GML, "Envelope");
      envElement.setPrefix("gml");
      if (srsName != null) {
        envElement.setAttribute("srsName", srsName);
      } else {
        envElement.setAttribute("srsName", "");
      }

      // lower corner
      final Element lower = document.createElementNS(Namespaces.GML, "lowerCorner");
      String lowValue =
          bounds.getLowerCorner().getOrdinate(0) + " " + bounds.getLowerCorner().getOrdinate(1);
      lower.setTextContent(lowValue);
      lower.setPrefix("gml");
      envElement.appendChild(lower);

      // upper corner
      final Element upper = document.createElementNS(Namespaces.GML, "upperCorner");
      String uppValue =
          bounds.getUpperCorner().getOrdinate(0) + " " + bounds.getUpperCorner().getOrdinate(1);
      upper.setTextContent(uppValue);
      upper.setPrefix("gml");
      envElement.appendChild(upper);

      boundElement.appendChild(envElement);
      return boundElement;
    }
    return null;
  }
Пример #3
0
  /** property url should be src attribute with url as value */
  @Override
  public void transform(WidgetTransformerContext context, Property property) throws CoreException {

    String domainAttributValue =
        property
            .getWidget()
            .getPropertyValue(PropertyTypeConstants.DOMAIN_ATTRIBUTE_WITHOUT_VALIDATOR);

    if (domainAttributValue != null && domainAttributValue.length() > 0) {
      Property beanNameProperty =
          BeanPropertyUtils.findBeanNameProperty(context, property.getWidget());
      String beanNamePropertyValue = beanNameProperty.getValue();

      // Create the element <xsp:attribute name="src">...</xsp:attribute>
      Namespace ns = context.getTransformModel().findNamespace(XSP_NAMESPACE_URI);
      Element valElmt =
          context
              .getDocument()
              .createElementNS(ns.getUri(), TransformerConstants.ATTRIBUTE_ELEMENT_NAME);
      valElmt.setPrefix(ns.getPrefix());
      TransformUtils.appendChild(context, valElmt);
      // Create the attribute name="src"
      Attr a = context.getDocument().createAttribute(TransformerConstants.NAME_ATTRIBUTE_NAME);
      a.setValue("src");
      valElmt.setAttributeNode(a);

      // create the <bean:get-property bean="..." property="..."/>
      Namespace beanNamespace = context.getTransformModel().findNamespace(BEAN_URI);
      Element defElmt =
          context.getDocument().createElementNS(beanNamespace.getUri(), BEAN_GET_PROPERTY_ELEMENT);
      defElmt.setPrefix(beanNamespace.getPrefix());
      addAttribute(context, defElmt, BEAN_BEAN_ATTRIBUTE, beanNamePropertyValue);
      addAttribute(context, defElmt, BEAN_PROPERTY_ATTRIBUTE, domainAttributValue);
      valElmt.appendChild(defElmt);

    } else {
      String url = property.getValue();
      if (url != null && url.length() != 0) {
        addAttribute(context, "src", url);
      }
    }
  }
Пример #4
0
  public void createAndAddIndexGroups(
      final IndexEntry[] theIndexEntries,
      final IndexConfiguration theConfiguration,
      final Document theDocument,
      final Locale theLocale) {
    final IndexComparator indexEntryComparator = new IndexComparator(theLocale);

    final IndexGroup[] indexGroups =
        indexGroupProcessor.process(theIndexEntries, theConfiguration, theLocale);

    final Element rootElement = theDocument.getDocumentElement();

    final Element indexGroupsElement = theDocument.createElementNS(namespace_url, "index.groups");
    indexGroupsElement.setPrefix(prefix);

    for (final IndexGroup group : indexGroups) {
      // Create group element
      final Node groupElement = theDocument.createElementNS(namespace_url, "index.group");
      groupElement.setPrefix(prefix);
      // Create group label element and index entry childs
      final Element groupLabelElement = theDocument.createElementNS(namespace_url, "label");
      groupLabelElement.setPrefix(prefix);
      groupLabelElement.appendChild(theDocument.createTextNode(group.getLabel()));
      groupElement.appendChild(groupLabelElement);

      final Node[] entryNodes =
          transformToNodes(group.getEntries(), theDocument, indexEntryComparator);
      for (final Node entryNode : entryNodes) {
        groupElement.appendChild(entryNode);
      }

      indexGroupsElement.appendChild(groupElement);
    }

    rootElement.appendChild(indexGroupsElement);
  }
  // DOM output
  public void setupNamespace(Element element) {
    String uri = element.getNamespaceURI();
    String myPrefix = getPrefixByUri(uri);
    element.setPrefix(myPrefix);

    if (myPrefix != null) {
      IRNSContainer parent = (IRNSContainer) rnode_.getParentRNode();

      if (parent == null) {
        addPrefixDecl(element, myPrefix, uri);

        return;
      }

      RNSContext parentContext = parent.getRNSContext();
      String parentPrefix = parentContext.getPrefixByUri(uri);

      if (!myPrefix.equals(parentPrefix)) {
        addPrefixDecl(element, myPrefix, uri);
      }
    }
  }
Пример #6
0
  /**
   * Writes the given {@link LayoutDevice}s into the given file.
   *
   * @param deviceXml the file to write.
   * @param deviceList the LayoutDevice to write into the file.
   */
  private void write(File deviceXml, List<LayoutDevice> deviceList) {
    try {
      // create a new document
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      docFactory.setNamespaceAware(true);
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument();

      // create a base node
      Element baseNode =
          doc.createElementNS(
              LayoutDevicesXsd.NS_LAYOUT_DEVICE_XSD, LayoutDevicesXsd.NODE_LAYOUT_DEVICES);
      // create the prefix for the namespace
      baseNode.setPrefix("d");
      doc.appendChild(baseNode);

      // fill it with the layout devices.
      for (LayoutDevice device : deviceList) {
        device.saveTo(doc, baseNode);
      }

      // save the document to disk
      // Prepare the DOM document for writing
      Source source = new DOMSource(doc);

      // Prepare the output file
      File file = new File(deviceXml.getAbsolutePath());
      Result result = new StreamResult(file);

      // Write the DOM document to the file
      Transformer xformer = TransformerFactory.newInstance().newTransformer();
      xformer.transform(source, result);
    } catch (Exception e) {
      AdtPlugin.log(e, "Failed to write %s", deviceXml.getAbsolutePath());
    }
  }
Пример #7
0
 private static Element createNode(Document doc, Element parentNode, String name) {
   Element newNode = doc.createElementNS(LayoutDeviceManager.LAYOUT_DEVICES_NAMESPACE, name);
   newNode.setPrefix(doc.lookupPrefix(LayoutDeviceManager.LAYOUT_DEVICES_NAMESPACE));
   parentNode.appendChild(newNode);
   return newNode;
 }
Пример #8
0
  /**
   * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
   *     java.lang.String, org.xml.sax.Attributes)
   */
  public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
      throws SAXException {
    // save accumulated character content
    if (inModification && charBuf.length() > 0) {
      //            String normalized = charBuf.toString();
      final String normalized =
          preserveWhitespace
              ? charBuf.toString()
              : charBuf.getNormalizedString(FastStringBuffer.SUPPRESS_BOTH);

      if (normalized.length() > 0) {
        final Text text = doc.createTextNode(charBuf.toString());
        if (stack.isEmpty()) {
          // LOG.debug("appending text to fragment: " + text.getData());
          contents.add(text);
        } else {
          final Element last = stack.peek();
          last.appendChild(text);
        }
      }
      charBuf.setLength(0);
    }
    if (namespaceURI.equals(XUPDATE_NS)) {
      String select = null;
      if (localName.equals(MODIFICATIONS)) {
        startModifications(atts);
        return;
      } else if (localName.equals(VARIABLE)) {
        // variable declaration
        startVariableDecl(atts);
        return;
      } else if (IF.equals(localName)) {
        if (inModification) {
          throw new SAXException("xupdate:if is not allowed inside a modification");
        }
        select = atts.getValue("test");
        final Conditional cond =
            new Conditional(broker, documentSet, select, namespaces, variables);
        cond.setAccessContext(accessCtx);
        conditionals.push(cond);
        return;
      } else if (VALUE_OF.equals(localName)) {
        if (!inModification) {
          throw new SAXException("xupdate:value-of is not allowed outside a modification");
        }

      } else if (APPEND.equals(localName)
          || INSERT_BEFORE.equals(localName)
          || INSERT_AFTER.equals(localName)
          || REMOVE.equals(localName)
          || RENAME.equals(localName)
          || UPDATE.equals(localName)
          || REPLACE.equals(localName)) {
        if (inModification) {
          throw new SAXException("nested modifications are not allowed");
        }
        select = atts.getValue("select");
        if (select == null) {
          throw new SAXException(localName + " requires a select attribute");
        }
        doc = builder.newDocument();
        contents = new NodeListImpl();
        inModification = true;
      } else if ((ELEMENT.equals(localName)
          || ATTRIBUTE.equals(localName)
          || TEXT.equals(localName)
          || PROCESSING_INSTRUCTION.equals(localName)
          || COMMENT.equals(localName))) {
        if (!inModification) {
          throw new SAXException("creation elements are only allowed inside " + "a modification");
        }
        charBuf.setLength(0);
      } else {
        throw new SAXException("Unknown XUpdate element: " + qName);
      }

      // start a new modification section
      if (APPEND.equals(localName)) {
        final String child = atts.getValue("child");
        modification = new Append(broker, documentSet, select, child, namespaces, variables);
      } else if (UPDATE.equals(localName)) {
        modification = new Update(broker, documentSet, select, namespaces, variables);
      } else if (INSERT_BEFORE.equals(localName)) {
        modification =
            new Insert(broker, documentSet, select, Insert.INSERT_BEFORE, namespaces, variables);
      } else if (INSERT_AFTER.equals(localName)) {
        modification =
            new Insert(broker, documentSet, select, Insert.INSERT_AFTER, namespaces, variables);
      } else if (REMOVE.equals(localName)) {
        modification = new Remove(broker, documentSet, select, namespaces, variables);
      } else if (RENAME.equals(localName)) {
        modification = new Rename(broker, documentSet, select, namespaces, variables);
      } else if (REPLACE.equals(localName)) {
        modification = new Replace(broker, documentSet, select, namespaces, variables);
      }

      // process commands for node creation
      else if (ELEMENT.equals(localName)) {
        String name = atts.getValue("name");
        if (name == null) {
          throw new SAXException("element requires a name attribute");
        }
        final int p = name.indexOf(':');
        String namespace = null;
        String prefix = "";
        if (p != Constants.STRING_NOT_FOUND) {
          prefix = name.substring(0, p);
          if (name.length() == p + 1) {
            throw new SAXException("illegal prefix in qname: " + name);
          }
          name = name.substring(p + 1);
          namespace = atts.getValue("namespace");
          if (namespace == null) {
            namespace = (String) namespaces.get(prefix);
          }
          if (namespace == null) {
            throw new SAXException("no namespace defined for prefix " + prefix);
          }
        }
        Element elem;
        if (namespace != null && namespace.length() > 0) {
          elem = doc.createElementNS(namespace, name);
          elem.setPrefix(prefix);
        } else {
          elem = doc.createElement(name);
        }

        if (stack.isEmpty()) {
          contents.add(elem);
        } else {
          final Element last = stack.peek();
          last.appendChild(elem);
        }
        this.setWhitespaceHandling((Element) stack.push(elem));
      } else if (ATTRIBUTE.equals(localName)) {
        final String name = atts.getValue("name");
        if (name == null) {
          throw new SAXException("attribute requires a name attribute");
        }
        final int p = name.indexOf(':');
        String namespace = null;
        if (p != Constants.STRING_NOT_FOUND) {
          final String prefix = name.substring(0, p);
          if (name.length() == p + 1) {
            throw new SAXException("illegal prefix in qname: " + name);
          }
          namespace = atts.getValue("namespace");
          if (namespace == null) {
            namespace = (String) namespaces.get(prefix);
          }
          if (namespace == null) {
            throw new SAXException("no namespace defined for prefix " + prefix);
          }
        }
        Attr attrib =
            namespace != null && namespace.length() > 0
                ? doc.createAttributeNS(namespace, name)
                : doc.createAttribute(name);
        if (stack.isEmpty()) {
          for (int i = 0; i < contents.getLength(); i++) {
            final Node n = contents.item(i);
            String ns = n.getNamespaceURI();
            final String nname = ns == null ? n.getNodeName() : n.getLocalName();
            if (ns == null) {
              ns = "";
            }
            // check for duplicate attributes
            if (n.getNodeType() == Node.ATTRIBUTE_NODE
                && nname.equals(name)
                && ns.equals(namespace)) {
              throw new SAXException(
                  "The attribute " + attrib.getNodeName() + " cannot be specified twice");
            }
          }
          contents.add(attrib);
        } else {
          final Element last = (Element) stack.peek();
          if (namespace != null && last.hasAttributeNS(namespace, name)
              || namespace == null && last.hasAttribute(name)) {
            throw new SAXException(
                "The attribute "
                    + attrib.getNodeName()
                    + " cannot be specified "
                    + "twice on the same element");
          }
          if (namespace != null) {
            last.setAttributeNodeNS(attrib);
          } else {
            last.setAttributeNode(attrib);
          }
        }
        inAttribute = true;
        currentNode = attrib;

        // process value-of
      } else if (VALUE_OF.equals(localName)) {
        select = atts.getValue("select");
        if (select == null) {
          throw new SAXException("value-of requires a select attribute");
        }
        final Sequence seq = processQuery(select);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Found " + seq.getItemCount() + " items for value-of");
        }
        Item item;
        try {
          for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
            item = i.nextItem();
            if (Type.subTypeOf(item.getType(), Type.NODE)) {
              final Node node = NodeSetHelper.copyNode(doc, ((NodeValue) item).getNode());
              if (stack.isEmpty()) {
                contents.add(node);
              } else {
                final Element last = (Element) stack.peek();
                last.appendChild(node);
              }
            } else {
              final String value = item.getStringValue();
              characters(value.toCharArray(), 0, value.length());
            }
          }
        } catch (final XPathException e) {
          throw new SAXException(e.getMessage(), e);
        }
      }
    } else if (inModification) {
      final Element elem =
          namespaceURI != null && namespaceURI.length() > 0
              ? doc.createElementNS(namespaceURI, qName)
              : doc.createElement(qName);
      Attr a;
      for (int i = 0; i < atts.getLength(); i++) {
        final String name = atts.getQName(i);
        final String nsURI = atts.getURI(i);
        if (name.startsWith("xmlns")) {
          // Why are these showing up? They are supposed to be stripped out?
        } else {
          a = nsURI != null ? doc.createAttributeNS(nsURI, name) : doc.createAttribute(name);
          a.setValue(atts.getValue(i));
          if (nsURI != null) {
            elem.setAttributeNodeNS(a);
          } else {
            elem.setAttributeNode(a);
          }
        }
      }
      if (stack.isEmpty()) {
        contents.add(elem);
      } else {
        final Element last = (Element) stack.peek();
        last.appendChild(elem);
      }
      this.setWhitespaceHandling((Element) stack.push(elem));
    }
  }
  /**
   * @param featureCollection
   * @param writer
   * @param fragment : true if we write in a stream, dont write start and end elements
   * @throws DataStoreException
   */
  public Element writeFeatureCollection(
      final FeatureCollection featureCollection, final boolean fragment, final boolean wfs)
      throws DataStoreException, ParserConfigurationException {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // then we have to create document-loader:
    factory.setNamespaceAware(false);
    DocumentBuilder loader = factory.newDocumentBuilder();

    // creating a new DOM-document...
    Document document = loader.newDocument();

    // the XML header
    if (!fragment) {
      document.setXmlVersion("1.0");
      // writer.writeStartDocument("UTF-8", "1.0");
    }

    // the root Element
    final Element rootElement;
    if (wfs) {
      rootElement = document.createElementNS("http://www.opengis.net/wfs", "FeatureCollection");
      rootElement.setPrefix("wfs");
    } else {
      rootElement = document.createElementNS("http://www.opengis.net/gml", "FeatureCollection");
      rootElement.setPrefix("gml");
    }

    document.appendChild(rootElement);

    String collectionID = "";
    if (featureCollection.getID() != null) {
      collectionID = featureCollection.getID();
    }
    final Attr idAttribute = document.createAttributeNS(Namespaces.GML, "id");
    idAttribute.setValue(collectionID);
    idAttribute.setPrefix("gml");
    rootElement.setAttributeNodeNS(idAttribute);

    if (schemaLocation != null && !schemaLocation.equals("")) {
      rootElement.setAttributeNS(
          "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", schemaLocation);
    }

    /*FeatureType type = featureCollection.getFeatureType();
    if (type != null && type.getName() != null) {
        String namespace = type.getName().getNamespaceURI();
        if (namespace != null && !namespace.equals(Namespaces.GML)) {
            Prefix prefix    = getPrefix(namespace);
            writer.writeNamespace(prefix.prefix, namespace);
        }
    }*/
    /*
     * The boundedby part
     */
    final Element boundElement = writeBounds(featureCollection.getEnvelope(), document);
    if (boundElement != null) {
      rootElement.appendChild(boundElement);
    }

    // we write each feature member of the collection
    FeatureIterator iterator = featureCollection.iterator();
    try {
      while (iterator.hasNext()) {
        final Feature f = iterator.next();
        final Element memberElement = document.createElementNS(Namespaces.GML, "featureMember");
        memberElement.setPrefix("gml");
        memberElement.appendChild(writeFeature(f, document, true));
        rootElement.appendChild(memberElement);
      }

    } finally {
      // we close the stream
      iterator.close();
    }
    return rootElement;
  }
  /**
   * Write the feature into the stream.
   *
   * @param feature The feature
   * @param root
   * @throws XMLStreamException
   */
  public Element writeFeature(final Feature feature, final Document rootDocument, boolean fragment)
      throws ParserConfigurationException {

    final Document document;
    if (rootDocument == null) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      // then we have to create document-loader:
      factory.setNamespaceAware(false);
      DocumentBuilder loader = factory.newDocumentBuilder();

      // creating a new DOM-document...
      document = loader.newDocument();
    } else {
      document = rootDocument;
    }

    // the root element of the xml document (type of the feature)
    final FeatureType type = feature.getType();
    final Name typeName = type.getName();
    final String namespace = typeName.getNamespaceURI();
    final String localPart = typeName.getLocalPart();

    final Element rootElement;
    final Prefix prefix;
    if (namespace != null) {
      prefix = getPrefix(namespace);
      rootElement = document.createElementNS(namespace, localPart);
      rootElement.setPrefix(prefix.prefix);

    } else {
      rootElement = document.createElement(localPart);
      prefix = null;
    }
    // if main document set the xmlns
    if (!fragment) {
      rootElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/", "xmlns:gml", "http://www.opengis.net/gml");
    }
    final Attr idAttr = document.createAttributeNS(Namespaces.GML, "id");
    idAttr.setValue(feature.getIdentifier().getID());
    idAttr.setPrefix("gml");
    rootElement.setAttributeNodeNS(idAttr);

    if (rootDocument == null) {
      document.appendChild(rootElement);
    }
    // write properties in the type order
    for (final PropertyDescriptor desc : type.getDescriptors()) {
      final Collection<Property> props = feature.getProperties(desc.getName());
      for (Property a : props) {
        final Object valueA = a.getValue();
        final PropertyType typeA = a.getType();
        final Name nameA = a.getName();
        final String nameProperty = nameA.getLocalPart();
        String namespaceProperty = nameA.getNamespaceURI();
        if (valueA instanceof Collection && !(typeA instanceof GeometryType)) {
          for (Object value : (Collection) valueA) {
            final Element element;
            if (namespaceProperty != null) {
              element = document.createElementNS(namespaceProperty, nameProperty);
            } else {
              element = document.createElement(nameProperty);
            }
            element.setTextContent(Utils.getStringValue(value));
            if (prefix != null) {
              element.setPrefix(prefix.prefix);
            }
            rootElement.appendChild(element);
          }

        } else if (valueA instanceof Map && !(typeA instanceof GeometryType)) {
          final Map<?, ?> map = (Map) valueA;
          for (Entry<?, ?> entry : map.entrySet()) {
            final Element element;
            if (namespaceProperty != null) {
              element = document.createElementNS(namespaceProperty, nameProperty);
            } else {
              element = document.createElement(nameProperty);
            }
            final Object key = entry.getKey();
            if (key != null) {
              element.setAttribute("name", (String) key);
            }
            element.setTextContent(Utils.getStringValue(entry.getValue()));
            if (prefix != null) {
              element.setPrefix(prefix.prefix);
            }
            rootElement.appendChild(element);
          }

        } else if (!(typeA instanceof GeometryType)) {
          String value = Utils.getStringValue(valueA);
          if (value != null || (value == null && !a.isNillable())) {

            if ((nameProperty.equals("name") || nameProperty.equals("description"))
                && !Namespaces.GML.equals(namespaceProperty)) {
              namespaceProperty = Namespaces.GML;
              LOGGER.warning(
                  "the property name and description of a feature must have the GML namespace");
            }
            final Element element;
            if (namespaceProperty != null) {
              element = document.createElementNS(namespaceProperty, nameProperty);
            } else {
              element = document.createElement(nameProperty);
            }
            if (value != null) {
              element.setTextContent(value);
            }
            if (prefix != null) {
              element.setPrefix(prefix.prefix);
            }
            rootElement.appendChild(element);
          }

          // we add the geometry
        } else {

          if (valueA != null) {
            final Element element;
            if (namespaceProperty != null) {
              element = document.createElementNS(namespaceProperty, nameProperty);
            } else {
              element = document.createElement(nameProperty);
            }
            if (prefix != null) {
              element.setPrefix(prefix.prefix);
            }
            Geometry isoGeometry =
                JTSUtils.toISO(
                    (com.vividsolutions.jts.geom.Geometry) valueA,
                    type.getCoordinateReferenceSystem());
            Marshaller marshaller = null;
            try {
              marshaller = POOL.acquireMarshaller();
              marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
              marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
              marshaller.marshal(OBJECT_FACTORY.buildAnyGeometry(isoGeometry), element);
            } catch (JAXBException ex) {
              LOGGER.log(
                  Level.WARNING,
                  "JAXB Exception while marshalling the iso geometry: " + ex.getMessage(),
                  ex);
            } finally {
              if (marshaller != null) {
                POOL.release(marshaller);
              }
            }
            rootElement.appendChild(element);
          }
        }
      }
    }

    // writer.writeEndElement();
    return rootElement;
  }
Пример #11
0
 /**
  * Creates element with "prefix" in "namespace_url" with given name for the target document
  *
  * @param theTargetDocument target document
  * @param theName name
  * @return new element
  */
 private Element createElement(final Document theTargetDocument, final String theName) {
   final Element indexEntryNode = theTargetDocument.createElementNS(this.namespace_url, theName);
   indexEntryNode.setPrefix(this.prefix);
   return indexEntryNode;
 }
  @Override
  protected List<Document> generateSample(
      Collection<PersonElementWrapper> people, DateTime baseDate, String stateParam)
      throws Exception {

    List<Document> personDocuments = new ArrayList<Document>();

    for (PersonElementWrapper person : people) {

      Document ret = documentBuilder.newDocument();
      personDocuments.add(ret);
      Element e = null;

      // LOG.info("person.state=" + person.state + ", stateParam=" + stateParam);

      e = ret.createElementNS(OjbcNamespaceContext.NS_CH_DOC, "CriminalHistory");
      ret.appendChild(e);
      e.setPrefix(OjbcNamespaceContext.NS_PREFIX_CH_DOC);

      e = appendElement(e, OjbcNamespaceContext.NS_CH_EXT, "RapSheet");
      Element rapSheet = e;

      e = appendElement(rapSheet, OjbcNamespaceContext.NS_RAPSHEET_41, "Metadata");
      e = appendElement(e, OjbcNamespaceContext.NS_NC, "ReportingOrganizationText");
      e.setTextContent("State CHRI");

      addIntroductionElement(person, rapSheet);
      addPersonElement(ret, person, rapSheet);
      addBiometricElement(ret, person, rapSheet);

      String locationId = addLocationElement(ret, person, rapSheet);

      int arrestCount = generatePoissonInt(1, true);

      List<Arrest> arrests = new ArrayList<Arrest>();

      for (int i = 0; i < arrestCount; i++) {
        Arrest arrest = new Arrest(baseDate, person);
        arrests.add(arrest);
      }

      Set<Agency> agencies = new HashSet<Agency>();
      for (Arrest arrest : arrests) {
        agencies.add(arrest.arrestingAgency);
        for (ArrestCharge arrestCharge : arrest.charges) {
          if (arrestCharge.offense != null) {
            agencies.add(arrestCharge.offense.supervisionAgency);
          }
        }
      }

      addAgencyElements(ret, rapSheet, agencies);
      addResidenceLocationElement(ret, person, rapSheet, locationId);
      addSupervisionCycleElements(ret, rapSheet, arrests);
      addMainCycleElements(ret, rapSheet, arrests);
      addArrestAgencyAssociations(ret, rapSheet, arrests);
      addSupervisionAgencyAssociations(ret, rapSheet, arrests);

      addProtectionOrderElements(rapSheet, person, baseDate);

      OJBC_NAMESPACE_CONTEXT.populateRootNamespaceDeclarations(ret.getDocumentElement());
    }

    return personDocuments;
  }