Useful for mapping exceptions of Multimutation or to be silent by mapping success to a valid subdocument result

@return document fragment result
189431
public static <E> DocumentFragment<Mutation> convertToSubDocumentResult(ResponseStatus status, Mutation mutation, E element) {
        return new DocumentFragment<Mutation>(null, 0, null,
                Collections.singletonList(SubdocOperationResult.createResult(null, mutation, status, element)));
    }
569198
public LabeledParsedDocument next() {
        if (nextDoc == null)
            throw new NoSuchElementException("No further documents");
        LabeledParsedDocument next = nextDoc;
        while (true) {
            try {
                advance();
                break;
            } 
            // Case for if we didn't property read the line
            catch (IOException ioe) {
                throw new IOError(ioe);
            } 
            // Some lines in the PukWaC are corrupted due to missing characters.
            // We silently catch these errors here and try to advance further to
            // the next parse tree.  Note that if none further exist, advance
            // will still return and we will break from the loop.
            catch (Exception e) {

            }
        }
        return next;
    }
98589
public function toDoc(): \DOMDocument
    {
        if (null === $this->document) {
            throw new XslProcessorException(
                    'Can not transform, set document or xml file to transform first'
            );
        }

        $this->registerCallbacks();
        $result = $this->xsltProcessor->transformToDoc($this->document);
        if (false === $result) {
            throw new XslProcessorException($this->createMessage());
        }

        return $result;
    }
12563
public Map<ComponentJob, AnalyzerResult> getUnsafeResultElements() {
        if (_unsafeResultElements == null) {
            _unsafeResultElements = new LinkedHashMap<>();
            final Map<ComponentJob, AnalyzerResult> resultMap = _analysisResult.getResultMap();
            for (final Entry<ComponentJob, AnalyzerResult> entry : resultMap.entrySet()) {
                final AnalyzerResult analyzerResult = entry.getValue();
                try {
                    SerializationUtils.serialize(analyzerResult, new NullOutputStream());
                } catch (final SerializationException e) {
                    _unsafeResultElements.put(entry.getKey(), analyzerResult);
                }
            }
        }
        return _unsafeResultElements;
    }
521769
private function _getResult()
    {
        $def = $this->actionChain->getCurrentAction();
        $result = $def['result'];
        if (! $result) {
            return null;
        } elseif (is_string($result)) {
            return $result;
        } elseif (is_array($result)) {
            return array_shift($result);
        } else {
            throw new Exception('invalid action result.');
        }
    }
1215776
public DocumentPath childPath() {
    if (pathElements.size() <= 1) {
      return null;
    }
    return new DocumentPath(this.pathElements.subList(pathElements.size() - 1, pathElements.size()));
  }
620463
public final BELScriptWalker.set_document_return set_document() throws RecognitionException {
        BELScriptWalker.set_document_return retval = new BELScriptWalker.set_document_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree dkt=null;
        CommonTree qv=null;
        CommonTree oi=null;
        CommonTree string_literal13=null;
        CommonTree char_literal14=null;
        BELScriptWalker.document_property_return prop = null;


        CommonTree dkt_tree=null;
        CommonTree qv_tree=null;
        CommonTree oi_tree=null;
        CommonTree string_literal13_tree=null;
        CommonTree char_literal14_tree=null;

        try {
            // BELScriptWalker.g:121:13: ( ( 'SET' dkt= DOCUMENT_KEYWORD ) prop= document_property '=' (qv= QUOTED_VALUE | oi= OBJECT_IDENT ) )
            // BELScriptWalker.g:122:5: ( 'SET' dkt= DOCUMENT_KEYWORD ) prop= document_property '=' (qv= QUOTED_VALUE | oi= OBJECT_IDENT )
            {
            root_0 = (CommonTree)adaptor.nil();

            // BELScriptWalker.g:122:5: ( 'SET' dkt= DOCUMENT_KEYWORD )
            // BELScriptWalker.g:122:6: 'SET' dkt= DOCUMENT_KEYWORD
            {
            _last = (CommonTree)input.LT(1);
            string_literal13=(CommonTree)match(input,24,FOLLOW_24_in_set_document144); 
            string_literal13_tree = (CommonTree)adaptor.dupNode(string_literal13);

            adaptor.addChild(root_0, string_literal13_tree);

            _last = (CommonTree)input.LT(1);
            dkt=(CommonTree)match(input,DOCUMENT_KEYWORD,FOLLOW_DOCUMENT_KEYWORD_in_set_document148); 
            dkt_tree = (CommonTree)adaptor.dupNode(dkt);

            adaptor.addChild(root_0, dkt_tree);


            }

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_document_property_in_set_document153);
            prop=document_property();

            state._fsp--;

            adaptor.addChild(root_0, prop.getTree());
            _last = (CommonTree)input.LT(1);
            char_literal14=(CommonTree)match(input,25,FOLLOW_25_in_set_document155); 
            char_literal14_tree = (CommonTree)adaptor.dupNode(char_literal14);

            adaptor.addChild(root_0, char_literal14_tree);

            // BELScriptWalker.g:122:61: (qv= QUOTED_VALUE | oi= OBJECT_IDENT )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==QUOTED_VALUE) ) {
                alt3=1;
            }
            else if ( (LA3_0==OBJECT_IDENT) ) {
                alt3=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // BELScriptWalker.g:122:62: qv= QUOTED_VALUE
                    {
                    _last = (CommonTree)input.LT(1);
                    qv=(CommonTree)match(input,QUOTED_VALUE,FOLLOW_QUOTED_VALUE_in_set_document160); 
                    qv_tree = (CommonTree)adaptor.dupNode(qv);

                    adaptor.addChild(root_0, qv_tree);


                    }
                    break;
                case 2 :
                    // BELScriptWalker.g:122:80: oi= OBJECT_IDENT
                    {
                    _last = (CommonTree)input.LT(1);
                    oi=(CommonTree)match(input,OBJECT_IDENT,FOLLOW_OBJECT_IDENT_in_set_document166); 
                    oi_tree = (CommonTree)adaptor.dupNode(oi);

                    adaptor.addChild(root_0, oi_tree);


                    }
                    break;

            }


                    if (!annotationContext.isEmpty() || !stmtlist.isEmpty()) {
                        addError(new SetDocumentPropertiesFirstException(dkt.getLine(), dkt.getCharPositionInLine()));
                    }

                    final String keywordValue;
                    if (qv != null) {
                        keywordValue = qv.toString();
                    } else if (oi != null) {
                        keywordValue = oi.toString();
                    } else {
                        throw new IllegalStateException("Did not understand document keyword value, expecting quoted value or object identifier.");
                    }

                    docprop.put(prop.r, keywordValue);
                    lastDocumentPropertyLocation = dkt.getLine();
                

            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
448780
protected function reassignDocuments()
    {
        $countCheck = SQLSelect::create('*', 'DMSDocument_Pages');
        if (!$countCheck->count()) {
            $this->output('There was no data to migrate. Finishing.');
            return $this;
        }

        $query = SQLSelect::create(array('DMSDocumentID', 'SiteTreeID'), 'DMSDocument_Pages');
        $result = $query->execute();

        foreach ($result as $row) {
            $document = DMSDocument::get()->byId($row['DMSDocumentID']);
            if (!$document) {
                $this->addResult('Skipped: document does not exist');
                continue;
            }

            $page = SiteTree::get()->byId($row['SiteTreeID']);
            if (!$page) {
                $this->addResult('Skipped: page does not exist');
                continue;
            }

            // Don't try and process pages that don't have a document set. This should be created by the first
            // action step in this build task, so shouldn't occur if run in correct order.
            if (!$page->DocumentSets()->count()) {
                $this->addResult('Skipped: no default document set');
                continue;
            }
            $this->addDocumentToSet($document, $page->DocumentSets()->first());
            $this->addResult('Reassigned to document set');
        }

        return $this;
    }
1215151
public function current()
    {
        $documentData = $this->myResultCursor->current();
        if (is_null($documentData)) {
            return null; 
        }
        /** @var MongoObject $document */
        $document = $this->container->get(
            $this->classMapInterface->getClassForResult($this->collection, $documentData)
        );

        $document->setCollection($this->collection);
        $document->loadFromArray($documentData);

        return $document;
    }
1344071
public function multipart()
    {

        if (empty($this->_multiparts)) {

            $this->_multiparts = array();

            if (!$this->isContentType('multipart/mixed')) {
                throw new Exception('Response is not multipart');
            }

            // Step 1. Get boundary

            preg_match('/boundary=([^";]+)/i', $this->getContentType(), $matches);

            if (empty($matches[1])) {
                throw new Exception('Boundary not found');
            }

            $boundary = $matches[1];

            // Step 2. Split by boundary and remove first and last parts if needed

            $parts = explode('--' . $boundary . '', $this->text()); //TODO Handle as stream

            if (empty(trim($parts[0]))) {
                array_shift($parts);
            }

            if (trim($parts[count($parts) - 1]) == '--') {
                array_pop($parts);
            }

            if (count($parts) == 0) {
                throw new Exception('No parts found');
            }

            // Step 3. Create status info object

            $statusInfoPart = array_shift($parts);
            $statusInfoObj = new self(null,
                self::createResponse(trim($statusInfoPart), $this->response()->getStatusCode())
            );
            $statusInfo = $statusInfoObj->json()->response;

            // Step 4. Parse all parts into Response objects

            foreach ($parts as $i => $part) {

                $partInfo = $statusInfo[$i];

                $this->_multiparts[] = new self(null, self::createResponse(trim($part), $partInfo->status));

            }

        }

        return $this->_multiparts;

    }
1152962
public function getMultilingualSection()
    {
        $result = null;
        $msID = $this->getMultilingualSectionID();
        if ($msID !== 0) {
            $s = Section::getByID($msID);
            if ($s) {
                $result = $s;
            }
        }

        return $result;
    }
1242750
public DocumentFragment rtree(XPathContext support)
  {
    DocumentFragment docFrag = null;
    int result = rtf();

    if (DTM.NULL == result)
    {
      DTM frag = support.createDocumentFragment();

      // %OPT%
      frag.appendTextChild(str());

      docFrag = (DocumentFragment)frag.getNode(frag.getDocument());
    }
    else
    {
      DTM frag = support.getDTM(result);
      docFrag = (DocumentFragment)frag.getNode(frag.getDocument());
    }

    return docFrag;
  }
672946
def getFragment(self):
        """"""
        # assert self.innerHTML
        fragment = self.fragmentClass()
        self.openElements[0].reparentChildren(fragment)
        return fragment
1245218
@Override
    public LabelledDocument nextDocument() {
        LabelledDocument document = currentIterator.next();
        for (String label : document.getLabels()) {
            labels.storeLabel(label);
        }

        return document;
    }
244017
public function recurseThroughResult(array $pathSegments): Result
    {
        if (count($pathSegments) === 0) {
            return $this;
        }

        $propertyName = array_shift($pathSegments);

        if (!isset($this->propertyResults[$propertyName])) {
            $newResult = new Result();
            $newResult->setParent($this);
            $this->propertyResults[$propertyName] = $newResult;
        }

        /** @var Result $result */
        $result = $this->propertyResults[$propertyName];
        return $result->recurseThroughResult($pathSegments);
    }
95126
private boolean goToNextDoc() throws IOException {
    if (docId == NO_MORE_DOCS) {
      return true;
    } else {
      // try to find docId with match for all items from sequence
      Integer spanDocId;
      Integer newDocId = null;
      Integer minOptionalDocId = null;
      boolean allItemsOptional = true;
      for (QueueItem item : queueSpans) {
        if (!item.sequenceSpans.optional) {
          allItemsOptional = false;
        }
        if (!item.noMoreDocs) {
          if (item.sequenceSpans.spans == null) {
            spanDocId = NO_MORE_DOCS;
          } else if (newDocId == null) {
            spanDocId = item.sequenceSpans.spans.nextDoc();
          } else {
            if (!item.sequenceSpans.optional) {
              spanDocId = item.sequenceSpans.spans.advance(newDocId);
            } else {
              if (item.sequenceSpans.spans.docID() == -1
                  || newDocId > item.sequenceSpans.spans.docID()) {
                spanDocId = item.sequenceSpans.spans.advance(newDocId);
              } else {
                spanDocId = item.sequenceSpans.spans.docID();
              }
            }
          }
          if (spanDocId.equals(NO_MORE_DOCS)) {
            item.noMoreDocs = true;
            if (!item.sequenceSpans.optional) {
              // a not optional span has NO_MORE_DOCS: stop
              docId = NO_MORE_DOCS;
              return true;
            }
          } else if (!spanDocId.equals(newDocId)) {
            // last found spanDocId not equal to potential new docId
            if (newDocId != null) {
              if (!item.sequenceSpans.optional) {
                // move also previous spans to at least spanDocId
                advance(spanDocId);
                return true;
              }
              // define potential new docId
            } else {
              if (!item.sequenceSpans.optional) {
                // previous optional span with lower docId
                if ((minOptionalDocId != null)
                    && (minOptionalDocId < spanDocId)) {
                  advance(spanDocId);
                  return true;
                } else {
                  // use spanDocId as potential newDocId
                  newDocId = spanDocId;
                }
              } else {
                // remember minimum docId optional spans
                minOptionalDocId = (minOptionalDocId == null) ? spanDocId
                    : Math.min(minOptionalDocId, spanDocId);
              }
            }
          }
        }
      }
      // if all items are optional
      if (allItemsOptional && newDocId == null && minOptionalDocId != null) {
        newDocId = minOptionalDocId;
      }
      // nothing found
      if (newDocId == null) {
        docId = NO_MORE_DOCS;
        return true;
      } else {
        docId = newDocId;
        ignoreItem.advanceToDoc(docId);
        // try and glue together
        if (findMatches()) {
          return true;
          // no matches
        } else {
          resetQueue();
          return false;
        }
      }
    }
  }
1228144
public Element toRootElement() {
        Document doc = null;
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.newDocument();
        } catch (Exception e) {
            jlogger.log(Level.SEVERE, "validate", e);
            e.printStackTrace();
            // Fortify Mod: if we get here then there is no point in going further
            return null;
        }
        Element root = doc.createElement("errors");
        doc.appendChild(root);
        ErrorIterator errIterator = iterator();
        while (errIterator.hasNext()) {
            ValidationError err = errIterator.next();
            Element elem = doc.createElement("error");
            elem.setTextContent(err.getMessage());
            root.appendChild(elem);
        }
        return root;
    }