本文整理汇总了Java中org.codehaus.jackson.node.ArrayNode.addObject方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayNode.addObject方法的具体用法?Java ArrayNode.addObject怎么用?Java ArrayNode.addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.node.ArrayNode
的用法示例。
在下文中一共展示了ArrayNode.addObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countersToJSON
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
@Private
public JsonNode countersToJSON(Counters counters) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode nodes = mapper.createArrayNode();
if (counters != null) {
for (CounterGroup counterGroup : counters) {
ObjectNode groupNode = nodes.addObject();
groupNode.put("NAME", counterGroup.getName());
groupNode.put("DISPLAY_NAME", counterGroup.getDisplayName());
ArrayNode countersNode = groupNode.putArray("COUNTERS");
for (Counter counter : counterGroup) {
ObjectNode counterNode = countersNode.addObject();
counterNode.put("NAME", counter.getName());
counterNode.put("DISPLAY_NAME", counter.getDisplayName());
counterNode.put("VALUE", counter.getValue());
}
}
}
return nodes;
}
示例2: extractTags
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
/**
* Extracts the tags from a note and creates a JSON array.
*
* @param item
* the item that holds the note data
* @return the array
*/
private ArrayNode extractTags(NoteData item) {
ArrayNode result = JsonHelper.getSharedObjectMapper().createArrayNode();
// create items manually because TagData POJO is incompatible to REST API TagResource
if (item.getTags() != null) {
for (TagData tagItem : item.getTags()) {
ObjectNode tag = result.addObject();
tag.put("tagId", tagItem.getId());
tag.put("tagStoreAlias", tagItem.getTagStoreAlias());
tag.put("tagStoreTagId", tagItem.getTagStoreTagId());
String languageCode = null;
if (tagItem.getLocale() != null) {
languageCode = tagItem.getLocale().toString().toLowerCase();
}
tag.put("languageCode", languageCode);
tag.put("name", tagItem.getName());
tag.put("description", tagItem.getDescription());
tag.put("defaultName", tagItem.getDefaultName());
}
}
return result;
}
示例3: writeGaugeAtributeValues
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
private void writeGaugeAtributeValues(SortedMap<String, OdfAttributeGauge> attrMap, String ns, String elementName, ArrayNode attrArray) throws XMLStreamException {
for (String attrName : attrMap.keySet()) {
ObjectNode attrObj= attrArray.addObject();
attrObj.put("name", attrName);
List<Integer> hits = new ArrayList<Integer>();
// Integer totalHits = 0;
SortedMap<String, OdfAttributeGauge> gsAttributesGaugeMap = gauges.getNamespaceGaugeMap().get(ns).get(elementName)
.getAttributesGaugeMap();
List<Integer> hitlist = gsAttributesGaugeMap.get(attrName).getHits();
if(hitlist.size() > 0) {
ArrayNode hitsArray = attrObj.putArray("hits");
for (Integer hit : hitlist) {
hitsArray.add(hit);
}
}
}
}
示例4: putResultArray
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
public void putResultArray(ObjectNode d, WikiSimComparableResultList<Double> results) throws Exception {
ArrayNode a = d.putArray("citolytics");
for (WikiSimComparableResult<Double> result : results) {
ObjectNode r = a.addObject();
r.put("title", result.getName());
if (includeIds)
r.put("id", String.valueOf(result.getId()));
if (!disableScores) {
// Test for too large scores (avoid Infinity values)
if(result.getSortField1() > Integer.MAX_VALUE)
throw new Exception("Recommendation score > Integer.MAX_VALUE: " + result.getSortField1());
r.put("score", result.getSortField1());
}
}
}
示例5: createJsonNoteObject
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
/**
* Creates a JSON object with data about a note.
*
* @param item
* the list item from which the data will be extracted
* @param isAutosave
* whether the item is an autosave or published note
* @param plaintextOnly
* true if the client expects the content in plaintext and not HTML
* @return the JSON object
*/
private ObjectNode createJsonNoteObject(NoteData item, boolean isAutosave, boolean plaintextOnly) {
ObjectNode jsonObj = JsonHelper.getSharedObjectMapper().createObjectNode();
if (plaintextOnly) {
jsonObj.put("content", HTMLHelper.htmlToPlaintextExt(item.getContent(), false));
} else {
jsonObj.put("content", item.getContent());
}
jsonObj.put("tags", extractTags(item));
jsonObj.put("usersToNotify", extractUsersToNotify(item));
jsonObj.put("attachments", extractAttachments(item));
jsonObj.put("isDirectMessage", item.isDirect());
jsonObj.put("isAutosave", isAutosave);
if (item.getBlog() != null) {
jsonObj.put("targetBlog", BlogSearchHelper.createBlogSearchJSONResult(item.getBlog()
.getId(), item.getBlog().getAlias(), item.getBlog().getTitle(), false));
}
if (item.getObjectProperties() != null) {
ArrayNode properties = jsonObj.putArray("properties");
for (StringPropertyTO property : item.getObjectProperties()) {
ObjectNode propertyJson = properties.addObject();
propertyJson.put("keyGroup", property.getKeyGroup());
propertyJson.put("key", property.getPropertyKey());
propertyJson.put("value", property.getPropertyValue());
}
}
return jsonObj;
}
示例6: getTagSuggestions
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
/**
* Create a serialized JSON array of objects that describe the available tag suggestions for a
* given tag store type.
*
* @param tagStoreType
* the tag store type for which the suggestions should be retrieved
* @param assignedTagsOnly
* only retrieve suggestions of tags that are already assigned to a Communote entity
* @param aliasAttribute
* name of the attribute in the JSON object that holds the tag suggestion alias
* @param titleAttribute
* name of the attribute in the JSON object that holds the localized name of the
* suggestion
* @param providerAttribute
* name of the attribute in the JSON object that holds the alias of the tag
* suggestion provider
* @param request
* the current request
* @return the serialized JSON array
*/
public String getTagSuggestions(TagStoreType tagStoreType, boolean assignedTagsOnly,
String aliasAttribute, String titleAttribute, String providerAttribute,
HttpServletRequest request) {
List<TagSuggestionConfiguration> configs = ServiceLocator.instance()
.getService(TagSuggestionManagement.class)
.getTagSuggestionConfigurations(tagStoreType, assignedTagsOnly);
ArrayNode resultObj = JsonHelper.getSharedObjectMapper().createArrayNode();
if (configs.size() > 0) {
Locale locale = SessionHandler.instance().getCurrentLocale(request);
String msgKey;
for (TagSuggestionConfiguration config : configs) {
ObjectNode suggestion = resultObj.addObject();
suggestion.put(aliasAttribute, config.getTagSuggestionAlias());
suggestion.put(providerAttribute, config.getTagSuggestionProviderAlias());
// use simpler static category title if there is only one category which is the
// built-in default
if (configs.size() == 1 && config.getTagSuggestionAlias().startsWith("Default")) {
msgKey = "autosuggest.title.tags";
} else {
msgKey = config.getLocalizedName();
}
suggestion.put(titleAttribute,
ResourceBundleManager.instance().getText(msgKey, locale));
}
}
return JsonHelper.writeJsonTreeAsString(resultObj);
}
示例7: writeSources
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
protected void writeSources(List<String> sourceNames) throws XMLStreamException {
Integer sourceNumber = 1;
ObjectNode srcs = rootArray.addObject();
srcs.put("name", "sources");
ArrayNode an = srcs.putArray(CHILDREN_TAG);
for (String src : sourceNames) {
ObjectNode doc = an.addObject();
doc.put("source", src);
// doc.put("run", sd.getRunDate());
sourceNumber += 1;
}
}
示例8: writeGauges
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
/**
* Write out the gauges for each of the sources
* Iterate the namespaces and then the attributes within each element
*
* We could make the attribute gauges optional?
*
* @param odfGauges
* @throws XMLStreamException
*/
public void writeGauges() throws XMLStreamException {
ObjectNode gaugesObj = rootArray.addObject();
gaugesObj.put("name", GAUGES_TAG);
ArrayNode gaugesArray = gaugesObj.putArray(HIDDEN_CHILDREN_TAG);
// we can just use the first gauge set as the the key to iterate from
OdfGaugeStore odfGauges = gauges;
Integer totalHits = 0;
List<Integer> nsHits = new ArrayList<Integer>();
nsHits.add(0);
ObjectNode nsCollector = gaugesArray.addObject();
nsCollector.put("name", NAMESPACE_TAG);
ArrayNode nsArray = nsCollector.putArray(HIDDEN_CHILDREN_TAG);
SortedMap<String, SortedMap<String, OdfElementGauge>> nsGaugeMap = odfGauges.getNamespaceGaugeMap();
//for each namespace iterate and write its element hits
for (String ns : nsGaugeMap.keySet()) {
//initialise the array as all 0 and the totalHits too
for(int i=0; i<nsHits.size(); i++) {
nsHits.set(i, 0);
}
totalHits = 0;
ObjectNode nsObj = nsArray.addObject();
nsObj.put("name", ns);
ArrayNode elArray = nsObj.putArray(HIDDEN_CHILDREN_TAG);
SortedMap<String, OdfElementGauge> gaugeMap = nsGaugeMap.get(ns);
for (String elementName : gaugeMap.keySet()) {
int j = 0;
List<Integer> eleHits = writeGaugeValue(ns, elementName, elArray);
//we will need to add nsHits elements
while(eleHits.size() > nsHits.size()) {
nsHits.add(0);
}
for (Integer h : eleHits) {
//prob if more than one element gauge....
//need parallel size of ns gauges?
//where are the ns hits used? only in the table?
Integer t = nsHits.get(j);
t += h;
nsHits.set(j, t);
totalHits += h;
j++;
}
}
ArrayNode hitsArray = nsObj.putArray("hits");
for (Integer hit : nsHits) {
hitsArray.add(hit);
}
}
}
示例9: writeManifest
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
public void writeManifest(String name, SortedSet<String> files) throws XMLStreamException {
ObjectNode manifestObj = rootArray.addObject();
manifestObj.put("name", MANIFEST_TAG);
ArrayNode manifestArray= manifestObj.putArray(HIDDEN_CHILDREN_TAG);
for(String file : files)
{
ObjectNode fileObj= manifestArray.addObject();
fileObj.put("name", file);
}
}
示例10: writeSources
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
protected void writeSources() throws XMLStreamException {
Integer sourceNumber = 1;
ObjectNode srcs = rootArray.addObject();
srcs.put("name", "sources");
ArrayNode an = srcs.putArray(CHILDREN_TAG);
for (StylesData sd : styles) {
ObjectNode doc = an.addObject();
doc.put("source", sd.getDocumentName());
doc.put("run", sd.getRunDate());
sourceNumber += 1;
}
}
示例11: writeFamilies
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
/**
* Iterate through the styles families
* Generate the default properties data
* walk the tree of styles and note the hits of each
*
* Possible issue is when a style has been removed from a document
* or when a new style has been added
*
* Maybe we need to normalise/merge the style sets first?
* Or we will get into trouble with the hit details
*
*
*
* @param styleNum
*
* @param styleFamiliesMap
* @param stylesUsed
* @throws XMLStreamException
*/
public Integer writeFamilies(SortedMap<String, OdfeStyleFamily> styleFamiliesMap, SortedMap<String, Integer> stylesUsed) throws XMLStreamException {
Integer familiesHits = 0;
ObjectNode familiesObj = rootArray.addObject();
familiesObj.put("name", "families");
ArrayNode familiesArray = familiesObj.putArray(CHILDREN_TAG);
for(String family : styleFamiliesMap.keySet()) {
Integer totalHits = 0;
OdfeStyleFamily styleFamily = styleFamiliesMap.get(family);
OdfDefaultStyle defaultStyle = styleFamily.getDefaultStyle();
ObjectNode familyObj = familiesArray.addObject();
familyObj.put("name", family);
ArrayNode familyArray = familyObj.putArray(HIDDEN_CHILDREN_TAG);
if (defaultStyle != null) {
ObjectNode defaultObj = familyArray.addObject();
defaultObj.put("name", "Default");
ArrayNode defaultArray = defaultObj.putArray(HIDDEN_CHILDREN_TAG);
writePropertySets(defaultArray, defaultStyle);
}
Iterable<FamilyStyleNode> roots = styleFamily.getFamilyStyles();
for(FamilyStyleNode familyStyle : roots) {
totalHits += walkFamilyTree(familyArray, familyStyle, stylesUsed);
}
if(totalHits > 0) {
familyObj.put("totalHits", totalHits);
familiesHits += totalHits;
}
}
if(familiesHits > 0) {
familiesObj.put("totalHits", familiesHits);
}
return familiesHits;
}
示例12: addTreeNode
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
/**
* @param contentsArray
* @param name
* @param diffType
* @return
*/
protected ArrayNode addTreeNode(ArrayNode contentsArray, String name, boolean hidden) {
ObjectNode familyObj = contentsArray.addObject();
familyObj.put("name", name);
ArrayNode treeArray;
if (hidden == true) {
treeArray = familyObj.putArray(HIDDEN_CHILDREN_TAG);
}
else {
treeArray = familyObj.putArray(CHILDREN_TAG);
}
return treeArray;
}
示例13: addDiffTreeNode
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
protected ArrayNode addDiffTreeNode(ArrayNode contentsArray, String name, boolean hidden, DiffType diffType) {
ObjectNode familyObj = contentsArray.addObject();
familyObj.put("name", name);
familyObj.put("diff", diffType.toString());
ArrayNode treeArray;
if (hidden == true) {
treeArray = familyObj.putArray(HIDDEN_CHILDREN_TAG);
}
else {
treeArray = familyObj.putArray(CHILDREN_TAG);
}
return treeArray;
}
示例14: walkFamilyTree
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
protected Integer walkFamilyTree(ArrayNode styleArray, FamilyStyleNode familyStyle, SortedMap<String, Integer> stylesUsed)
throws XMLStreamException {
OdfStyle style = familyStyle.getStyle();
ObjectNode familyObj = styleArray.addObject();
familyObj.put("name", style.getStyleNameAttribute());
// ArrayNode familyStyleArray = addTreeObject(familyObj, style.getStyleNameAttribute(), true);
List<Integer> hitList = new ArrayList<Integer>();
Integer totalHits = 0;
for (StylesData sd : styles) {
Integer hits = sd.getStylesUsed().get(style.getStyleNameAttribute());
if (hits != null) {
hitList.add(hits);
totalHits += hits;
} else {
hitList.add(0);
}
}
if (totalHits > 0) {
ArrayNode hitsArray = familyObj.putArray("hits");
for (Integer hit : hitList) {
hitsArray.add(hit);
}
}
// get the style properties and iterate them
// basically should be a copy of what is in the original document
ArrayNode familyStyleArray = familyObj.putArray(HIDDEN_CHILDREN_TAG);
writePropertySets(familyStyleArray, style);
// recurse through the trees
Integer childHits = 0;
Iterable<FamilyStyleNode> children = familyStyle.getChildren();
for (FamilyStyleNode child : children) {
childHits += walkFamilyTree(familyStyleArray, child, stylesUsed);
}
if (childHits > 0) {
totalHits += childHits;
familyObj.put("totalHits", totalHits);
}
return totalHits;
}
示例15: writeAttributes
import org.codehaus.jackson.node.ArrayNode; //导入方法依赖的package包/类
private void writeAttributes(ArrayNode propsArray, NamedNodeMap attrs) throws XMLStreamException {
for (int i = 0; i < attrs.getLength(); i++) {
Node attr = attrs.item(i);
ObjectNode attrObj = propsArray.addObject();
attrObj.put(NAME_TAG, attr.getNodeName());
attrObj.put(VALUE_TAG, attr.getNodeValue());
}
}