org.citygml4j.util.xml.SAXEventBuffer Java Examples

The following examples show how to use org.citygml4j.util.xml.SAXEventBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CityGMLWriter.java    From web-feature-service with Apache License 2.0 6 votes vote down vote up
private void writeFeatureCollection(long matchNo, long returnNo, WriteMode writeMode) throws FeatureWriteException {
	try {
		FeatureCollectionType featureCollection = new FeatureCollectionType();
		featureCollection.setTimeStamp(getTimeStamp());
		featureCollection.setNumberMatched(String.valueOf(matchNo));
		featureCollection.setNumberReturned(BigInteger.valueOf(returnNo));

		JAXBElement<?> output;
		if (level == 1) {
			output = wfsFactory.createFeatureCollection(featureCollection);
		} else {
			MemberPropertyType member = new MemberPropertyType();
			member.getContent().add(wfsFactory.createFeatureCollection(featureCollection));
			output = wfsFactory.createMember(member);
		}

		SAXEventBuffer buffer = new SAXEventBuffer();
		SAXFragmentWriter fragmentWriter = new SAXFragmentWriter(new QName(Constants.WFS_NAMESPACE_URI, "FeatureCollection"), buffer, writeMode);
		Marshaller marshaller = cityGMLBuilder.getJAXBContext().createMarshaller();
		marshaller.marshal(output, fragmentWriter);

		writerPool.addWork(buffer);
	} catch (JAXBException e) {
		throw new FeatureWriteException("Failed to marshal feature collection element.", e);
	}
}
 
Example #2
Source File: KmlExportWorkerFactory.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
public KmlExportWorkerFactory(
		JAXBContext jaxbKmlContext,
		JAXBContext jaxbColladaContext,
		WorkerPool<SAXEventBuffer> writerPool,
		ExportTracker tracker,
		Query query,
		ObjectFactory kmlFactory,
		Config config,
		EventDispatcher eventDispatcher) {
	this.jaxbKmlContext = jaxbKmlContext;
	this.jaxbColladaContext = jaxbColladaContext;
	this.writerPool = writerPool;
	this.tracker = tracker;
	this.query = query;
	this.kmlFactory = kmlFactory;
	this.config = config;
	this.eventDispatcher = eventDispatcher;
}
 
Example #3
Source File: XMLWriterWorker.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
	if (firstWork != null) {
		doWork(firstWork);
		firstWork = null;
	}

	while (shouldRun) {
		try {
			SAXEventBuffer work = workQueue.take();
			doWork(work);
		} catch (InterruptedException ie) {
			// re-check state
		}
	}
}
 
Example #4
Source File: XMLWriterWorker.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
private void doWork(SAXEventBuffer work) {
	final ReentrantLock runLock = this.runLock;
	runLock.lock();

	try {
		if (!shouldWork)
			return;
		
		work.send(saxWriter, true);
	} catch (SAXException e) {
		eventDispatcher.triggerSyncEvent(new InterruptEvent("Failed to write XML content.", LogLevel.ERROR, e, eventChannel, this));
		shouldWork = false;
	} finally {
		runLock.unlock();
	}
}
 
Example #5
Source File: CityGMLWriter.java    From web-feature-service with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTruncatedResponse(TruncatedResponse truncatedResponse) throws FeatureWriteException {
	try {
		SAXEventBuffer buffer = new SAXEventBuffer();
		Marshaller marshaller = cityGMLBuilder.getJAXBContext().createMarshaller();
		marshaller.marshal(truncatedResponse, buffer); 
		writerPool.addWork(buffer);
	} catch (JAXBException e) {
		throw new FeatureWriteException("Failed to marshal truncated response element.", e);
	}
}
 
Example #6
Source File: KmlExporterManager.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public KmlExporterManager(JAXBContext jaxbKmlContext,
		JAXBContext jaxbColladaContext,
		AbstractDatabaseAdapter databaseAdapter,
		WorkerPool<SAXEventBuffer> writerPool,
		ExportTracker tracker,
		Query query,
		ObjectFactory kmlFactory,
		BlobExportAdapter textureExportAdapter,
		EventDispatcher eventDispatcher,
		Config config) {
	this.jaxbKmlContext = jaxbKmlContext;
	this.jaxbColladaContext = jaxbColladaContext;
	this.databaseAdapter = databaseAdapter;
	this.writerPool = writerPool;
	this.tracker = tracker;
	this.kmlFactory = kmlFactory;
	this.textureExportAdapter = textureExportAdapter;
	this.eventDispatcher = eventDispatcher;
	this.config = config;

	useTiling = query.isSetTiling();
	mainFilename = config.getInternal().getExportFile().toAbsolutePath().normalize().toString();
	if (mainFilename.lastIndexOf(File.separator) != -1) {
		if (mainFilename.lastIndexOf(".") == -1) {
			mainFilename = mainFilename.substring(mainFilename.lastIndexOf(File.separator) + 1);
		}
		else {
			mainFilename = mainFilename.substring(mainFilename.lastIndexOf(File.separator) + 1, mainFilename.lastIndexOf("."));
		}
	}
	else {
		if (mainFilename.lastIndexOf(".") != -1) {
			mainFilename = mainFilename.substring(0, mainFilename.lastIndexOf("."));
		}
	}
	mainFilename = mainFilename + ".kml";

	objectCounter = new HashMap<>();
}
 
Example #7
Source File: XMLChunkImpl.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
XMLChunkImpl(AbstractJAXBReader chunkReader, XMLChunkImpl parentChunk) {
	this.jaxbReader = chunkReader;
	this.parentChunk = parentChunk;

	buffer = new SAXEventBuffer();
	stax2sax = new StAXStream2SAX(buffer);
}
 
Example #8
Source File: XMLWriterWorkerFactory.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
@Override
public Worker<SAXEventBuffer> createWorker() {
	return new XMLWriterWorker(saxWriter, eventDispatcher);
}