if((!hasTilesetImage) || tile.getId() >= set.getMaxTileId()) {
if (!hasTilesetImage || tile.getId() >= set.getMaxTileId()) {
    private TileSet unmarshalTileset(Node t) throws Exception {        String source = getAttributeValue(t, "source");        String basedir = getAttributeValue(t, "basedir");        int firstGid = getAttribute(t, "firstgid", 1);        String tilesetBaseDir = xmlPath;        if (basedir != null) {            tilesetBaseDir = basedir; //makeUrl(basedir);        }        if (source != null) {            String filename = tilesetBaseDir + source;            //if (Util.checkRoot(source)) {            //    filename = makeUrl(source);            //}            TileSet ext = null;            try {                //just a little check for tricky people...                String extention = source.substring(source.lastIndexOf('.') + 1);                if (!"tsx".equals(extention.toLowerCase())) {                	logger.warn("tileset files should end in .tsx! ("+source+")");                }                InputStream in = new URL(makeUrl(filename)).openStream();                ext = unmarshalTilesetFile(in, filename);            } catch (FileNotFoundException fnf) {            	logger.error("Could not find external tileset file " +                        filename);            }            if (ext == null) {            	logger.error("tileset "+source+" was not loaded correctly!");                ext = new TileSet();            }            ext.setFirstGid(firstGid);            return ext;        }        else {            int tileWidth = getAttribute(t, "tilewidth", map != null ? map.getTileWidth() : 0);            int tileHeight = getAttribute(t, "tileheight", map != null ? map.getTileHeight() : 0);            int tileSpacing = getAttribute(t, "spacing", 0);            TileSet set = new TileSet();            set.setName(getAttributeValue(t, "name"));            set.setBaseDir(basedir);            set.setFirstGid(firstGid);            boolean hasTilesetImage = false;            NodeList children = t.getChildNodes();            //if we have a tileset image, load it (tileset can have only one image element)            Node child = findChild(t, "image");            if(child != null) {                String imgSource = getAttributeValue(child, "source");                String id = getAttributeValue(child, "id");                String transStr = getAttributeValue(child, "trans");                hasTilesetImage = true;                if (imgSource != null && id == null) {                    // Not a shared image, but an entire set in one image                    // file                    // FIXME: importTileBitmap does not fully support URLs                    String sourcePath = imgSource;                    if (!Util.checkRoot(imgSource)) {                        sourcePath = tilesetBaseDir + imgSource;                    }                    logger.info("Importing " + sourcePath + "...");                    BufferedImage tilesetImage = ImageIO.read(new File(sourcePath));                    if (transStr != null) {                        // In this case, the tileset image needs special                        // handling for transparency                        Color color = new Color(                                Integer.parseInt(transStr, 16));                        Toolkit tk = Toolkit.getDefaultToolkit();                        Image trans = tk.createImage(                                new FilteredImageSource(tilesetImage.getSource(),                                    new TransparentImageFilter(                                        color.getRGB())));                        BufferedImage img = new BufferedImage(                                trans.getWidth(null),                                trans.getHeight(null),                                BufferedImage.TYPE_INT_ARGB);                        img.getGraphics().drawImage(trans, 0, 0, null);                        tilesetImage = img;                        set.setTransparentColor(color);                    }                    set.importTileBitmap(tilesetImage, new BasicTileCutter(                            tileWidth, tileHeight, tileSpacing, 0),                        true);                    set.setTilesetImageFilename(sourcePath);                } else {                    set.addImage(unmarshalImage(child, tilesetBaseDir),                            Integer.parseInt(getAttributeValue(child, "id")));                }            }            //spin through and find tile elements            for (int i = 0; i < children.getLength(); i++) {                Node c = children.item(i);                if (c.getNodeName().equalsIgnoreCase("tile")) {                    Tile tile = unmarshalTile(set, c, tilesetBaseDir);                    if((!hasTilesetImage) || tile.getId() >= set.getMaxTileId()) {                        set.addTile(tile);                    } else {                        Tile myTile = set.getTile(tile.getId());                        myTile.setProperties(tile.getProperties());                        //TODO: there is the possibility here of overlaying images,                        //      which some people may want                    }                }            }            return set;        }    }