def asJSON(tree): """ Return a String with a JSON map containing the name, id, and list of connections. """ json = StringBuilder() json.append('{"id" : "').append(tree.id).append('",\n') json.append(' "name" : "').append(getTitle(tree)).append('",\n') tableOut, tableIn = findConnections(tree) json.append(' "outgoing" : [') for target, num in sortMapByValue(tableOut, True): json.append(' ["').append(getTitle(target)).append('", ').append(num).append('],\n') if len(tableOut) > 0: json.setLength(json.length()-2) json.append('],\n') json.append(' "incoming" : [') for origin, num in sortMapByValue(tableIn, True): json.append(' ["').append(getTitle(origin)).append('", ').append(num).append('],\n') if len(tableIn) > 0: json.setLength(json.length()-2) json.append(']}\n') return json.toString()
def preprocess(text): """Tokenize and stop the input text.""" ts = StandardTokenizer(Lucene.get_version(), StringReader(text.lower())) ts = StopFilter(Lucene.get_version(), ts, StopAnalyzer.ENGLISH_STOP_WORDS_SET) string_builder = StringBuilder() ts.reset() char_term_attr = ts.addAttribute(CharTermAttribute.class_) while ts.incrementToken(): if string_builder.length() > 0: string_builder.append(" ") string_builder.append(char_term_attr.toString()) return string_builder.toString()
class FormattingVisitor(NodeVisitor): #--------------------------------------------------------------------------- # Name: __init__() # Role: constructor #--------------------------------------------------------------------------- def __init__(self, url): self.result = StringBuilder() self.header = re.compile('[hH][1-6]$') self.h3Text = '' #--------------------------------------------------------------------------- # Name: append() # Role: Add to the text #--------------------------------------------------------------------------- def append(self, text): newline = ['', '\n'][self.result.length() > 0] self.result.append(newline + text) #--------------------------------------------------------------------------- # Name: head() # Role: Invoked when open tag is first seen # Note: node.text() = "the combined text of this element and all its children" #--------------------------------------------------------------------------- def head(self, node, depth): name = node.nodeName() if re.match(self.header, name): if name[1] == '3': text = self.h3Text = node.text() if text.find('inherited') < 0: print '%s %s' % (name, text) self.append('%s: %s' % (name, text)) else: self.h3Text = '' #--------------------------------------------------------------------------- # Name: tail() # Role: Invoked when end tag is seen #--------------------------------------------------------------------------- def tail(self, node, depth): name = node.nodeName() if self.h3Text and name == 'table': print node print '-' * 50 #--------------------------------------------------------------------------- # Name: toString() # Role: Return the accumulated string #--------------------------------------------------------------------------- def toString(self): return str(self.result)
def buildPostDataFortoken(self, encodedJWT, softwareStatementId) : postParameters = LinkedHashMap() postParameters.put("scope", self.clientScopes) postParameters.put("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") postParameters.put("grant_type", "client_credentials") postParameters.put("client_id", softwareStatementId) postParameters.put("client_assertion", encodedJWT) postData = StringBuilder() for param in postParameters.entrySet(): if postData.length() != 0: postData.append('&') postData.append(URLEncoder.encode(param.getKey(), "UTF-8")) postData.append('=') postData.append(URLEncoder.encode(String(param.getValue()), "UTF-8").replace("+", "%20")) print "Post data: "+postData.toString() return postData.toString()
class FormattingVisitor(NodeVisitor): #--------------------------------------------------------------------------- # Name: __init__() # Role: constructor #--------------------------------------------------------------------------- def __init__(self, url): self.result = StringBuilder() #--------------------------------------------------------------------------- # Name: append() # Role: Add to the text #--------------------------------------------------------------------------- def append(self, text): newline = ['', '\n'][self.result.length() > 0] self.result.append(newline + text) #--------------------------------------------------------------------------- # Name: head() # Role: Invoked when tag is first seen #--------------------------------------------------------------------------- def head(self, node, depth): name = node.nodeName() if name == 'h3' and node.hasText(): text = node.text() if text.find('inherited') < 0: self.append('%s: %s' % (name, text)) #--------------------------------------------------------------------------- # Name: tail() # Role: Invoked when end tag is seen #--------------------------------------------------------------------------- def tail(self, node, depth): name = node.nodeName() if name == 'table': print node # What do we want / need to do here ? #--------------------------------------------------------------------------- # Name: toString() # Role: Return the accumulated string #--------------------------------------------------------------------------- def toString(self): return str(self.result)