Open KML from a Link object

All

Any help greatly appreciated. I am try to use a Link object to open a KML stream directly in Google Earth.
Essentially my writer object produces some KML. I then want to get the OS native application to open the KML using Google Earth in this case.

private Link generateLink()
{
Kml kml = new Kml();

// Create a folder
Folder folder = kml.createAndSetFolder().withName(“AIME Google”)
.withOpen(true);

// Add the entities network link
de.micromata.opengis.kml.v_2_2_0.Link entityUrl = new de.micromata.opengis.kml.v_2_2_0.Link()
.withHref(
url

  • “ENTITY.kml?mode=MIL_STD_2525B&side=ALL&balloon=FULL&emissions=ON”)
    .withRefreshMode(RefreshMode.ON_INTERVAL)
    .withRefreshInterval(1.0);
    folder.createAndAddNetworkLink().withName(“Entities”).withOpen(true)
    .withUrl(entityUrl);

// Add the trails network link
de.micromata.opengis.kml.v_2_2_0.Link trailsUrl = new de.micromata.opengis.kml.v_2_2_0.Link()
.withHref(url + “TRAILS.kml”)
.withRefreshMode(RefreshMode.ON_INTERVAL)
.withRefreshInterval(1.0);
folder.createAndAddNetworkLink().withName(“Trails”).withOpen(true)
.withUrl(trailsUrl);

// Add the Link 16 network link
de.micromata.opengis.kml.v_2_2_0.Link link16Url = new de.micromata.opengis.kml.v_2_2_0.Link()
.withHref(url + “Link16.kml”)
.withRefreshMode(RefreshMode.ON_INTERVAL)
.withRefreshInterval(1.0);
folder.createAndAddNetworkLink().withName(“Link 16”).withOpen(true)
.withUrl(link16Url);

StringWriter writer = new StringWriter();
kml.marshal(writer);

ExternalResource er = new ExternalResource(writer.toString(),
“application/vnd.google-earth.kml+xml”);
Link link = new Link(“AIME Google Earth link”, er);

return link;