Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This allows you to centralize common configuration items from multiple client configurations that you want to be the same for all client configurations, for example setting the extents for map views, or ensuring the same label for every ToC view. Something like this can also be performed using the set processing instruction, but this method makes it much easier.

Note

Snippets can only be used with client configuration items

To define a new snippet all you need to do is create the XML tags as you would if you were including them directly in the client configuration but rather than including them within the client configuration you create the tag at the top level within the config.xml file.

For example, lets assume that we want to create a snippet for the map extents set for in a map view, that way we can have multiple client configurations all with the same extents and only one location to set them, making it easier to change all of the clients at once.
So, if we currently have something like the following:

Code Block
xml
xml
titleExample, all be it incomplete, showing some client configurations
linenumberstrue
<client:config id="test">
	...
	<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:client="urn:com.cohga.html.client#1.0">
	<client:config id="test1">
		<view id="com.cohga.html.client.map.mapView">
		...
		<extents>
				<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
				<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
			<limit minx="320000" miny="5810000" maxx="360000" maxy="5840000"/>
		</extents>
		...
	</view>
	...
</client:config>

To create a new snippet from the extents in the above sample we would add

Code Block
xmlxml
linenumberstrue

<client:extents id="defaults">
	<initial minx="327098" miny="5811358" maxx="351971" </extents>
		</view>
	</client:config>

	<client:config id="test2">
		<view id="com.cohga.html.client.map.mapView">
			<extents>
				<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
				<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
	<limit minx="320000" miny="5810000		</extents>
		</view>
	</client:config>

	<client:config id="test3">
		<view id="com.cohga.html.client.map.mapView">
			<extents>
				<initial minx="327098" miny="5811358" maxx="360000351971" maxy="58400005827675"/>
</client:extents>

This would create a new snippet, called defaults of type extents. The id, defaults in the above example, isn't important and we can use anything that makes sense here (it's just used to refer to a specific snippet later when we want to use it). The type, extents in the above example, is important however and must be the same as the target tag that we're actually creating the snippet for, and it's the combination of the id and type that's used later on to include the snippet within a client configuration.

At the simplest to use the snippet within the client configuration simply requires a reference to the snippet to be added in place of the original tags, so to reference the new snippet we created you would use the following

...


<extents ref="defaults"/>

Anywhere this is found within the client configuration it will be replaced with the contents of the snippet we defined earlier. So to complete our example the client configuration would now become

Code Block
xmlxml
linenumberstrue

<client:config id="test">
	...
				<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
			</extents>
		</view>
	</client:config>
</config>

To create a new snippet for the extents in the above sample we would extract the part of the configuration we want to make common, like this:

Code Block
xml
xml
titleCommon extents extracted into a snippet with the id 'defaults'
linenumberstrue

<client:extents id="defaults">
	<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
	<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
</client:extents>

This would create a new snippet, called defaults of type extents. The id, defaults in the above example, isn't important and we can use anything that makes sense here (it's just used to refer to a specific snippet later when we want to use it). The type, extents in the above example, is important however and must be the same as the target tag that we're actually creating the snippet for, and it's the combination of the id and type that's used later on to include the snippet within a client configuration.

At the simplest to use the snippet within the client configuration simply requires a reference to the snippet to be added in place of the original tags, so to reference the new snippet we created you would replace the original extents tags with the following:

Code Block
xml
xml
titleReferencing the new snippet
linenumberstrue

<extents ref="defaults"/>

Anywhere this is found within the client configuration it will be replaced with the contents of the snippet we defined earlier.

So to complete our example I'll show the complete client configurations that will replace the original using snippets:

Code Block
xml
xml
2Example configurations altered to use a snippet
linenumberstrue

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:client="urn:com.cohga.html.client#1.0">
	<client:extents id="defaults">
		<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
		<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
	</client:extents>

	<client:config id="test1">
		<view id="com.cohga.html.client.map.mapView">
			<extents ref="defaults"/>
		</view>
	</client:config>

	<client:config id="test2">
		<view id="com.cohga.html.client.map.mapView">
			<extents ref="defaults"/>
		</view>
	</client:config>

	<client:config id="test3">
		<view id="com.cohga.html.client.map.mapView">
			<extents ref="defaults"/>
		</view>
	</client:config>
</config>

Refining snippets

Beyond just including the snippet in the client configuration you can also alter the snippet by including extra sub-tags in the reference.
For example if we wanted to setup one client configuration to have a different initial extent and another to add a limit extent we could do the following:

Code Block
xml
xml
titleAltering included snippets
linenumberstrue

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:client="urn:com.cohga.html.client#1.0">
	<client:extents id="defaults">
		<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
		<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
	</client:extents>

	<client:config id="test1">
		<view id="com.cohga.html.client.map.mapView">
			<extents ref="defaults"/>
		</view>
	</client:config>

	<client:config id="test2">
		<view id="com.cohga.html.client.map.mapView">
			<extents ref="defaults">
				<initial minx="327000" miny="5811000" maxx="330000" maxy="5813000"/>
			</extents>
		</view>
	</client:config>

	<client:config id="test3">
		<view id="com.cohga.html.client.map.mapView">
			<extents ref="defaults">
				<limit minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
			</extents>
		</view>
	</client:config>
</config>

this would be the equivalent of

Code Block
xml
xml
titleAltered example shown not using snippets
linenumberstrue

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:client="urn:com.cohga.html.client#1.0">
	<client:config id="test1">
		<view id="com.cohga.html.client.map.mapView">
			<extents>
				<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
				<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
			</extents>
		</view>
	</client:config>

	<client:config id="test2">
		<view id="com.cohga.html.client.map.mapView">
		...	<extents>
		<extents ref="defaults		<initial minx="327000" miny="5811000" maxx="330000" maxy="5813000"/>
		...
	</view>
	...
</client:config>

Refining snippets

Beyond just including the snippet in the client configuration you can also alter the snippet by including extra sub-tags in the reference. Assume for example that we wanted to setup a client configuration and re-use our extents snippet but in this particular client configuration we want to have a different initial extent, to do this we'd alter our client configuration as follows

Code Block
xmlxml
linenumberstrue

		<full minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
			</extents>
		</view>
	</client:config>

	<client:config id="customtest3">
	...
	<view id="com.cohga.html.client.map.mapView">
			...<extents>
		<extents ref="defaults">
			<initial		<initial minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
				<full minx="328098327098" miny="5811358" maxx="331971351971" maxy="58176755827675"/>
		</extents>		<limit minx="327098" miny="5811358" maxx="351971" maxy="5827675"/>
		...
	</view>
	...
</client:config>

This would use the same full and limit extents as in our snippet but alters the initial extent.

...

	</extents>
		</view>
	</client:config>
</config>
Note

One thing you can't currently do is to remove a sub-tag from a snippet via the reference.

Nested snippets

Snippets can include references to other snippets and references can include references to other snippets. For example we could've created our extents snippet as follows

...

And if we wanted to we could create a separate snippet for our a "custom" extent

Code Block
xml
xml
linenumberstrue
<client:initial id="custom" minx="328098328000" miny="58113585811000" maxx="331971331000" maxy="58176755817000"/>

Then in our "custom" client configuration we could use the following to accomplish the same as we did previously

Code Block
xml
xml
linenumberstrue
<client:config id="custom">
	...
	<view id="com.cohga.html.client.map.mapView">
		...
		<extents ref="defaults">
			<initial ref="custom"/>
		</extents>
		...
	</view>
	...
</client:config>

Further Reading