Package org.geowebcache.layer

Examples of org.geowebcache.layer.TileLayer


    protected TileLayer deserializeAndCheckLayerInternal(String layerName, String formatExtension,
            InputStream is) throws RestletException, IOException {

        XStream xs = xmlConfig.getConfiguredXStreamWithContext(new XStream(new DomDriver()), Context.REST);

        TileLayer newLayer;

        try {
            if (formatExtension.equalsIgnoreCase("xml")) {
                newLayer = (TileLayer) xs.fromXML(is);
            } else if (formatExtension.equalsIgnoreCase("json")) {
                HierarchicalStreamDriver driver = new JettisonMappedXmlDriver();
                HierarchicalStreamReader hsr = driver.createReader(is);
                // See http://jira.codehaus.org/browse/JETTISON-48
                StringWriter writer = new StringWriter();
                new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer));
                writer.close();
                newLayer = (TileLayer) xs.fromXML(writer.toString());
            } else {
                throw new RestletException("Unknown or missing format extension: "
                        + formatExtension, Status.CLIENT_ERROR_BAD_REQUEST);
            }
        } catch (ConversionException xstreamExceptionWrapper) {
            Throwable cause = xstreamExceptionWrapper.getCause();
            if (cause instanceof Error) {
                throw (Error) cause;
            }
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            }
            if (cause!=null){
                throw new RestletException(cause.getMessage(), Status.SERVER_ERROR_INTERNAL,
                        (Exception) cause);
            } else {
                throw new RestletException(xstreamExceptionWrapper.getMessage(),
                    Status.SERVER_ERROR_INTERNAL, xstreamExceptionWrapper);
            }
        }

        if (!newLayer.getName().equals(layerName)) {
            throw new RestletException("There is a mismatch between the name of the "
                    + " layer in the submission and the URL you specified.",
                    Status.CLIENT_ERROR_BAD_REQUEST);
        }

        // Check that the parameter filters deserialized correctly
        if(newLayer.getParameterFilters()!=null) {
            try {
                for(@SuppressWarnings("unused")
                ParameterFilter filter: newLayer.getParameterFilters()){
                    // Don't actually need to do anything here.  Just iterate over the elements
                    // casting them into ParameterFilter
                }
            } catch (ClassCastException ex) {
                // By this point it has already been turned into a POJO, so the XML is no longer
View Full Code Here


        try {
            layerName = URLDecoder.decode((String) request.getAttributes().get("layer"), "UTF-8");
        } catch (UnsupportedEncodingException uee) {
        }

        TileLayer tl;
        try {
            tl = seeder.findTileLayer(layerName);
        } catch (GeoWebCacheException e) {
            throw new RestletException(e.getMessage(), Status.CLIENT_ERROR_BAD_REQUEST);
        }
View Full Code Here

    private void handleDoGet(Response response, TileLayer tl, boolean listAllTasks) {
        response.setEntity(makeFormPage(tl, listAllTasks), MediaType.TEXT_HTML);
    }

    public void doPost(Request req, Response resp) throws RestletException, GeoWebCacheException {
        final TileLayer tl;
        {
            String layerName = null;
            if (req.getAttributes().containsKey("layer")) {
                try {
                    layerName = URLDecoder.decode((String) req.getAttributes().get("layer"),
View Full Code Here

        } else {
            ConveyorTile convTile = (ConveyorTile) conv;

            // B3) Get the configuration that has to respond to this request
            TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);

            // Save it for later
            convTile.setTileLayer(layer);

            // Apply the filters
            layer.applyRequestFilters(convTile);

            // Keep the URI
            // tile.requestURI = request.getRequestURI();

            try {
                // A5) Ask the layer to provide the content for the tile
                convTile = layer.getTile(convTile);

                // A6) Write response
                writeData(convTile);

                // Alternatively:
View Full Code Here

        Resource blob = tile.getBlob();

        servletResp.setHeader("geowebcache-cache-result", String.valueOf(cacheResult));
        servletResp.setHeader("geowebcache-tile-index", Arrays.toString(tile.getTileIndex()));
        long[] tileIndex = tile.getTileIndex();
        TileLayer layer = tile.getLayer();
        GridSubset gridSubset = layer.getGridSubset(tile.getGridSetId());
        BoundingBox tileBounds = gridSubset.boundsFromIndex(tileIndex);
        servletResp.setHeader("geowebcache-tile-bounds", tileBounds.toString());
        servletResp.setHeader("geowebcache-gridset", gridSubset.getName());
        servletResp.setHeader("geowebcache-crs", gridSubset.getSRS().toString());
View Full Code Here

     * Writes a transparent, 8 bit PNG to avoid having clients like OpenLayers showing lots of pink
     * tiles
     */
    private void writeEmpty(ConveyorTile tile, String message) {
        tile.servletResp.setHeader("geowebcache-message", message);
        TileLayer layer = tile.getLayer();
        if (layer != null) {
            layer.setExpirationHeader(tile.servletResp, (int) tile.getTileIndex()[2]);

            if (layer.useETags()) {
                String ifNoneMatch = tile.servletReq.getHeader("If-None-Match");
                if (ifNoneMatch != null && ifNoneMatch.equals("gwc-blank-tile")) {
                    tile.servletResp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                } else {
View Full Code Here

        // Do we have a layer, or should we make a list?
        if (action != null) {
            String layerName = ServletUtils.URLDecode(action, request.getCharacterEncoding());

            TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);

            String rawGridSet = request.getParameter("gridSet");
            String gridSetStr = null;
            if (rawGridSet != null)
                gridSetStr = ServletUtils.URLDecode(rawGridSet, request.getCharacterEncoding());

            if (gridSetStr == null) {
                gridSetStr = request.getParameter("srs");

                if (gridSetStr == null) {
                    gridSetStr = layer.getGridSubsets().iterator().next();
                }
            }

            String formatStr = request.getParameter("format");

            if (formatStr != null) {
                if (!layer.supportsFormat(formatStr)) {
                    throw new GeoWebCacheException("Unknow or unsupported format " + formatStr);
                }
            } else {
                formatStr = layer.getDefaultMimeType().getFormat();
            }

            if (request.getPathInfo().startsWith("/demo")) {
                // Running in GeoServer
                page = generateHTML(layer, gridSetStr, formatStr, true);
View Full Code Here

            GridSetBroker gridSetBroker) throws GeoWebCacheException {
        StringBuffer buf = new StringBuffer();

        Set<String> layerList = new TreeSet<String>(tileLayerDispatcher.getLayerNames());
        for (String layerName : layerList) {
            TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);
            buf.append("<tr><td style=\"min-width: 100px;\"><strong>" + layer.getName()
                    + "</strong><br />\n");
            buf.append("<a href=\"rest/seed/" + layer.getName() + "\">Seed this layer</a>\n");
            buf.append("</td><td>" + layer.isEnabled() + "</td>");
            buf.append("<td><table width=\"100%\">");

            int count = 0;
            for (String gridSetId : layer.getGridSubsets()) {
                GridSubset gridSubset = layer.getGridSubset(gridSetId);
                String gridSetName = gridSubset.getName();
                if (gridSetName.length() > 20) {
                    gridSetName = gridSetName.substring(0, 20) + "...";
                }
                buf.append("<tr><td style=\"width: 170px;\">").append(gridSetName);

                buf.append("</td><td>OpenLayers: [");
                Iterator<MimeType> mimeIter = layer.getMimeTypes().iterator();
                boolean prependComma = false;
                while (mimeIter.hasNext()) {
                    MimeType mime = mimeIter.next();
                    if (mime instanceof ImageMime) {
                        if (prependComma) {
                            buf.append(", ");
                        } else {
                            prependComma = true;
                        }
                        buf.append(generateDemoUrl(layer.getName(), gridSubset.getName(),
                                (ImageMime) mime));
                    }
                }
                buf.append("]</td><td>\n");

                if (gridSubset.getName().equals(gridSetBroker.WORLD_EPSG4326.getName())) {
                    buf.append(" &nbsp; KML: [");
                    String prefix = "";
                    prependComma = false;
                    Iterator<MimeType> kmlIter = layer.getMimeTypes().iterator();
                    while (kmlIter.hasNext()) {
                        MimeType mime = kmlIter.next();
                        if (mime instanceof ImageMime || mime == XMLMime.kml) {
                            if (prependComma) {
                                buf.append(", ");
                            } else {
                                prependComma = true;
                            }
                            buf.append("<a href=\"" + prefix + "service/kml/" + layer.getName()
                                    + "." + mime.getFileExtension() + ".kml\">"
                                    + mime.getFileExtension() + "</a>");
                        } else if (mime == XMLMime.kmz) {
                            if (prependComma) {
                                buf.append(", ");
                            } else {
                                prependComma = true;
                            }
                            buf.append("<a href=\"" + prefix + "service/kml/" + layer.getName()
                                    + ".kml.kmz\">kmz</a>");
                        }
                    }
                    buf.append("]");
                } else {
View Full Code Here

        this.convTile = convTile;
    }

    protected void writeResponse(RuntimeStats stats) throws OWSException {
        TileLayer layer = convTile.getLayer();

        GridSet gridSet = convTile.getGridSubset().getGridSet();
        if (gridSet.getTileHeight() < j || j < 0) {
            throw new OWSException(400, "PointIJOutOfRange", "J", "J was " + j
                    + ", must be between 0 and " + gridSet.getTileHeight());
        }

        if (gridSet.getTileWidth() < i || i < 0) {
            throw new OWSException(400, "PointIJOutOfRange", "I", "I was " + i
                    + ", must be between 0 and " + gridSet.getTileWidth());
        }

        Resource data = null;
        try {
            BoundingBox bbox = convTile.getGridSubset().boundsFromIndex(convTile.getTileIndex());
            data = layer.getFeatureInfo(convTile, bbox, convTile.getGridSubset().getTileHeight(),
                    convTile.getGridSubset().getTileWidth(), i, j);
        } catch (GeoWebCacheException e) {
            throw new OWSException(500, "NoApplicableCode", "", e.getMessage());
        }
View Full Code Here

        String layer = values.get("layer");
        if (layer == null) {
            throw new OWSException(400, "MissingParameterValue", "LAYER", "Missing LAYER parameter");
        }

        TileLayer tileLayer = null;

        try {
            tileLayer = tld.getTileLayer(layer);
        } catch (GeoWebCacheException e) {
            throw new OWSException(400, "InvalidParameterValue", "LAYER", "LAYER " + layer
                    + " is not known.");
        }

        Map<String, String> fullParameters;
        try {
            // WMTS uses the "STYLE" instead of "STYLES"
            @SuppressWarnings("unchecked")
            Map<String, Object> rawParameters = new HashMap<>(request.getParameterMap());
            for(Entry<String, Object> e:rawParameters.entrySet()){
                if(e.getKey().equalsIgnoreCase("STYLE")) {
                    rawParameters.put("STYLES", e.getValue());
                    break;
                }
            }
            fullParameters = tileLayer.getModifiableParameters(rawParameters, encoding);

        } catch (GeoWebCacheException e) {
            throw new OWSException(500, "NoApplicableCode", "", e.getMessage()
                    + " while fetching modifiable parameters for LAYER " + layer);
        }

        MimeType mimeType = null;
        if (reqType == RequestType.TILE) {
            String format = values.get("format");
            if (format == null) {
                throw new OWSException(400, "MissingParameterValue", "FORMAT",
                        "Unable to determine requested FORMAT, " + format);
            }
            try {
                mimeType = MimeType.createFromFormat(format);
            } catch (MimeException me) {
                throw new OWSException(400, "InvalidParameterValue", "FORMAT",
                        "Unable to determine requested FORMAT, " + format);
            }
        } else {
            String infoFormat = ServletUtils.stringFromMap(request.getParameterMap(),
                    request.getCharacterEncoding(), "infoformat");
           
            if (infoFormat == null) {
                throw new OWSException(400, "MissingParameterValue", "INFOFORMAT",
                        "Parameter INFOFORMAT was not provided");
            }
            try {
                mimeType = MimeType.createFromFormat(infoFormat);
            } catch (MimeException me) {
                throw new OWSException(400, "InvalidParameterValue", "INFOFORMAT",
                        "Unable to determine requested INFOFORMAT, " + infoFormat);
            }
        }

        final String tilematrixset = values.get("tilematrixset");
        if (tilematrixset == null) {
            throw new OWSException(400, "MissingParameterValue", "TILEMATRIXSET",
                    "No TILEMATRIXSET specified");
        }

        GridSubset gridSubset = tileLayer.getGridSubset(tilematrixset);
        if (gridSubset == null) {
            throw new OWSException(400, "InvalidParameterValue", "TILEMATRIXSET",
                    "Unable to match requested TILEMATRIXSET " + tilematrixset
                            + " to those supported by layer");
        }
View Full Code Here

TOP

Related Classes of org.geowebcache.layer.TileLayer

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.