MapContentProvider extends AbstractJrxmlContentProvider { @Override public Pair<InputStream, Boolean> prepareJrxmlAndReadInputParameters( InputStream jrxml, Map<String, Object> params, ProcessletInputs in, List<CodeType> processedIds, Map<String, String> parameters ) throws ProcessletException { for ( ProcessletInput input : in.getParameters() ) { if ( !processedIds.contains( input.getIdentifier() ) && input instanceof ComplexInput ) { ComplexInput complexIn = (ComplexInput) input; if ( SCHEMA.equals( complexIn.getSchema() ) && MIME_TYPE.equals( complexIn.getMimeType() ) ) { String mapId = complexIn.getIdentifier().getCode(); LOG.debug( "Found input parameter " + mapId + " representing a map!" ); try { JAXBContext jc = JAXBContext.newInstance( org.deegree.services.wps.provider.jrxml.jaxb.map.Map.class ); Unmarshaller unmarshaller = jc.createUnmarshaller(); org.deegree.services.wps.provider.jrxml.jaxb.map.Map map = (org.deegree.services.wps.provider.jrxml.jaxb.map.Map) unmarshaller.unmarshal( complexIn.getValueAsXMLStream() ); XMLAdapter jrxmlAdapter = new XMLAdapter( jrxml ); OMElement root = jrxmlAdapter.getRootElement(); List<OrderedDatasource<?>> datasources = anaylizeRequestOrder( map.getDatasources().getWMSDatasourceOrWFSDatasource() ); int resolution = map.getResolution().intValue(); String mapKey = getParameterFromIdentifier( mapId, SUFFIXES.MAP_SUFFIX ); if ( parameters.containsKey( mapKey ) ) { OMElement mapImgRep = jrxmlAdapter.getElement( root, new XPath( ". + mapKey + "}']/jasper:reportElement", nsContext ) ); if ( mapImgRep == null ) { LOG.info( "Could not find image tag in the jrxml for map parameter '" + mapKey + "'" ); break; } int originalWidth = jrxmlAdapter.getRequiredNodeAsInteger( mapImgRep, new XPath( "@width", nsContext ) ); int originalHeight = jrxmlAdapter.getRequiredNodeAsInteger( mapImgRep, new XPath( "@height", nsContext ) ); int width = adjustSpan( originalWidth, resolution ); int height = adjustSpan( originalHeight, resolution ); Envelope bbox = calculateBBox( map.getDetail(), mapId, width, height, resolution ); params.put( mapKey, prepareMap( datasources, parameters.get( mapKey ), originalWidth, originalHeight, width, height, bbox, resolution ) ); double scale = RenderHelper.calcScaleWMS130( width, height, bbox, bbox.getCoordinateSystem(), MapUtils.DEFAULT_PIXEL_SIZE ); String scaleKey = getParameterFromIdentifier( mapId, SUFFIXES.SCALE_SUFFIX ); if ( parameters.containsKey( scaleKey ) ) { params.put( scaleKey, convert( scale, parameters.get( scaleKey ) ) ); } String scalebarKey = getParameterFromIdentifier( mapId, SUFFIXES.SCALEBAR_SUFFIX ); if ( parameters.containsKey( scalebarKey ) ) { prepareScaleBar( params, scalebarKey, jrxmlAdapter, datasources, parameters.get( scalebarKey ), bbox, width ); } } prepareLayerlist( getParameterFromIdentifier( mapId, SUFFIXES.LAYERLIST_SUFFIX ), jrxmlAdapter, map, datasources ); String legendKey = getParameterFromIdentifier( mapId, SUFFIXES.LEGEND_SUFFIX ); if ( parameters.containsKey( legendKey ) ) { params.put( legendKey, prepareLegend( legendKey, jrxmlAdapter, datasources, parameters.get( legendKey ), resolution ) ); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { if ( LOG.isTraceEnabled() ) { LOG.trace( "Adjusted jrxml: " + jrxmlAdapter.getRootElement() ); } jrxmlAdapter.getRootElement().serialize( bos ); jrxml = new ByteArrayInputStream( bos.toByteArray() ); } catch ( XMLStreamException e ) { throw new RuntimeException( e ); } finally { IOUtils.closeQuietly( bos ); } } catch ( JAXBException e ) { String msg = "Could not parse map configuration from parameter '" + complexIn.getIdentifier() + "': " + e.getMessage(); LOG.debug( msg, e ); throw new ProcessletException( msg ); } catch ( IOException e ) { String msg = "Could not read map configuration from parameter '" + complexIn.getIdentifier() + "': " + e.getMessage(); LOG.debug( msg, e ); throw new ProcessletException( msg ); } catch ( XMLStreamException e ) { String msg = "Could not read map configuration as xml from parameter '" + complexIn.getIdentifier() + "': " + e.getMessage(); LOG.debug( msg, e ); throw new ProcessletException( msg ); } processedIds.add( input.getIdentifier() ); } } } return new Pair<InputStream, Boolean>( jrxml, false ); } MapContentProvider( Workspace workspace ); @Override void inspectInputParametersFromJrxml( Map<String, ParameterDescription> parameterDescriptions,
                                                 List<JAXBElement<? extends ProcessletInputDefinition>> inputs,
                                                 XMLAdapter jrxmlAdapter, Map<String, String> parameters,
                                                 List<String> handledParameters ); @Override Pair<InputStream, Boolean> prepareJrxmlAndReadInputParameters( InputStream jrxml,
                                                                          Map<String, Object> params,
                                                                          ProcessletInputs in,
                                                                          List<CodeType> processedIds,
                                                                          Map<String, String> parameters ); static final double INCH2M; }
@Ignore @Test public void testPrepareJrxmlAndReadInputParameters() throws URISyntaxException, IOException, XMLStreamException, FactoryConfigurationError { MapContentProvider wmsContentProvider = getProvider(); List<CodeType> processedIds = new ArrayList<CodeType>(); Pair<InputStream, Boolean> jrxml = new Pair<InputStream, Boolean>( TestMapContentProviderTest.class.getResourceAsStream( "../../testWPSreportTemplate.jrxml" ), false ); Map<String, Object> params = new HashMap<String, Object>(); ProcessletInputs in = Utils.getInputs( "MAP", MIME_TYPE, SCHEMA, TestMapContentProviderTest.class.getResourceAsStream( "complexInput" ) ); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put( "mapMAP_img", "java.lang.String" ); parameters.put( "mapMAP_legend", "java.lang.String" ); parameters.put( "LEGEND", "java.lang.String" ); try { jrxml = wmsContentProvider.prepareJrxmlAndReadInputParameters( jrxml.first, params, in, processedIds, parameters ); } catch ( ProcessletException e ) { Assume.assumeNoException( e ); } assertEquals( 2, params.size() ); assertEquals( 1, processedIds.size() ); XMLAdapter a = new XMLAdapter( jrxml.first ); String[] elements = a.getNodesAsStrings( a.getRootElement(), new XPath( "/jasper:jasperReport/jasper:detail/jasper:band/jasper:frame/jasper:staticText/jasper:text/text()", nsContext ) ); assertEquals( 3, elements.length ); boolean containsLake = false; boolean containsOverview = false; for ( int i = 0; i < elements.length; i++ ) { if ( "Lake".equals( elements[i] ) ) containsLake = true; if ( "StateOverview".equals( elements[i] ) ) containsOverview = true; } assertTrue( containsOverview ); assertTrue( containsLake ); }
@Ignore @Test public void testPrepareJrxmlAndReadInputParametersWFS() throws URISyntaxException, IOException, XMLStreamException, FactoryConfigurationError, ProcessletException { MapContentProvider wmsContentProvider = getProvider(); List<CodeType> processedIds = new ArrayList<CodeType>(); Pair<InputStream, Boolean> jrxml = new Pair<InputStream, Boolean>( TestMapContentProviderTest.class.getResourceAsStream( "../../testWPSreportTemplate.jrxml" ), false ); Map<String, Object> params = new HashMap<String, Object>(); ProcessletInputs in = Utils.getInputs( "MAP", MIME_TYPE, SCHEMA, TestMapContentProviderTest.class.getResourceAsStream( "complexInputWFS" ) ); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put( "mapMAP_img", "java.lang.String" ); parameters.put( "mapMAP_legend", "java.lang.String" ); parameters.put( "LEGEND", "java.lang.String" ); try { jrxml = wmsContentProvider.prepareJrxmlAndReadInputParameters( jrxml.first, params, in, processedIds, parameters ); } catch ( ProcessletException e ) { Assume.assumeNoException( e ); } assertEquals( 2, params.size() ); assertEquals( 1, processedIds.size() ); assertTrue( params.containsKey( "mapMAP_img" ) ); Object value = params.get( "mapMAP_img" ); assertTrue( value instanceof String ); BufferedImage img = ImageIO.read( new File( (String) value ) ); assertNotNull( img ); assertEquals( 438, img.getWidth() ); assertEquals( 479, img.getHeight() ); }