dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30574
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15533: support COMMENTs in Nodes (will only be output in XML at the moment, since valid JSON does not su...
------------------------------------------------------------
revno: 15533
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-03 10:43:56 +0200
message:
support COMMENTs in Nodes (will only be output in XML at the moment, since valid JSON does not support comments)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeHint.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeHint.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeHint.java 2014-06-01 12:21:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeHint.java 2014-06-03 08:43:56 +0000
@@ -35,9 +35,27 @@
{
public enum Type
{
- XML_NAMESPACE,
- XML_ATTRIBUTE,
- XML_COLLECTION_WRAPPING
+ /**
+ * If the serializer supports namespacing, this hint can be used to set the namespace.
+ */
+ NAMESPACE,
+
+ /**
+ * If the serializer supports attributes, this hint can be used to hint that this
+ * node is a attribute or not.
+ */
+ ATTRIBUTE,
+
+ /**
+ * If the serializer has a notion of wrapping collection (like XML), this hint can be used to
+ * turn this feature on or off.
+ */
+ WRAP_COLLECTION,
+
+ /**
+ * If the serializer supports comments, this hint can be used to set a comment for a node.
+ */
+ COMMENT
}
private final Type type;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2014-06-02 22:47:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2014-06-03 08:43:56 +0000
@@ -80,6 +80,11 @@
{
writer.writeStartDocument( "UTF-8", "1.0" );
+ if ( rootNode.haveHint( NodeHint.Type.COMMENT ) )
+ {
+ writer.writeComment( (String) rootNode.getHint( NodeHint.Type.COMMENT ).getValue() );
+ }
+
writeStartElement( rootNode, writer );
for ( Node node : rootNode.getNodes() )
@@ -115,9 +120,9 @@
String value = String.format( "%s", simpleNode.getValue() );
- if ( simpleNode.haveHint( NodeHint.Type.XML_NAMESPACE ) )
+ if ( simpleNode.haveHint( NodeHint.Type.NAMESPACE ) )
{
- writer.writeAttribute( "", String.valueOf( simpleNode.getHint( NodeHint.Type.XML_NAMESPACE ).getValue() ), simpleNode.getName(), value );
+ writer.writeAttribute( "", String.valueOf( simpleNode.getHint( NodeHint.Type.NAMESPACE ).getValue() ), simpleNode.getName(), value );
}
else
{
@@ -157,11 +162,16 @@
private void dispatcher( Node node, XMLStreamWriter writer ) throws IOException, XMLStreamException
{
+ if ( node.haveHint( NodeHint.Type.COMMENT ) )
+ {
+ writer.writeComment( (String) node.getHint( NodeHint.Type.COMMENT ).getValue() );
+ }
+
switch ( node.getType() )
{
case SIMPLE:
- if ( node.haveHint( NodeHint.Type.XML_ATTRIBUTE ) &&
- (boolean) node.getHint( NodeHint.Type.XML_ATTRIBUTE ).getValue() )
+ if ( node.haveHint( NodeHint.Type.ATTRIBUTE ) &&
+ (boolean) node.getHint( NodeHint.Type.ATTRIBUTE ).getValue() )
{
renderSimpleNodeAttribute( (SimpleNode) node, writer );
}
@@ -176,9 +186,9 @@
case COLLECTION:
boolean useWrapping = true;
- if ( node.haveHint( NodeHint.Type.XML_COLLECTION_WRAPPING ) )
+ if ( node.haveHint( NodeHint.Type.WRAP_COLLECTION ) )
{
- useWrapping = (boolean) node.getHint( NodeHint.Type.XML_COLLECTION_WRAPPING ).getValue();
+ useWrapping = (boolean) node.getHint( NodeHint.Type.WRAP_COLLECTION ).getValue();
}
renderCollectionNode( (CollectionNode) node, writer, useWrapping );
@@ -188,9 +198,9 @@
private void writeStartElement( Node node, XMLStreamWriter writer ) throws XMLStreamException
{
- if ( node.haveHint( NodeHint.Type.XML_NAMESPACE ) )
+ if ( node.haveHint( NodeHint.Type.NAMESPACE ) )
{
- writer.writeStartElement( "", node.getName(), String.valueOf( node.getHint( NodeHint.Type.XML_NAMESPACE ).getValue() ) );
+ writer.writeStartElement( "", node.getName(), String.valueOf( node.getHint( NodeHint.Type.NAMESPACE ).getValue() ) );
}
else
{