use of org.geotoolkit.sampling.xml.v100.ObjectFactory in project ddf by codice.
the class WfsFilterDelegate method createFeatureIdFilter.
private JAXBElement<ResourceIdType> createFeatureIdFilter(final String id) {
ResourceIdType resId = new ResourceIdType();
resId.setRid(id);
ObjectFactory objFact = new ObjectFactory();
return objFact.createResourceId(resId);
}
use of org.geotoolkit.sampling.xml.v100.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionHits.
@Ignore
@Test
public void testMarshalRecordCollectionHits() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.FULL);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.FULL);
collection.setResultType(ResultType.HITS);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, never()).marshal(any(Object.class), any(HierarchicalStreamWriter.class), any(MarshallingContext.class));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(0));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of org.geotoolkit.sampling.xml.v100.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetBrief.
@Ignore
@Test
public void testMarshalRecordCollectionGetBrief() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.BRIEF);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.BRIEF);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.BRIEF));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of org.geotoolkit.sampling.xml.v100.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetElements.
@Ignore
@Test
public void testMarshalRecordCollectionGetElements() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
List<QName> elements = new LinkedList<>();
elements.add(CswConstants.CSW_TITLE_QNAME);
elements.add(CswConstants.CSW_SOURCE_QNAME);
query.setElementName(elements);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementName(elements);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(nullValue()));
assertThat(context.get(CswConstants.ELEMENT_NAMES), is(notNullValue()));
List<QName> qnames = (List<QName>) context.get(CswConstants.ELEMENT_NAMES);
assertThat(qnames.contains(CswConstants.CSW_TITLE_QNAME), is(true));
assertThat(qnames.contains(CswConstants.CSW_SOURCE_QNAME), is(true));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(nullValue()));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of org.geotoolkit.sampling.xml.v100.ObjectFactory in project BibleMultiConverter by schierlm.
the class USX3 method doExportBook.
@Override
protected void doExportBook(ParatextBook book, File outFile) throws Exception {
ObjectFactory of = new ObjectFactory();
Usx usx = of.createUsx();
usx.setVersion("3.0");
usx.setBook(of.createBook());
usx.getBook().setStyle("id");
usx.getBook().setCode(book.getId().getIdentifier());
usx.getBook().setContent(book.getBibleName());
for (Map.Entry<String, String> attr : book.getAttributes().entrySet()) {
Para para = new Para();
para.setStyle(ParaStyle.fromValue(attr.getKey()));
para.getContent().add(attr.getValue());
usx.getParaOrTableOrChapter().add(para);
}
book.accept(new ParatextBook.ParatextBookContentVisitor<IOException>() {
List<Object> currentContent = null;
Table currentTable = null;
@Override
public void visitChapterStart(ChapterIdentifier location) throws IOException {
Chapter ch = new Chapter();
ch.setStyle("c");
ch.setSid(location.toString());
ch.setNumber(BigInteger.valueOf(location.chapter));
usx.getParaOrTableOrChapter().add(ch);
currentContent = null;
currentTable = null;
}
@Override
public void visitChapterEnd(ChapterIdentifier location) throws IOException {
Chapter ch = new Chapter();
ch.setEid(location.toString());
usx.getParaOrTableOrChapter().add(ch);
currentContent = null;
currentTable = null;
}
@Override
public void visitParagraphStart(ParatextBook.ParagraphKind kind) throws IOException {
if (kind == ParatextBook.ParagraphKind.TABLE_ROW) {
if (currentTable == null) {
currentTable = new Table();
usx.getParaOrTableOrChapter().add(currentTable);
}
Row row = new Row();
row.setStyle("tr");
currentTable.getRow().add(row);
currentContent = currentTable.getRow().get(currentTable.getRow().size() - 1).getVerseOrCell();
} else {
Para para = new Para();
para.setStyle(PARA_KIND_MAP.get(kind));
usx.getParaOrTableOrChapter().add(para);
currentContent = para.getContent();
currentTable = null;
}
}
@Override
public void visitTableCellStart(String tag) throws IOException {
if (currentTable == null) {
System.out.println("WARNING: Table cell outside of table");
return;
}
Row currentRow = currentTable.getRow().get(currentTable.getRow().size() - 1);
Cell cell = new Cell();
cell.setAlign(tag.contains("r") ? CellAlign.END : CellAlign.START);
cell.setStyle(CellStyle.fromValue(tag));
currentRow.getVerseOrCell().add(cell);
currentContent = cell.getContent();
}
@Override
public void visitParatextCharacterContent(ParatextCharacterContent content) throws IOException {
if (currentContent == null)
visitParagraphStart(ParatextBook.ParagraphKind.PARAGRAPH_P);
content.accept(new USX3.USXCharacterContentVisitor(currentContent));
}
});
JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
Marshaller m = ctx.createMarshaller();
if (!Boolean.getBoolean("biblemulticonverter.skipxmlvalidation"))
m.setSchema(getSchema());
m.marshal(usx, new UnifiedScriptureXMLWriter(new FileWriter(outFile), "UTF-8"));
}
Aggregations