// Returns the document's source, as visible, if docId is 0, returns top document source.
332099
func (t *Tab) GetPageSource(docNodeId int) (string, error) {
	if docNodeId == 0 {
		docNodeId = t.GetTopNodeId()
	}
	doc, ok := t.getElement(docNodeId)
	if !ok {
		return "", &ElementNotFoundErr{Message: fmt.Sprintf("docNodeId %d not found", docNodeId)}
	}
	outerParams := &gcdapi.DOMGetOuterHTMLParams{NodeId: doc.id}
	return t.DOM.GetOuterHTMLWithParams(outerParams)
}
206952
func (s *ScriptSort) Source() (interface{}, error) {
	if s.script == nil {
		return nil, errors.New("ScriptSort expected a script")
	}
	source := make(map[string]interface{})
	x := make(map[string]interface{})
	source["_script"] = x

	src, err := s.script.Source()
	if err != nil {
		return nil, err
	}
	x["script"] = src

	x["type"] = s.typ

	if s.ascending {
		x["order"] = "asc"
	} else {
		x["order"] = "desc"
	}
	if s.sortMode != nil {
		x["mode"] = *s.sortMode
	}
	if s.nestedFilter != nil {
		src, err := s.nestedFilter.Source()
		if err != nil {
			return nil, err
		}
		x["nested_filter"] = src
	}
	if s.nestedPath != nil {
		x["nested_path"] = *s.nestedPath
	}
	if s.nestedSort != nil {
		src, err := s.nestedSort.Source()
		if err != nil {
			return nil, err
		}
		x["nested"] = src
	}
	return source, nil
}
523235
func GetDataSourceByName(c *m.ReqContext) Response {
	query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}

	if err := bus.Dispatch(&query); err != nil {
		if err == m.ErrDataSourceNotFound {
			return Error(404, "Data source not found", nil)
		}
		return Error(500, "Failed to query datasources", err)
	}

	dtos := convertModelToDtos(query.Result)
	dtos.ReadOnly = true
	return JSON(200, &dtos)
}
530910
func (cr *Context) PopGroupToSource() {
	C.cairo_pop_group_to_source(cr.Ptr)
	if err := cr.status(); err != nil {
		panic(err)
	}
}
945425
func (q *MoreLikeThisQuery) Source() (interface{}, error) {
	// {
	//   "match_all" : { ... }
	// }
	if len(q.docs) == 0 {
		return nil, errors.New(`more_like_this requires some documents to be "liked"`)
	}

	source := make(map[string]interface{})

	params := make(map[string]interface{})
	source["more_like_this"] = params

	if len(q.fields) > 0 {
		params["fields"] = q.fields
	}

	var likes []interface{}
	for _, doc := range q.docs {
		src, err := doc.Source()
		if err != nil {
			return nil, err
		}
		likes = append(likes, src)
	}
	params["like"] = likes

	if len(q.unlikeDocs) > 0 {
		var dontLikes []interface{}
		for _, doc := range q.unlikeDocs {
			src, err := doc.Source()
			if err != nil {
				return nil, err
			}
			dontLikes = append(dontLikes, src)
		}
		params["unlike"] = dontLikes
	}

	if q.minimumShouldMatch != "" {
		params["minimum_should_match"] = q.minimumShouldMatch
	}
	if q.minTermFreq != nil {
		params["min_term_freq"] = *q.minTermFreq
	}
	if q.maxQueryTerms != nil {
		params["max_query_terms"] = *q.maxQueryTerms
	}
	if len(q.stopWords) > 0 {
		params["stop_words"] = q.stopWords
	}
	if q.minDocFreq != nil {
		params["min_doc_freq"] = *q.minDocFreq
	}
	if q.maxDocFreq != nil {
		params["max_doc_freq"] = *q.maxDocFreq
	}
	if q.minWordLength != nil {
		params["min_word_length"] = *q.minWordLength
	}
	if q.maxWordLength != nil {
		params["max_word_length"] = *q.maxWordLength
	}
	if q.boostTerms != nil {
		params["boost_terms"] = *q.boostTerms
	}
	if q.boost != nil {
		params["boost"] = *q.boost
	}
	if q.analyzer != "" {
		params["analyzer"] = q.analyzer
	}
	if q.failOnUnsupportedField != nil {
		params["fail_on_unsupported_field"] = *q.failOnUnsupportedField
	}
	if q.queryName != "" {
		params["_name"] = q.queryName
	}
	if q.include != nil {
		params["include"] = *q.include
	}

	return source, nil
}
298717
func (desDoc *DesignDoc) getRev(doc *Document) (error, string) {

	type GetDocResp struct {
		Error string `json:"error"`
		Ok    bool   `json:"ok"`
		Id    string `json:"_id"`
		Rev   string `json:"_rev"`
	}

	result := new(GetDocResp)
	docBytes, err := doc.GetDocument()
	if err != nil {
		return err, ""
	}

	err = json.Unmarshal(docBytes, result)

	if err != nil {
		return err, ""
	}

	return nil, result.Rev
}
1049400
func (a *BucketSortAggregation) Source() (interface{}, error) {
	source := make(map[string]interface{})
	params := make(map[string]interface{})
	source["bucket_sort"] = params

	if a.from != 0 {
		params["from"] = a.from
	}
	if a.size != -1 {
		params["size"] = a.size
	}

	if a.gapPolicy != "" {
		params["gap_policy"] = a.gapPolicy
	}

	// Parses sorters to JSON-serializable interface.
	if len(a.sorters) > 0 {
		sorters := make([]interface{}, len(a.sorters))
		params["sort"] = sorters
		for idx, sorter := range a.sorters {
			src, err := sorter.Source()
			if err != nil {
				return nil, err
			}
			sorters[idx] = src
		}
	}

	// Add metadata if available.
	if len(a.meta) > 0 {
		source["meta"] = a.meta
	}

	return source, nil
}
1201659
func (self *Context) GetDom() *goquery.Document {
	if self.dom == nil {
		self.initDom()
	}
	return self.dom
}
1191215
func NewSourceFromDB(DBConfigFile string) (Source, error) {
	// Load DB from cofiguration file
	db, err := dbconf.DBFromConfig(DBConfigFile)

	if err != nil {
		return nil, err
	}
	// Create accesor
	accessor := sql.NewAccessor(db)
	src := NewDBSource(accessor)

	return src, nil
}
1141521
func (q *ParentIdQuery) Source() (interface{}, error) {
	// {
	//   "parent_id" : {
	//       "type" : "blog",
	//       "id" : "1"
	//   }
	// }
	source := make(map[string]interface{})
	query := make(map[string]interface{})
	source["parent_id"] = query

	query["type"] = q.typ
	query["id"] = q.id
	if q.boost != nil {
		query["boost"] = *q.boost
	}
	if q.ignoreUnmapped != nil {
		query["ignore_unmapped"] = *q.ignoreUnmapped
	}
	if q.queryName != "" {
		query["_name"] = q.queryName
	}
	if q.innerHit != nil {
		src, err := q.innerHit.Source()
		if err != nil {
			return nil, err
		}
		query["inner_hits"] = src
	}
	return source, nil
}
1214147
func (s *MgetService) Source() (interface{}, error) {
	source := make(map[string]interface{})
	items := make([]interface{}, len(s.items))
	for i, item := range s.items {
		src, err := item.Source()
		if err != nil {
			return nil, err
		}
		items[i] = src
	}
	source["docs"] = items
	return source, nil
}
907459
func NewSource(name string, in io.Reader, idgen line.IDGenerator, capacity int, enableSep bool) *Source {
	s := &Source{
		name:       name,
		in:         in, // Note that this may be closed, so do not rely on it
		capacity:   capacity,
		enableSep:  enableSep,
		idgen:      idgen,
		ready:      make(chan struct{}),
		setupDone:  make(chan struct{}),
		ChanOutput: pipeline.ChanOutput(make(chan interface{})),
	}
	s.Reset()
	return s
}
271486
func (d Document) Get(k string) interface{} {
	v, _ := d[k]
	return v
}
266815
func getSourceMount(source string) (string, string, error) {
	// Ensure any symlinks are resolved.
	sourcePath, err := filepath.EvalSymlinks(source)
	if err != nil {
		return "", "", err
	}

	mi, err := mount.GetMounts(mount.ParentsFilter(sourcePath))
	if err != nil {
		return "", "", err
	}
	if len(mi) < 1 {
		return "", "", fmt.Errorf("Can't find mount point of %s", source)
	}

	// find the longest mount point
	var idx, maxlen int
	for i := range mi {
		if len(mi[i].Mountpoint) > maxlen {
			maxlen = len(mi[i].Mountpoint)
			idx = i
		}
	}
	return mi[idx].Mountpoint, mi[idx].Optional, nil
}
832153
func getSourceFromFile(file string, reader *sourceReader, fns graph.Nodes, start, end int) (graph.Nodes, string, error) {
	lineNodes := make(map[int]graph.Nodes)

	// Collect source coordinates from profile.
	const margin = 5 // Lines before first/after last sample.
	if start == 0 {
		if fns[0].Info.StartLine != 0 {
			start = fns[0].Info.StartLine
		} else {
			start = fns[0].Info.Lineno - margin
		}
	} else {
		start -= margin
	}
	if end == 0 {
		end = fns[0].Info.Lineno
	}
	end += margin
	for _, n := range fns {
		lineno := n.Info.Lineno
		nodeStart := n.Info.StartLine
		if nodeStart == 0 {
			nodeStart = lineno - margin
		}
		nodeEnd := lineno + margin
		if nodeStart < start {
			start = nodeStart
		} else if nodeEnd > end {
			end = nodeEnd
		}
		lineNodes[lineno] = append(lineNodes[lineno], n)
	}
	if start < 1 {
		start = 1
	}

	var src graph.Nodes
	for lineno := start; lineno <= end; lineno++ {
		line, ok := reader.line(file, lineno)
		if !ok {
			break
		}
		flat, cum := lineNodes[lineno].Sum()
		src = append(src, &graph.Node{
			Info: graph.NodeInfo{
				Name:   strings.TrimRight(line, "\n"),
				Lineno: lineno,
			},
			Flat: flat,
			Cum:  cum,
		})
	}
	if err := reader.fileError(file); err != nil {
		return nil, file, err
	}
	return src, file, nil
}
796050
func (e *Element) IsDocument() (bool, error) {
	e.lock.RLock()
	defer e.lock.RUnlock()

	if !e.ready {
		return false, &ElementNotReadyErr{}
	}
	return (e.nodeType == int(DOCUMENT_NODE)), nil
}
404538
func (r *BulkUpdateRequest) Doc(doc interface{}) *BulkUpdateRequest {
	r.doc = doc
	r.source = nil
	return r
}