Package org.geoserver.wfs.xslt.config

Examples of org.geoserver.wfs.xslt.config.TransformInfo


    @Override
    protected void write(final FeatureCollectionResponse featureCollection, OutputStream output,
            Operation operation) throws IOException, ServiceException {
        // get the transformation we need
        TransformInfo info = locateTransformation(featureCollection, operation);
        Transformer transformer = repository.getTransformer(info);
        // force Xalan to indent the output
        if(transformer.getOutputProperties() != null && "yes".equals(transformer.getOutputProperties().getProperty("indent"))) {
            try {
                transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            } catch(IllegalArgumentException e) {
                LOGGER.log(Level.FINE, "Could not set indent amount", e);
                // in case it's not Xalan
            }
        }
       

        // prepare the fake operation we're providing to the source output format
        final Operation sourceOperation = buildSourceOperation(operation, info);

        // lookup the operation we are going to use
        final Response sourceResponse = findSourceResponse(sourceOperation, info);
        if (sourceResponse == null) {
            throw new WFSException(
                    "Could not locate a response that can generate the desired source format '"
                            + info.getSourceFormat() + "' for transformation '" + info.getName() + "'");

        }

        // prepare the stream connections, so that we can do the transformation on the fly
        PipedInputStream pis = new PipedInputStream();
View Full Code Here


        GetFeatureRequest req = GetFeatureRequest.adapt(operation.getParameters()[0]);
        String outputFormat = req.getOutputFormat();

        // locate the transformation, and make sure it's the same for all feature types
        Set<FeatureType> featureTypes = getFeatureTypes(collections);
        TransformInfo result = null;
        FeatureType reference = null;
        for (FeatureType ft : featureTypes) {
            TransformInfo curr = locateTransform(outputFormat, ft);
            if (curr == null) {
                throw new WFSException("Could not find a XSLT transformation generating "
                        + outputFormat + " for feature type " + ft.getName(), ServiceException.INVALID_PARAMETER_VALUE, "typeName");
            } else if (result == null) {
                reference = ft;
                result = curr;
            } else if (!result.equals(curr)) {
                throw new WFSException(
                        "Multiple feature types are mapped to different XLST transformations, cannot proceed: "
                                + result.getXslt() + ", " + curr.getXslt(), ServiceException.INVALID_PARAMETER_VALUE, "typeName");

            }
        }

        return result;
View Full Code Here

    }

    private TransformInfo locateTransform(String outputFormat, FeatureType ft) throws IOException {
        // first lookup the type specific transforms
        FeatureTypeInfo info = gs.getCatalog().getFeatureTypeByName(ft.getName());
        TransformInfo result = null;
        if (info != null) {
            List<TransformInfo> transforms = repository.getTypeTransforms(info);
            result = filterByOutputFormat(outputFormat, transforms);
        }
View Full Code Here

    }
   
    @Override
    public String getMimeType(Object value, Operation operation) throws ServiceException {
        try {
            TransformInfo info = locateTransformation((FeatureCollectionResponse) value, operation);
            return info.mimeType();
        } catch(IOException e) {
            throw new WFSException("Failed to load the required transformation", e);
        }
    }
View Full Code Here

   
    @Override
    public String getAttachmentFileName(Object value, Operation operation) {     
        try {
            FeatureCollectionResponse featureCollections = (FeatureCollectionResponse) value;
            TransformInfo info = locateTransformation(featureCollections, operation);
           
            // concatenate all feature types requested
            StringBuilder sb = new StringBuilder();
            for (FeatureCollection<FeatureType, Feature> fc : featureCollections.getFeatures()) {
                sb.append(fc.getSchema().getName().getLocalPart());
                sb.append("_");
            }
            sb.setLength(sb.length() - 1);
           
            String extension = info.getFileExtension();
            if(extension == null) {
                extension = ".txt";
                sb.append(extension);
            }
            if(!extension.startsWith(".")) {
View Full Code Here

        if (transform == null) {
            throw new RestletException("Failed to locate transformation " + transform,
                    Status.CLIENT_ERROR_NOT_FOUND);
        }

        TransformInfo info = repository.getTransformInfo(transform);
        DataFormat format = getFormatGet();
        if (format instanceof XSLTDataFormat) {
            return repository.getTransformSheet(info);
        } else {
            return info;
View Full Code Here

    }

    @Override
    protected void handleObjectDelete() throws Exception {
        String transform = RESTUtils.getAttribute(getRequest(), "transform");
        TransformInfo info = repository.getTransformInfo(transform);
        repository.removeTransformInfo(info);
    }
View Full Code Here

    @Override
    protected void handleObjectPut(Object object) throws Exception {
        String transform = RESTUtils.getAttribute(getRequest(), "transform");
        if (object instanceof TransformInfo) {
            TransformInfo info = (TransformInfo) object;
            // force the right name
            info.setName(transform);
            repository.putTransformInfo(info);
        } else {
            TransformInfo info = repository.getTransformInfo(transform);
            repository.putTransformSheet(info, IOUtils.toInputStream((String) object));
        }
    }
View Full Code Here

        String sourceFormat = getQueryStringValue("sourceFormat");
        String outputFormat = getQueryStringValue("outputFormat");
        String outputMimeType = getQueryStringValue("outputMimeType");
        String fileExtension = getQueryStringValue("fileExtension");

        TransformInfo info;
        if (object instanceof TransformInfo) {
            info = (TransformInfo) object;
            if(transform != null) {
                info.setName(transform);
            }
            validate(info);
            repository.putTransformInfo(info);
            return info.getName();
        } else {
            // the format has turned the user provided stream into a string for validation purposes
            String xslt = (String) object;
            info = repository.getTransformInfo(transform);
            if (info == null) {
                info = new TransformInfo();
                info.setName(transform);
                info.setSourceFormat(sourceFormat);
                info.setOutputFormat(outputFormat);
                info.setOutputMimeType(outputMimeType);
                info.setFileExtension(fileExtension);
                info.setXslt(transform + ".xslt");
                validate(info);
                repository.putTransformInfo(info);
            }

            repository.putTransformSheet(info, new ByteArrayInputStream(xslt.getBytes()));
        }

        return info.getName();
    }
View Full Code Here

        }

        @Override
        public void marshal(Object source, HierarchicalStreamWriter writer,
                MarshallingContext context) {
            TransformInfo original = (TransformInfo) source;
            TransformInfo resolved = new TransformInfo(original);
            FeatureTypeInfo ft = resolved.getFeatureType();
            if (ft != null) {
                resolved.setFeatureType((FeatureTypeInfo) ModificationProxy.unwrap(ft));
            }
            super.marshal(resolved, writer, context);
        }
View Full Code Here

TOP

Related Classes of org.geoserver.wfs.xslt.config.TransformInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.