Skip to content

Instantly share code, notes, and snippets.

@itsrifat
Created September 18, 2014 04:44
Show Gist options
  • Save itsrifat/12baccd7e2b9eba333ad to your computer and use it in GitHub Desktop.
Save itsrifat/12baccd7e2b9eba333ad to your computer and use it in GitHub Desktop.
client code for generating metadata that conforms to ISO 19115 using APache SIS
package edu.unr.nccp;
import org.apache.sis.internal.jaxb.gmi.MI_Metadata;
import org.apache.sis.metadata.iso.citation.DefaultContact;
import org.apache.sis.metadata.iso.citation.DefaultResponsibleParty;
import org.opengis.metadata.Metadata;
import org.opengis.metadata.citation.Contact;
import org.opengis.metadata.identification.CharacterSet;
import org.opengis.metadata.maintenance.ScopeCode;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class GenerateMetadataXml {
public static void main(String[] args) {
MI_Metadata mi_Metadata = new MI_Metadata();
mi_Metadata.setLanguage(Locale.ENGLISH);
mi_Metadata.setCharacterSet(CharacterSet.UTF_8);
List scopeCodes = new ArrayList<ScopeCode>();
scopeCodes.add(ScopeCode.DATASET);
mi_Metadata.setHierarchyLevels(scopeCodes);
try {
File file = new File("file.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(MI_Metadata.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(mi_Metadata, file);
jaxbMarshaller.marshal(mi_Metadata, System.out);
} catch (JAXBException e) {
}
}
}
@itsrifat
Copy link
Author

This client code generates this xml https://gist.github.com/itsrifat/826d901868c37c20b314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment