Creates an inner document for the given parent document.
Inner documents are used for tables cells with style {@code asciidoc}.

@param parentDocument The parent document of the new document.
@return A new inner document.
767644
@Override
    public Document createDocument(Document parentDocument) {
        Ruby runtime = JRubyRuntimeContext.get(parentDocument);
        RubyHash options = RubyHash.newHash(runtime);
        options.put(
                runtime.newSymbol("parent"),
                ((DocumentImpl) parentDocument).getRubyObject());

        return (Document) NodeConverter.createASTNode(runtime, NodeConverter.NodeType.DOCUMENT_CLASS, runtime.getNil(), options);
    }
239887
private Document updateOrCreateIndex(EntityMetadata metadata, final MetamodelImpl metaModel, Object entity,
            String parentId, Class<?> clazz, boolean isUpdate)
    {
        boolean isEmbeddedId = metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());
        if (!metadata.isIndexable())
        {
            return null;
        }

        Document document = null;
        Object embeddedObject = null;
        Object rowKey = null;

        try
        {
            rowKey = PropertyAccessorHelper.getId(entity, metadata);
        }
        catch (PropertyAccessException e1)
        {
            throw new LuceneIndexingException("Can't access Primary key property from " + metadata.getEntityClazz(), e1);
        }

        if (metadata.getType().equals(EntityMetadata.Type.SUPER_COLUMN_FAMILY))
        {
            Map<String, EmbeddableType> embeddables = metaModel.getEmbeddables(metadata.getEntityClazz());

            Iterator<String> iter = embeddables.keySet().iterator();

            while (iter.hasNext())
            {

                String attributeName = iter.next();
                EmbeddableType embeddableAttribute = embeddables.get(attributeName);
                EntityType entityType = metaModel.entity(metadata.getEntityClazz());

                embeddedObject = PropertyAccessorHelper.getObject(entity, (Field) entityType
                        .getAttribute(attributeName).getJavaMember());

                if (embeddedObject == null)
                {
                    continue;
                }
                if (embeddedObject instanceof Collection<?>)
                {
                    document = updateOrCreateIndexCollectionTypeEmbeddedObject(metadata, metaModel, entity, parentId,
                            clazz, isUpdate, document, embeddedObject, rowKey, attributeName, embeddableAttribute);
                }
                else
                {
                    document = prepareDocumentForSuperColumn(metadata, entity, attributeName, parentId, clazz);
                    createSuperColumnDocument(metadata, entity, document,
                            metaModel.isEmbeddable(embeddedObject.getClass()) ? embeddedObject : entity,
                            embeddableAttribute, metaModel);
                    if (isUpdate)
                    {
                        updateDocument(parentId, document, null);
                    }
                    else
                    {
                        indexDocument(metadata, document);
                    }
                }
            }
        }
        else
        {
            document = updateOrCreateIndexNonSuperColumnFamily(metadata, metaModel, entity, parentId, clazz, isUpdate,
                    isEmbeddedId, rowKey);
        }
        return document;

    }
872322
protected Node doClone(Node parent) {
        Node clone;

        try {
            clone = (Node) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }

        clone.parentNode = parent; // can be null, to create an orphan split
        clone.siblingIndex = parent == null ? 0 : siblingIndex;

        return clone;
    }
503596
public int addDocument(String document) {
    if (root().getNumberOfChildren() >= 0) {
      throw new IllegalStateException("Tree sorting has begun");
    }
    final int index;
    synchronized (this) {
      index = documents.size();
      documents.add(document);
    }
    cursors.addAll(
      IntStream.range(0, document.length() + 1).mapToObj(i -> new CursorData(index, i)).collect(Collectors.toList()));
    nodes.update(0, node -> node.setCursorCount(cursors.length()));
    return index;
  }
485714
public function toXML(DOMElement $parent = null) : DOMElement
    {
        if ($parent === null) {
            $doc = DOMDocumentFactory::create();
            $e = $doc->createElementNS(Constants::NS_MD, 'md:EntitiesDescriptor');
            $doc->appendChild($e);
        } else {
            $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:EntitiesDescriptor');
            $parent->appendChild($e);
        }

        if ($this->ID !== null) {
            $e->setAttribute('ID', $this->ID);
        }

        if ($this->validUntil !== null) {
            $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil));
        }

        if ($this->cacheDuration !== null) {
            $e->setAttribute('cacheDuration', $this->cacheDuration);
        }

        if ($this->Name !== null) {
            $e->setAttribute('Name', $this->Name);
        }

        Extensions::addList($e, $this->Extensions);

        /** @var \SAML2\XML\md\EntityDescriptor|\SAML2\XML\md\EntitiesDescriptor $node */
        foreach ($this->children as $node) {
            $node->toXML($e);
        }

        $this->signElement($e, $e->firstChild);

        return $e;
    }
225313
function Document (document, name, parent) {
  if (!(this instanceof Document)) return new Document(document, name, parent);
  debug('document <%s> being built', name);
  Entry.call(this, document, name, parent);
  this._context = helpers.getAPI(this);
  this._currVal = {}; // 'this' object in evaluating user expressions
  this._this = this._currVal;
  Object.defineProperty(this._currVal, '_$parent', {
    get: function () {
      return parent._currVal;
    }
  });

  this._children = {};
  for (var childName in this._content) {
    this._children[childName] =
      helpers.build(this._content[childName], childName, this);
    (function (method) {
      var child = this._children[method];
      Object.defineProperty(this._currVal, method, {
        enumerable: true,
        get: function () {
          if (child._currVal === undefined)
            return child.next();
          return child._currVal; // doc and array's currval never empty
        }
      });
    }).call(this, childName);
  }
  debug('document <%s> build complete', name);
}
1090629
private function setParentPageUuid(
        ArticleDocument $document,
        ArticleViewDocumentInterface $article
    ) {
        $parentPageUuid = $this->getParentPageUuidFromPageTree($document);

        if (!$parentPageUuid) {
            return;
        }

        $article->setParentPageUuid($parentPageUuid);
    }
1152537
public static Window showXML(Document document, BaseUIComponent parent) {
        Map<String, Object> args = Collections.singletonMap("document", document);
        boolean modal = parent == null;
        Window dialog = PopupDialog.show(XMLConstants.VIEW_DIALOG, args, modal, modal, modal, null);
        
        if (parent != null) {
            dialog.setParent(parent);
        }
        
        return dialog;
    }
586064
private function fillElement (DOMDocument $doc, DOMElement $parent, array $filler)
    {
        foreach ($filler as $name => $value) {
            if ($value instanceof DOMElement) {
                $element = $value;
            } else {
                $element = $doc->createElement($name);
                
                if (is_array($value)) {
                    $this->fillElement($doc, $element, $value);
                } else {
                    $element->appendChild(new DOMCdataSection($value));
                }
            }
            
            $parent->appendChild($element);
        }
    }
725887
public Document cloneDocument(DOMImplementation domImpl, Document document) {
    Element root = document.getDocumentElement();
    // New document
    Document result = domImpl.createDocument(root.getNamespaceURI(), root.getNodeName(), null);
    Element rroot = result.getDocumentElement();
    // Cloning the document element is a bit tricky.
    // This is adopted from DomUtilities#deepCloneDocument
    boolean before = true;
    for(Node n = document.getFirstChild(); n != null; n = n.getNextSibling()) {
      if(n == root) {
        before = false;
        copyAttributes(result, root, rroot);
        for(Node c = root.getFirstChild(); c != null; c = c.getNextSibling()) {
          final Node cl = cloneNode(result, c);
          if(cl != null) {
            rroot.appendChild(cl);
          }
        }
      }
      else {
        if(n.getNodeType() != Node.DOCUMENT_TYPE_NODE) {
          final Node cl = cloneNode(result, n);
          if(cl != null) {
            if(before) {
              result.insertBefore(cl, rroot);
            }
            else {
              result.appendChild(cl);
            }
          }
        }
      }
    }
    return result;
  }
631038
function createDocumentFragment(ownerDocument, data){
    if (!ownerDocument) {
        ownerDocument = document;
    }
    if(supportsUnknownElements){
        return ownerDocument.createDocumentFragment();
    }
    data = data || getExpandoData(ownerDocument);
    var clone = data.frag.cloneNode(),
        i = 0,
        elems = getElements(),
        l = elems.length;
    for(;i<l;i++){
        clone.createElement(elems[i]);
    }
    return clone;
  }
1025839
function(doc, nodes, selector, after) {
        var parent = module.exports.resolveParent(doc, selector);
        if (!parent) {
            //Try to create the parent recursively if necessary
            try {
                var parentToCreate = et.XML('<' + path.basename(selector) + '>'),
                    parentSelector = path.dirname(selector);

                this.graftXML(doc, [parentToCreate], parentSelector);
            } catch (e) {
                return false;
            }
            parent = module.exports.resolveParent(doc, selector);
            if (!parent) return false;
        }

        nodes.forEach(function (node) {
            // check if child is unique first
            if (uniqueChild(node, parent)) {
                var children = parent.getchildren();
                var insertIdx = after ? findInsertIdx(children, after) : children.length;

                //TODO: replace with parent.insert after the bug in ElementTree is fixed
                parent.getchildren().splice(insertIdx, 0, node);
            }
        });

        return true;
    }
455651
private static function _setDocId(&$subdoc, &$parentNode, $id, &$docIdXpath, $curLevel = 0) {
        if ($parentNode->nodeName == $docIdXpath[$curLevel]) {
            if ($curLevel == count($docIdXpath) - 1) {
                // remove all sub-nodes
                $curChild = $parentNode->firstChild;
                while ($curChild) {
                    $nextChild = $curChild->nextSibling;
                    $parentNode->removeChild($curChild);
                    $curChild = $nextChild;
                }
                // set the ID
                if (!CPS_Request::isValidUTF8((string) $id))
                	throw new CPS_Exception(array(array('long_message' => 'Invalid UTF-8 encoding in document ID', 'code' => ERROR_CODE_INVALID_UTF8, 'level' => 'ERROR', 'source' => 'CPS_API')));
                $textNode = $subdoc->createTextNode($id);
                $parentNode->appendChild($textNode);
            } else {
                // traverse children
                $found = false;
                $curChild = $parentNode->firstChild;
                while ($curChild) {
                    if ($curChild->nodeName == $docIdXpath[$curLevel + 1]) {
                        CPS_Request::_setDocId($subdoc, $curChild, $id, $docIdXpath, $curLevel + 1);
                        $found = true;
                        break;
                    }
                    $curChild = $curChild->nextSibling;
                }
                if (!$found) {
                    $newNode = $subdoc->createElement($docIdXpath[$curLevel + 1]);
                    $parentNode->appendChild($newNode);
                    CPS_Request::_setDocId($subdoc, $newNode, $id, $docIdXpath, $curLevel + 1);
                }
            }
        } else {
            throw new CPS_Exception(array(array('long_message' => 'Document root xpath not matching document ID xpath', 'code' => ERROR_CODE_INVALID_XPATHS, 'level' => 'REJECTED', 'source' => 'CPS_API')));
        }
    }
314133
private function buildXml($data, \DOMDocument $doc, \DOMNode $parentNode = null)
    {
        if (is_array($data)) {
            foreach ($data as $elementName => $element) {
                if (is_int($elementName)) {
                    $elementName = 'item';
                }

                $newElement = $doc->createElement($elementName);

                if ($parentNode) {
                    $parentNode->appendChild($newElement);
                } else {
                    $doc->appendChild($newElement);
                }

                $this->buildXml($element, $doc, $newElement);
            }
        } else {
            $parentNode->nodeValue = $data;
        }
    }
1278030
public function toXML(DOMElement $parent) : DOMElement
    {
        Assert::notEmpty($this->OrganizationName);
        Assert::notEmpty($this->OrganizationDisplayName);
        Assert::notEmpty($this->OrganizationURL);

        $doc = $parent->ownerDocument;

        $e = $doc->createElementNS(Constants::NS_MD, 'md:Organization');
        $parent->appendChild($e);

        Extensions::addList($e, $this->Extensions);

        Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationName', true, $this->OrganizationName);
        Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationDisplayName', true, $this->OrganizationDisplayName);
        Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationURL', true, $this->OrganizationURL);

        return $e;
    }
118452
public function create(CreateStruct $createStruct, array $parentNode)
    {
        try {
            return $this->innerGateway->create($createStruct, $parentNode);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
476293
private function matchDocComment(ParentNode $parent, $property_name = 'docComment') {
    if ($this->docComment) {
      $parent->addChild($this->docComment, $property_name);
      $parent->addChildren($this->getSkipNodes($this->skippedDocComment));
      $this->skippedDocComment = [];
      $this->docComment = NULL;
    }
    $this->skipParent = NULL;
  }