Export tiles colors data to configuration media.

@param configMinimap The configuration media output (must not be <code>null</code>).
@param tiles The tiles data (must not be <code>null</code>).
@throws LionEngineException If error on writing.
765957
public static void exports(Media configMinimap, Map<TileRef, ColorRgba> tiles)
    {
        Check.notNull(configMinimap);
        Check.notNull(tiles);

        final Map<ColorRgba, Collection<TileRef>> colors = convertToColorKey(tiles);
        final Xml nodeMinimap = new Xml(NODE_MINIMAP);

        for (final Map.Entry<ColorRgba, Collection<TileRef>> entry : colors.entrySet())
        {
            final ColorRgba color = entry.getKey();
            final Xml nodeColor = nodeMinimap.createChild(NODE_COLOR);
            nodeColor.writeInteger(ATT_COLOR_RED, color.getRed());
            nodeColor.writeInteger(ATT_COLOR_GREEN, color.getGreen());
            nodeColor.writeInteger(ATT_COLOR_BLUE, color.getBlue());

            for (final TileRef tileRef : entry.getValue())
            {
                final Xml nodeTileRef = TileConfig.exports(tileRef);
                nodeColor.add(nodeTileRef);
            }
        }

        nodeMinimap.save(configMinimap);
    }
554499
@SuppressWarnings("unchecked")
    private Map<String, CmsTemplateContext> getContextMap() {

        Object cachedObj = m_cache.getCachedObject(m_cms, getConfigurationPropertyPath());
        if (cachedObj != null) {
            return (Map<String, CmsTemplateContext>)cachedObj;
        } else {
            try {
                Map<String, CmsTemplateContext> map = initMap();
                m_cache.putCachedObject(m_cms, getConfigurationPropertyPath(), map);
                return map;
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
                return Collections.emptyMap();
            }
        }

    }
477969
public List<TileCoordinate> translateToZoomLevel(byte zoomlevelNew) {
        List<TileCoordinate> tiles = null;
        int zoomlevelDistance = zoomlevelNew - this.zoomlevel;

        int factor = (int) Math.pow(2, Math.abs(zoomlevelDistance));
        if (zoomlevelDistance > 0) {
            tiles = new ArrayList<>((int) Math.pow(4, Math.abs(zoomlevelDistance)));
            int tileUpperLeftX = this.x * factor;
            int tileUpperLeftY = this.y * factor;
            for (int i = 0; i < factor; i++) {
                for (int j = 0; j < factor; j++) {
                    tiles.add(new TileCoordinate(tileUpperLeftX + j, tileUpperLeftY + i, zoomlevelNew));
                }
            }
        } else {
            tiles = new ArrayList<>(1);
            tiles.add(new TileCoordinate(this.x / factor, this.y / factor, zoomlevelNew));
        }
        return tiles;
    }
648930
private static void exportTiles(Xml nodeTransition, Collection<TileRef> tilesRef)
    {
        for (final TileRef tileRef : tilesRef)
        {
            final Xml nodeTileRef = TileConfig.exports(tileRef);
            nodeTransition.add(nodeTileRef);
        }
    }
598674
protected void configureGoogleClient(final Collection<BaseClient> properties) {
        val google = pac4jProperties.getGoogle();
        val client = new Google2Client(google.getId(), google.getSecret());
        if (StringUtils.isNotBlank(google.getId()) && StringUtils.isNotBlank(google.getSecret())) {
            configureClient(client, google);
            if (StringUtils.isNotBlank(google.getScope())) {
                client.setScope(Google2Client.Google2Scope.valueOf(google.getScope().toUpperCase()));
            }

            LOGGER.debug("Created client [{}] with identifier [{}]", client.getName(), client.getKey());
            properties.add(client);
        }
    }
80071
private static Collection<TileRef> getTiles(Map<ColorRgba, Collection<TileRef>> colors, ColorRgba color)
    {
        if (!colors.containsKey(color))
        {
            colors.put(color, new HashSet<TileRef>());
        }
        return colors.get(color);
    }
345373
public void create(MapTile map, Media config)
    {
        mapHidden.create(map, config, hideTiles);
        mapFogged.create(map, config, fogTiles);
    }
246535
public void setHandlerConfig(Map config)
   {
      configMap.clear();
      if (config != null)
         configMap.putAll(config);
   }
767429
private static int writeFormatTiles(TileDao tileDao, File directory,
			String imageFormat, Integer width, Integer height,
			TileFormatType tileType, boolean rawImage) throws IOException {

		int tileCount = 0;

		// Get the projection of the tile matrix set
		SpatialReferenceSystem srs = tileDao.getTileMatrixSet().getSrs();
		Projection projection = srs.getProjection();

		// Get the transformation to web mercator
		Projection webMercator = ProjectionFactory
				.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
		ProjectionTransform projectionToWebMercator = projection
				.getTransformation(webMercator);

		// Get the bounding box of actual tiles
		BoundingBox zoomBoundingBox = tileDao.getBoundingBox();
		if (projection.isUnit(Units.DEGREES)) {
			zoomBoundingBox = TileBoundingBoxUtils
					.boundDegreesBoundingBoxWithWebMercatorLimits(zoomBoundingBox);
		}
		BoundingBox zoomWebMercatorBoundingBox = zoomBoundingBox
				.transform(projectionToWebMercator);

		GeoPackageTileRetriever retriever = null;
		if (rawImage) {
			retriever = new GeoPackageTileRetriever(tileDao);
		} else {
			retriever = new GeoPackageTileRetriever(tileDao, width, height,
					imageFormat);
		}

		double maxLength = tileDao.getMaxLength();
		double minLength = tileDao.getMinLength();

		double upperMax = getLength(
				new BoundingBox(zoomBoundingBox.getMinLongitude(),
						zoomBoundingBox.getMaxLatitude() - maxLength,
						zoomBoundingBox.getMinLongitude() + maxLength,
						zoomBoundingBox.getMaxLatitude()),
				projectionToWebMercator);
		double upperMin = getLength(
				new BoundingBox(zoomBoundingBox.getMinLongitude(),
						zoomBoundingBox.getMaxLatitude() - minLength,
						zoomBoundingBox.getMinLongitude() + minLength,
						zoomBoundingBox.getMaxLatitude()),
				projectionToWebMercator);

		double lowerMax = getLength(
				new BoundingBox(zoomBoundingBox.getMinLongitude(),
						zoomBoundingBox.getMinLatitude(),
						zoomBoundingBox.getMinLongitude() + maxLength,
						zoomBoundingBox.getMinLatitude() + maxLength),
				projectionToWebMercator);
		double lowerMin = getLength(
				new BoundingBox(zoomBoundingBox.getMinLongitude(),
						zoomBoundingBox.getMinLatitude(),
						zoomBoundingBox.getMinLongitude() + minLength,
						zoomBoundingBox.getMinLatitude() + minLength),
				projectionToWebMercator);

		double maxWebMercatorLength = Math.max(upperMax, lowerMax);
		double minWebMercatorLength = Math.min(upperMin, lowerMin);

		double minZoom = TileBoundingBoxUtils
				.zoomLevelOfTileSize(maxWebMercatorLength);
		double maxZoom = TileBoundingBoxUtils
				.zoomLevelOfTileSize(minWebMercatorLength);

		int minZoomCeiling = (int) Math.ceil(minZoom);
		int maxZoomFloor = (int) Math.floor(maxZoom);

		LOGGER.log(Level.INFO, tileType + " Zoom Range: " + minZoomCeiling
				+ " - " + maxZoomFloor);

		for (int zoomLevel = minZoomCeiling; zoomLevel <= maxZoomFloor; zoomLevel++) {

			File zDirectory = new File(directory, String.valueOf(zoomLevel));
			TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
					zoomWebMercatorBoundingBox, zoomLevel);

			int zoomCount = 0;

			LOGGER.log(
					Level.INFO,
					"Zoom Level: " + zoomLevel + ", Min X: "
							+ tileGrid.getMinX() + ", Max X: "
							+ tileGrid.getMaxX() + ", Min Y: "
							+ tileGrid.getMinY() + ", Max Y: "
							+ tileGrid.getMaxY() + ", Max Tiles: "
							+ tileGrid.count());

			for (long x = tileGrid.getMinX(); x <= tileGrid.getMaxX(); x++) {

				// Build the z/x directory
				File xDirectory = new File(zDirectory, String.valueOf(x));

				for (long y = tileGrid.getMinY(); y <= tileGrid.getMaxY(); y++) {

					GeoPackageTile geoPackageTile = retriever.getTile((int) x,
							(int) y, zoomLevel);

					if (geoPackageTile != null) {

						// Get the y file name for the specified format
						long yFileName = y;
						if (tileType == TileFormatType.TMS) {
							yFileName = TileBoundingBoxUtils
									.getYAsOppositeTileFormat(zoomLevel,
											(int) y);
						}

						File imageFile = new File(xDirectory,
								String.valueOf(yFileName) + "." + imageFormat);

						// Make any needed directories for the image
						xDirectory.mkdirs();

						if (geoPackageTile.getImage() != null) {
							// Write the image to the file
							ImageIO.write(geoPackageTile.getImage(),
									imageFormat, imageFile);
						} else {
							// Write the raw image bytes to the file
							FileOutputStream fos = new FileOutputStream(
									imageFile);
							fos.write(geoPackageTile.getData());
							fos.close();
						}

						zoomCount++;

						if (zoomCount % ZOOM_PROGRESS_FREQUENCY == 0) {
							LOGGER.log(Level.INFO, "Zoom " + zoomLevel
									+ " Tile Progress... " + zoomCount);
						}
					}

				}
			}

			LOGGER.log(Level.INFO, "Zoom " + zoomLevel + " Tiles: " + zoomCount);

			tileCount += zoomCount;
		}

		return tileCount;
	}
189928
@Override
    public void prepare()
    {
        if (surface == null)
        {
            throw new LionEngineException(ERROR_SURFACE);
        }
        final Graphic g = surface.createGraphic();
        final int v = map.getInTileHeight();
        final int h = map.getInTileWidth();

        for (int ty = 0; ty < v; ty++)
        {
            for (int tx = 0; tx < h; tx++)
            {
                final Tile tile = map.getTile(tx, ty);
                final ColorRgba color = getTileColor(tile);
                if (!NO_TILE.equals(color))
                {
                    g.setColor(color);
                    g.drawRect(tx, v - ty - 1, 1, 1, true);
                }
            }
        }
        g.dispose();
    }
1033769
public void create(MapTile map, Media config, SpriteTiled sheet)
    {
        this.map.create(map.getTileWidth(), map.getTileHeight(), map.getInTileWidth(), map.getInTileHeight());
        if (sheet != null)
        {
            this.map.loadSheets(Arrays.asList(sheet));
        }
        for (int i = 0; i < NO_FOG; i++)
        {
            final String group;
            if (i == FOG)
            {
                group = FOG_GROUP;
            }
            else
            {
                group = TRANSITION_GROUP;
            }
            mapGroup.changeGroup(new TileGame(Integer.valueOf(0), i, 0, 0, map.getTileWidth(), map.getTileHeight()),
                                 group);
        }
        mapGroup.changeGroup(new TileGame(Integer.valueOf(0), NO_FOG, 0, 0, map.getTileWidth(), map.getTileHeight()),
                             MapTileGroupModel.NO_GROUP_NAME);
        transition.loadTransitions(config);

        for (int x = 0; x < map.getInTileWidth(); x++)
        {
            for (int y = 0; y < map.getInTileHeight(); y++)
            {
                final Tile tile = new TileGame(Integer.valueOf(0),
                                               FOG,
                                               x * (double) map.getTileWidth(),
                                               y * (double) map.getTileHeight(),
                                               map.getTileWidth(),
                                               map.getTileHeight());
                this.map.setTile(tile);
            }
        }
    }
882797
protected void drawMapTiles(final Graphics g, final int zoom, Rectangle viewportBounds)
    {
        int size = getTileFactory().getTileSize(zoom);
        Dimension mapSize = getTileFactory().getMapSize(zoom);

        // calculate the "visible" viewport area in tiles
        int numWide = viewportBounds.width / size + 2;
        int numHigh = viewportBounds.height / size + 2;

        // TilePoint topLeftTile = getTileFactory().getTileCoordinate(
        // new Point2D.Double(viewportBounds.x, viewportBounds.y));
        TileFactoryInfo info = getTileFactory().getInfo();

        // number of tiles in x direction
        int tpx = (int) Math.floor(viewportBounds.getX() / info.getTileSize(0));
        // number of tiles in y direction
        int tpy = (int) Math.floor(viewportBounds.getY() / info.getTileSize(0));
        // TilePoint topLeftTile = new TilePoint(tpx, tpy);

        // p("top tile = " + topLeftTile);
        // fetch the tiles from the factory and store them in the tiles cache
        // attach the tileLoadListener
        for (int x = 0; x <= numWide; x++)
        {
            for (int y = 0; y <= numHigh; y++)
            {
                int itpx = x + tpx;// topLeftTile.getX();
                int itpy = y + tpy;// topLeftTile.getY();
                // TilePoint point = new TilePoint(x + topLeftTile.getX(), y + topLeftTile.getY());
                // only proceed if the specified tile point lies within the area being painted
                if (g.getClipBounds().intersects(
                        new Rectangle(itpx * size - viewportBounds.x, itpy * size - viewportBounds.y, size, size)))
                {
                    Tile tile = getTileFactory().getTile(itpx, itpy, zoom);
                    int ox = ((itpx * getTileFactory().getTileSize(zoom)) - viewportBounds.x);
                    int oy = ((itpy * getTileFactory().getTileSize(zoom)) - viewportBounds.y);

                    // if the tile is off the map to the north/south, then just don't paint anything
                    if (!isTileOnMap(itpx, itpy, mapSize))
                    {
                        if (isOpaque())
                        {
                            g.setColor(getBackground());
                            g.fillRect(ox, oy, size, size);
                        }
                    }
                    else if (tile.isLoaded())
                    {
                        g.drawImage(tile.getImage(), ox, oy, null);
                    }
                    else
                    {
                        Tile superTile = null;

                        // Use tile at higher zoom level with 200% magnification and if we are not already at max resolution
                        if (zoom < info.getMaximumZoomLevel()) {
                            superTile = getTileFactory().getTile(itpx / 2, itpy / 2, zoom + 1);
                        }

                        if ( superTile != null && superTile.isLoaded())
                        {
                            int offX = (itpx % 2) * size / 2;
                            int offY = (itpy % 2) * size / 2;
                            g.drawImage(superTile.getImage(), ox, oy, ox + size, oy + size, offX, offY, offX + size / 2, offY + size / 2, null);
                        }
                        else
                        {
                            int imageX = (getTileFactory().getTileSize(zoom) - getLoadingImage().getWidth(null)) / 2;
                            int imageY = (getTileFactory().getTileSize(zoom) - getLoadingImage().getHeight(null)) / 2;
                            g.setColor(Color.GRAY);
                            g.fillRect(ox, oy, size, size);
                            g.drawImage(getLoadingImage(), ox + imageX, oy + imageY, null);
                        }
                    }
                    if (isDrawTileBorders())
                    {

                        g.setColor(Color.black);
                        g.drawRect(ox, oy, size, size);
                        g.drawRect(ox + size / 2 - 5, oy + size / 2 - 5, 10, 10);
                        g.setColor(Color.white);
                        g.drawRect(ox + 1, oy + 1, size, size);

                        String text = itpx + ", " + itpy + ", " + getZoom();
                        g.setColor(Color.BLACK);
                        g.drawString(text, ox + 10, oy + 30);
                        g.drawString(text, ox + 10 + 2, oy + 30 + 2);
                        g.setColor(Color.WHITE);
                        g.drawString(text, ox + 10 + 1, oy + 30 + 1);
                    }
                }
            }
        }
    }
238858
@Override
    @SuppressWarnings("unchecked")
    public void decorate(Map<String, Object> result) throws Exception {
        try {
            ServiceReference<ConfigurationAdmin> cmRef = bundleContext.getServiceReference(ConfigurationAdmin.class);
            ServiceReference<JMXSecurityMBean> jmxSecRef = bundleContext.getServiceReference(JMXSecurityMBean.class);
            if (cmRef == null || jmxSecRef == null) {
                return;
            }

            ConfigurationAdmin configAdmin = bundleContext.getService(cmRef);
            JMXSecurityMBean jmxSec = bundleContext.getService(jmxSecRef);
            if (configAdmin == null || jmxSec == null) {
                return;
            }

            // 1. each pair of MBean/operation has to be marked with RBAC flag (can/can't invoke)
            // 2. the information is provided by org.apache.karaf.management.JMXSecurityMBean.canInvoke(java.util.Map)
            // 3. we'll peek into available configadmin jmx.acl* configs, to see which MBeans/operations have to
            //    be examined and which will produce same results
            // 4. only then we'll prepare Map as parameter for canInvoke()

            Configuration[] configurations = configAdmin.listConfigurations("(service.pid=jmx.acl*)");
            if (configurations == null) {
                return;
            }
            List<String> allJmxAclPids = Arrays.stream(configurations)
                .map(Configuration::getPid)
                .collect(Collectors.toCollection(LinkedList::new));
            if (allJmxAclPids.isEmpty()) {
                return;
            }

            Map<String, Map<String, Object>> domains = (Map<String, Map<String, Object>>) result.get("domains");
            // cache contains MBeanInfos for different MBeans/ObjectNames
            Map<String, Map<String, Object>> cache = (Map<String, Map<String, Object>>) result.get("cache");
            // new cache will contain MBeanInfos + RBAC info
            Map<String, Map<String, Object>> rbacCache = new HashMap<>();

            // the fact that some MBeans share JSON MBeanInfo doesn't mean that they can share RBAC info
            // - each MBean's name may have RBAC information configured in different PIDs.

            // when iterating through all repeating MBeans that share MBeanInfo (that doesn't have RBAC info
            // yet), we have to decide if it'll use shared info after RBAC check or will switch to dedicated
            // info. we have to be careful not to end with most MBeans *not* sharing MBeanInfo (in case if
            // somehow the shared info will be "special case" from RBAC point of view)

            Map<String, List<String>> queryForMBeans = new HashMap<>();
            Map<String, List<String>> queryForMBeanOperations = new HashMap<>();
            constructQueries(allJmxAclPids, domains, cache, rbacCache, queryForMBeans, queryForMBeanOperations);

            // RBAC per MBeans (can invoke *any* operation or attribute?)
            doQueryForMBeans(jmxSec, domains, rbacCache, queryForMBeans);

            // RBAC per { MBean,operation } (can invoke status for each operation)
            doQueryForMBeanOperations(jmxSec, domains, rbacCache, queryForMBeanOperations);

            result.remove("cache");
            result.put("cache", rbacCache);

            if (verify) {
                verify(result);
            }

        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            // simply do not decorate
        }
    }
1018096
public static void main(String[] args) throws Exception {

		boolean valid = true;
		boolean requiredArguments = false;

		String imageFormat = null;
		boolean rawImage = false;
		File inputDirectory = null;
		TileFormatType tileType = null;
		File geoPackageFile = null;
		String tileTable = null;

		for (int i = 0; valid && i < args.length; i++) {

			String arg = args[i];

			// Handle optional arguments
			if (arg.startsWith(ARGUMENT_PREFIX)) {

				String argument = arg.substring(ARGUMENT_PREFIX.length());

				switch (argument) {

				case ARGUMENT_IMAGE_FORMAT:
					if (i < args.length) {
						imageFormat = args[++i];
					} else {
						valid = false;
						System.out.println("Error: Image Format argument '"
								+ arg + "' must be followed by a image format");
					}
					break;

				case ARGUMENT_RAW_IMAGE:
					rawImage = true;
					break;

				default:
					valid = false;
					System.out.println("Error: Unsupported arg: '" + arg + "'");
				}

			} else {
				// Set required arguments in order
				if (inputDirectory == null) {
					inputDirectory = new File(arg);
				} else if (tileType == null) {
					tileType = TileFormatType.valueOf(arg.toUpperCase());
				} else if (geoPackageFile == null) {
					geoPackageFile = new File(arg);
				} else if (tileTable == null) {
					tileTable = arg;
					requiredArguments = true;
				} else {
					valid = false;
					System.out.println("Error: Unsupported extra argument: "
							+ arg);
				}
			}
		}

		if (!valid || !requiredArguments) {
			printUsage();
		} else {
			// Read the tiles
			try {
				readTiles(geoPackageFile, tileTable, inputDirectory,
						imageFormat, tileType, rawImage);
			} catch (Exception e) {
				printUsage();
				throw e;
			}
		}

	}
977656
public static void writeFile(MapWriterConfiguration configuration, TileBasedDataProcessor dataProcessor)
            throws IOException {
        EXECUTOR_SERVICE = Executors.newFixedThreadPool(configuration.getThreads());
        RandomAccessFile randomAccessFile = new RandomAccessFile(configuration.getOutputFile(), "rw");

        int amountOfZoomIntervals = dataProcessor.getZoomIntervalConfiguration().getNumberOfZoomIntervals();
        ByteBuffer containerHeaderBuffer = ByteBuffer.allocate(HEADER_BUFFER_SIZE);
        // CONTAINER HEADER
        int totalHeaderSize = writeHeaderBuffer(configuration, dataProcessor, containerHeaderBuffer);

        // set to mark where zoomIntervalConfig starts
        containerHeaderBuffer.reset();

        final LoadingCache<TDWay, Geometry> jtsGeometryCache = CacheBuilder.newBuilder()
                .maximumSize(JTS_GEOMETRY_CACHE_SIZE).concurrencyLevel(Runtime.getRuntime().availableProcessors() * 2)
                .build(new JTSGeometryCacheLoader(dataProcessor));

        // SUB FILES
        // for each zoom interval write a sub file
        long currentFileSize = totalHeaderSize;
        for (int i = 0; i < amountOfZoomIntervals; i++) {
            // SUB FILE INDEX AND DATA
            long subfileSize = writeSubfile(currentFileSize, i, dataProcessor, jtsGeometryCache, randomAccessFile,
                    configuration);
            // SUB FILE META DATA IN CONTAINER HEADER
            writeSubfileMetaDataToContainerHeader(dataProcessor.getZoomIntervalConfiguration(), i, currentFileSize,
                    subfileSize, containerHeaderBuffer);
            currentFileSize += subfileSize;
        }

        randomAccessFile.seek(0);
        randomAccessFile.write(containerHeaderBuffer.array(), 0, totalHeaderSize);

        // WRITE FILE SIZE TO HEADER
        long fileSize = randomAccessFile.length();
        randomAccessFile.seek(OFFSET_FILE_SIZE);
        randomAccessFile.writeLong(fileSize);

        randomAccessFile.close();

        CacheStats stats = jtsGeometryCache.stats();
        LOGGER.fine("Tag values stats:\n" + OSMUtils.logValueTypeCount());
        LOGGER.info("JTS Geometry cache hit rate: " + stats.hitRate());
        LOGGER.info("JTS Geometry total load time: " + stats.totalLoadTime() / 1000);

        LOGGER.info("Finished writing file.");
    }
28717
private static void initMap() {
    // Go through all the enum constants and build a map of
    // LayoutVersion <-> EnumSet of all supported features in that LayoutVersion
    for (Feature f : Feature.values()) {
      EnumSet<Feature> ancestorSet = map.get(f.ancestorLV);
      if (ancestorSet == null) {
        ancestorSet = EnumSet.noneOf(Feature.class); // Empty enum set
        map.put(f.ancestorLV, ancestorSet);
      }
      EnumSet<Feature> featureSet = EnumSet.copyOf(ancestorSet);
      featureSet.add(f);
      map.put(f.lv, featureSet);
    }
    
    // Special initialization for 0.20.203 and 0.20.204
    // to add Feature#DELEGATION_TOKEN
    specialInit(Feature.RESERVED_REL20_203.lv, Feature.DELEGATION_TOKEN);
    specialInit(Feature.RESERVED_REL20_204.lv, Feature.DELEGATION_TOKEN);
  }
931572
public static TileRendererLayer createTileRendererLayer(
            TileCache tileCache, IMapViewPosition mapViewPosition,
            MapDataStore mapFile, XmlRenderTheme renderTheme) {
        TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapFile,
                mapViewPosition, AndroidGraphicFactory.INSTANCE);
        tileRendererLayer.setXmlRenderTheme(renderTheme);
        return tileRendererLayer;
    }