Map<Content, String> contentEntries) throws IOException {
boolean keepURLContentUnchanged = !offlineFurnitureLibrary
&& furnitureResourcesRemoteAbsoluteUrlBase == null
&& furnitureResourcesRemoteRelativeUrlBase == null;
Set<String> existingEntryNames = new HashSet<String>();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "ISO-8859-1"));
final String CATALOG_FILE_HEADER = "#\n# "
+ DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY + ".properties %tc\n"
+ "# Generated by Furniture Library Editor\n#\n";
writer.write(String.format(CATALOG_FILE_HEADER, new Date()));
writer.newLine();
writeProperty(writer, DESCRIPTION, furnitureLibrary.getDescription());
writeProperty(writer, VERSION, furnitureLibrary.getVersion());
writeProperty(writer, LICENSE, furnitureLibrary.getLicense());
writeProperty(writer, PROVIDER, furnitureLibrary.getProvider());
int i = 1;
for (CatalogPieceOfFurniture piece : furnitureLibrary.getFurniture()) {
writer.newLine();
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.ID, i, piece.getId());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.NAME, i, piece.getName());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DESCRIPTION, i, piece.getDescription());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.CATEGORY, i, piece.getCategory().getName());
Content pieceModel = piece.getModel();
String contentBaseName;
if (contentMatchingFurnitureName
|| !(pieceModel instanceof URLContent)
|| ((URLContent)pieceModel).getURL().getFile().toString().endsWith("model.obj")) {
contentBaseName = piece.getName();
} else {
String file = ((URLContent)pieceModel).getURL().getFile();
if (file.lastIndexOf('/') != -1) {
file = file.substring(file.lastIndexOf('/') + 1);
}
if (file.lastIndexOf('.') != -1) {
file = file.substring(0, file.lastIndexOf('.'));
}
contentBaseName = file;
}
String iconContentEntryName = getContentEntry(piece.getIcon(), contentBaseName + ".png",
keepURLContentUnchanged, existingEntryNames);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.ICON, i,
getContentProperty(piece.getIcon(), iconContentEntryName, offlineFurnitureLibrary,
furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase));
if (iconContentEntryName != null) {
contentEntries.put(piece.getIcon(), iconContentEntryName);
}
if (piece.getPlanIcon() != null) {
String planIconContentEntryName = getContentEntry(piece.getPlanIcon(), contentBaseName + "PlanIcon.png",
keepURLContentUnchanged, existingEntryNames);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.PLAN_ICON, i,
getContentProperty(piece.getPlanIcon(), planIconContentEntryName, offlineFurnitureLibrary,
furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase));
if (planIconContentEntryName != null) {
contentEntries.put(piece.getPlanIcon(), planIconContentEntryName);
}
}
boolean multipart = pieceModel instanceof ResourceURLContent
&& ((ResourceURLContent)pieceModel).isMultiPartResource()
|| !(pieceModel instanceof ResourceURLContent)
&& pieceModel instanceof URLContent
&& ((URLContent)pieceModel).isJAREntry();
String modelContentEntryName;
if (multipart) {
String jarEntryName = ((URLContent)pieceModel).getJAREntryName();
modelContentEntryName = getContentEntry(pieceModel,
pieceModel instanceof TemporaryURLContent
? contentBaseName + "/" + jarEntryName
: contentBaseName + "/" + jarEntryName.substring(jarEntryName.lastIndexOf('/') + 1),
keepURLContentUnchanged, existingEntryNames);
} else {
modelContentEntryName = getContentEntry(pieceModel,
contentBaseName + ".obj", keepURLContentUnchanged, existingEntryNames);
}
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MODEL, i,
getContentProperty(pieceModel, modelContentEntryName, offlineFurnitureLibrary,
furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase));
if (modelContentEntryName != null) {
contentEntries.put(pieceModel, modelContentEntryName);
}
if (multipart) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MULTI_PART_MODEL, i, "true");
}
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.WIDTH, i, piece.getWidth());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DEPTH, i, piece.getDepth());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.HEIGHT, i, piece.getHeight());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MOVABLE, i, piece.isMovable());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW, i, piece.isDoorOrWindow());
if (piece.isDoorOrWindow()) {
// Write properties specific to doors and windows
DoorOrWindow doorOrWindow = (DoorOrWindow)piece;
if (doorOrWindow.getWallThickness() != 1) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_WALL_THICKNESS, i,
doorOrWindow.getWallThickness() * doorOrWindow.getDepth());
}
if (doorOrWindow.getWallDistance() != 0) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_WALL_DISTANCE, i,
doorOrWindow.getWallDistance() * doorOrWindow.getDepth());
}
Sash [] sashes = doorOrWindow.getSashes();
if (sashes.length > 0) {
String sashXAxis = "";
String sashYAxis = "";
String sashWidth = "";
String sashStartAngle = "";
String sashEndAngle = "";
for (int sashIndex = 0; sashIndex < sashes.length; sashIndex++) {
if (sashIndex > 0) {
sashXAxis += " ";
sashYAxis += " ";
sashWidth += " ";
sashStartAngle += " ";
sashEndAngle += " ";
}
sashXAxis += sashes [sashIndex].getXAxis() * doorOrWindow.getWidth();
sashYAxis += sashes [sashIndex].getYAxis() * doorOrWindow.getDepth();
sashWidth += sashes [sashIndex].getWidth() * doorOrWindow.getWidth();
sashStartAngle += Math.round(Math.toDegrees(sashes [sashIndex].getStartAngle()) * 100) / 100;
sashEndAngle += Math.round(Math.toDegrees(sashes [sashIndex].getEndAngle()) * 100) / 100;
}
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_X_AXIS, i, sashXAxis);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_Y_AXIS, i, sashYAxis);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_WIDTH, i, sashWidth);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_START_ANGLE, i, sashStartAngle);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_END_ANGLE, i, sashEndAngle);
}
}
if (piece instanceof Light) {
// Write properties specific to lights
Light light = (Light)piece;
LightSource [] lightSources = light.getLightSources();
if (lightSources.length > 0) {
String lightSourceX = "";
String lightSourceY = "";
String lightSourceZ = "";
String lightSourceColor = "";
String lightSourceDiameter = null;
for (int lightIndex = 0; lightIndex < lightSources.length; lightIndex++) {
if (lightIndex > 0) {
lightSourceX += " ";
lightSourceY += " ";
lightSourceZ += " ";
lightSourceColor += " ";
if (lightSourceDiameter != null) {
lightSourceDiameter += " ";
}
}
lightSourceX += lightSources [lightIndex].getX() * light.getWidth();
lightSourceY += lightSources [lightIndex].getY() * light.getDepth();
lightSourceZ += lightSources [lightIndex].getZ() * light.getHeight();
lightSourceColor += "#" + Integer.toHexString(lightSources [lightIndex].getColor());
if (lightSources [lightIndex].getDiameter() != null) {
if (lightSourceDiameter == null) {
lightSourceDiameter = "";
}
lightSourceDiameter += lightSources [lightIndex].getDiameter() * light.getWidth();
}
}
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_X, i, lightSourceX);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_Y, i, lightSourceY);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_Z, i, lightSourceZ);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_COLOR, i, lightSourceColor);
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_DIAMETER, i, lightSourceDiameter);
}
}
if (piece.getElevation() > 0) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.ELEVATION, i, piece.getElevation());
}
float [][] modelRotation = piece.getModelRotation();
String modelRotationString =
Math.round(modelRotation[0][0]) + " " + Math.round(modelRotation[0][1]) + " " + Math.round(modelRotation[0][2]) + " "
+ Math.round(modelRotation[1][0]) + " " + Math.round(modelRotation[1][1]) + " " + Math.round(modelRotation[1][2]) + " "
+ Math.round(modelRotation[2][0]) + " " + Math.round(modelRotation[2][1]) + " " + Math.round(modelRotation[2][2]);
if (!"1 0 0 0 1 0 0 0 1".equals(modelRotationString)) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MODEL_ROTATION, i, modelRotationString);
}
if (!piece.isResizable()) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.RESIZABLE, i, piece.isResizable());
}
if (!piece.isDeformable()) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DEFORMABLE, i, piece.isDeformable());
}
if (!piece.isTexturable()) {
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.TEXTURABLE, i, piece.isTexturable());
}
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.PRICE, i, piece.getPrice());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.VALUE_ADDED_TAX_PERCENTAGE, i, piece.getValueAddedTaxPercentage());
writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.CREATOR, i, piece.getCreator());
i++;
}
writer.flush();
}