Esri Geoportal Server
1.2.9

com.esri.gpt.control.georss
Class ExtJsonFeedWriter

java.lang.Object
  extended by com.esri.gpt.control.georss.ExtJsonFeedWriter
All Implemented Interfaces:
FeedWriter
Direct Known Subclasses:
DcatJsonFeedWriter

public class ExtJsonFeedWriter
extends Object
implements FeedWriter

JSON feed writer. Writes response in JSON (or pretty JSON) format.

Uses json.writer.className parameter from gpt.xml to create an instance. Creates default instance if parameter is empty.

Default implementation uses json.predicate.banned parameter from gpt.xml, which is a regular expression used to stop printing certain fields. Note that fields beginning with "index.sys.xml" are not printed by default; the only way to have it printed is to specify them explicitely in outFields request parameter.

See Also:
JsonSearchEngine

Field Summary
protected  RequestContext context
          request context
protected static IsoDateFormat DF
          ISO date format
protected static Logger LOG
          Logger.
protected  MessageBroker messageBroker
          message broker
protected  Map<String,String[]> parameterMap
          parameter map
protected  Pattern predicateBanned
          predicates
protected  RestQuery query
          original query
protected  PrintWriter writer
          print writer
 
Constructor Summary
ExtJsonFeedWriter(HttpServletRequest request, RequestContext context, PrintWriter writer, RestQuery query, Boolean pretty)
          Creates instance of the feed.
ExtJsonFeedWriter(Map<String,String[]> parameterMap, RequestContext context, PrintWriter writer, RestQuery query, Boolean pretty)
          Creates instance of the feed.
 
Method Summary
protected  Set<String> buildOutFieldsSet()
          Builds collection of names of fields for output.
protected  boolean checkAttr(String attrName)
          Checks if attribute of a given name can be printed.
protected  String coord(double x, double y)
          Makes coordinates.
static ExtJsonFeedWriter createInstance(HttpServletRequest request, RequestContext context, PrintWriter writer, RestQuery query, Boolean pretty)
          Creates instance of the feed writer.
static ExtJsonFeedWriter createInstance(Map<String,String[]> parameterMap, RequestContext context, PrintWriter writer, RestQuery query, Boolean pretty)
          Creates instance of the feed writer.
protected static String getConfigParam(String paramName)
          Gets configuration parameter.
 MessageBroker getMessageBroker()
          Gets message broker
protected  String getOutputSpatialReference()
          Gets output spatial reference.
protected  String getRequestParam(String paramName)
          Gets request parameter.
protected  String guessServiceUrn(ResourceIdentifier ri, ResourceLink link)
          Guesses URN of resource link type.
protected  boolean hasRequestParam(String paramName)
          Checks if parameter has even been supplied.
protected  void levelDown()
          Decreases level of indentation.
protected  void levelUp()
          Increases level of indentation.
protected  void print(boolean indent, String text)
          Prints a single line without ending it with a new line.
protected  void printAPI(boolean more)
          Prints bottom links.
protected  void printArg(String argName, Number argVal, boolean more)
          Prints argument.
protected  void printArg(String argName, String argVal, boolean more)
          Prints argument.
protected  boolean printAttr(boolean before, String argName, long argVal)
          Prints attribute.
protected  boolean printAttr(boolean before, String argName, String argVal)
          Prints attribute.
protected  void printAttributes(String name, IFeedRecord r, boolean more)
          Prints attributes.
protected  void printField(IFeedRecords.FieldMeta f, boolean more)
          Prints a field.
protected  void printGeometry(Envelope env, boolean more)
          Prints geometry.
protected  void printLink(ResourceIdentifier ri, ResourceLink link, boolean more)
          Prints a link.
protected  void printLink(String url, String tag, String label, String urn, boolean more)
          Prints link.
protected  void printLinks(ResourceLinks links, boolean more)
          Prints all links.
protected  void println(String text)
          Prints a single line.
protected  void printPolygon(Envelope env)
          Prints polygon.
protected  void printPolygonShape(String name, Envelope env, boolean more)
          Prints a polygon.
protected  void printRecord(IFeedRecord r, Envelope env, boolean more)
          Prints record.
protected  void printRecords(IFeedRecords records, boolean more)
          Prints all records.
protected  void printResources(ResourceLinks links, boolean more)
          Prints all resources.
protected  void printTab()
          Prints tabulator.
 void setMessageBroker(MessageBroker messageBroker)
          Sets message broker
protected  String sp()
          Creates a single space.
 void write(IFeedRecords records)
          Writers records.
protected  void writeCountOnly(int numberOfHits)
          Writes number of matching records only.
protected  void writeIdsOnly(List<IFeedRecord> records)
          Writes records ids only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final Logger LOG
Logger.


DF

protected static final IsoDateFormat DF
ISO date format


parameterMap

protected Map<String,String[]> parameterMap
parameter map


context

protected final RequestContext context
request context


writer

protected PrintWriter writer
print writer


query

protected RestQuery query
original query


predicateBanned

protected Pattern predicateBanned
predicates


messageBroker

protected MessageBroker messageBroker
message broker

Constructor Detail

ExtJsonFeedWriter

public ExtJsonFeedWriter(HttpServletRequest request,
                         RequestContext context,
                         PrintWriter writer,
                         RestQuery query,
                         Boolean pretty)
Creates instance of the feed.

Parameters:
request - HTTP request
context - request context
writer - writer to write feed
query - query
pretty - true to print pretty response

ExtJsonFeedWriter

public ExtJsonFeedWriter(Map<String,String[]> parameterMap,
                         RequestContext context,
                         PrintWriter writer,
                         RestQuery query,
                         Boolean pretty)
Creates instance of the feed.

Parameters:
parameterMap - parameter map
context - request context
writer - writer to write feed
query - query
pretty - true to print pretty response
Method Detail

createInstance

public static ExtJsonFeedWriter createInstance(Map<String,String[]> parameterMap,
                                               RequestContext context,
                                               PrintWriter writer,
                                               RestQuery query,
                                               Boolean pretty)
Creates instance of the feed writer.

Parameters:
parameterMap - parameter map
context - request context
writer - writer
query - query
pretty - true for 'pretty' JSON output
Returns:
instance of ExtJsonFeedWriter

createInstance

public static ExtJsonFeedWriter createInstance(HttpServletRequest request,
                                               RequestContext context,
                                               PrintWriter writer,
                                               RestQuery query,
                                               Boolean pretty)
Creates instance of the feed writer.

Parameters:
request - HTTP servlet request
context - request context
writer - writer
query - query
pretty - true for 'pretty' JSON output
Returns:
instance of ExtJsonFeedWriter

setMessageBroker

public void setMessageBroker(MessageBroker messageBroker)
Sets message broker

Parameters:
messageBroker - the messageBroker to set

getMessageBroker

public MessageBroker getMessageBroker()
Gets message broker

Returns:
the messageBroker

write

public void write(IFeedRecords records)
Description copied from interface: FeedWriter
Writers records.

Specified by:
write in interface FeedWriter
Parameters:
records - records to write

writeCountOnly

protected void writeCountOnly(int numberOfHits)
Writes number of matching records only.

Parameters:
numberOfHits -

writeIdsOnly

protected void writeIdsOnly(List<IFeedRecord> records)
Writes records ids only.

Parameters:
records - list of records

printField

protected void printField(IFeedRecords.FieldMeta f,
                          boolean more)
Prints a field.

Parameters:
f - field
more - more fields

printRecords

protected void printRecords(IFeedRecords records,
                            boolean more)
Prints all records.

Parameters:
records - records to print
more - true if more info will be printed after that section

printRecord

protected void printRecord(IFeedRecord r,
                           Envelope env,
                           boolean more)
Prints record.

Parameters:
r - record to print
env - envelope
more - true if more info will be printed after that section

printAttributes

protected void printAttributes(String name,
                               IFeedRecord r,
                               boolean more)
Prints attributes.

Parameters:
name - name
r - record
more - true if more info will be printed after that section

printGeometry

protected void printGeometry(Envelope env,
                             boolean more)
Prints geometry.

Parameters:
env - geometry
more - flag to indicate if there will be more arguments

printPolygonShape

protected void printPolygonShape(String name,
                                 Envelope env,
                                 boolean more)
Prints a polygon.

Parameters:
env -

printPolygon

protected void printPolygon(Envelope env)
Prints polygon.

Parameters:
env - polygon to print

printLinks

protected void printLinks(ResourceLinks links,
                          boolean more)
Prints all links.

Parameters:
links - collection of resource links
more - flag to indicate if there will be more arguments

printResources

protected void printResources(ResourceLinks links,
                              boolean more)
Prints all resources.

Parameters:
links - collection of resource links
more - flag to indicate if there will be more arguments

printLink

protected final void printLink(ResourceIdentifier ri,
                               ResourceLink link,
                               boolean more)
Prints a link.

Parameters:
ri - resource identifier
link - resource link
more - flag to indicate if there will be more arguments

printLink

protected void printLink(String url,
                         String tag,
                         String label,
                         String urn,
                         boolean more)
Prints link.

Parameters:
url - url
tag - tag
label - label
urn - classified as urn
more - flag to indicate if there will be more arguments

printAPI

protected void printAPI(boolean more)
Prints bottom links.

Parameters:
more - more links

guessServiceUrn

protected String guessServiceUrn(ResourceIdentifier ri,
                                 ResourceLink link)
Guesses URN of resource link type.

Parameters:
ri - instance of resource identifier
link - resource link
Returns:
URN of resource link type

printArg

protected final void printArg(String argName,
                              String argVal,
                              boolean more)
Prints argument.

Parameters:
argName - argument name
argVal - argument value
more - flag to indicate if there will be more arguments

printArg

protected final void printArg(String argName,
                              Number argVal,
                              boolean more)
Prints argument.

Parameters:
argName - argument name
argVal - argument value
more - flag to indicate if there will be more arguments

printAttr

protected final boolean printAttr(boolean before,
                                  String argName,
                                  String argVal)
Prints attribute.

Parameters:
before - true if anything has been printed before
argName - argument name
argVal - argument value
Returns:
true if anything has been printed

printAttr

protected final boolean printAttr(boolean before,
                                  String argName,
                                  long argVal)
Prints attribute.

Parameters:
before - true if anything has been printed before
argName - argument name
argVal - argument value
Returns:
true if anything has been printed

coord

protected String coord(double x,
                       double y)
Makes coordinates.

Parameters:
x - x coordinate
y - y coordinate
Returns:
coordinate in JSON format

checkAttr

protected boolean checkAttr(String attrName)
Checks if attribute of a given name can be printed.

Parameters:
attrName - attribute name
Returns:
true if attribute can be printed

buildOutFieldsSet

protected Set<String> buildOutFieldsSet()
Builds collection of names of fields for output.

Returns:
set of fields names.

getConfigParam

protected static String getConfigParam(String paramName)
Gets configuration parameter.

Parameters:
paramName - parameter name
Returns:
parameter value

getRequestParam

protected String getRequestParam(String paramName)
Gets request parameter.

Parameters:
paramName - parameter name
Returns:
request parameter

hasRequestParam

protected boolean hasRequestParam(String paramName)
Checks if parameter has even been supplied.

Parameters:
paramName - parameter name
Returns:
true if parameter is present (even an empty string)

getOutputSpatialReference

protected String getOutputSpatialReference()
Gets output spatial reference.

Returns:
output spatial reference. Default: 4326.

levelUp

protected final void levelUp()
Increases level of indentation.


levelDown

protected final void levelDown()
Decreases level of indentation.


println

protected final void println(String text)
Prints a single line. Depending on the 'pretty' flag, line is indented or not.

Parameters:
text - text to print

print

protected final void print(boolean indent,
                           String text)
Prints a single line without ending it with a new line.

Parameters:
indent - true to indent the line
text - text to print

printTab

protected final void printTab()
Prints tabulator. Tabulator width depends on the indentation level.


sp

protected final String sp()
Creates a single space. Depending on the 'pretty' flag, it's either a space or no space at all.

Returns:
single space

Esri Geoportal Server
1.2.9

Copyright 2011 Environmental Systems Research Institute. All rights reserved. Use is subject to license terms.