_rootCategory = rootCategory;
}
private void writeCategory(Document document, Element parentElement, List<IRadioItem> itemList) {
if (itemList != null) {
IRadioItem item;
for (int i = 0; i < itemList.size(); i++) {
item = itemList.get(i);
try {
if (item instanceof CategoryRadioItem) {
Element categoryElement = document.createElement(RadioXmlConstants.CATEGORY_TAG);
Element categoryNameElement = document.createElement(RadioXmlConstants.CATEGORY_NAME_TAG);
categoryNameElement.setTextContent(URLEncoder.encode(item.getName(), "UTF-8"));
categoryElement.appendChild(categoryNameElement);
parentElement.appendChild(categoryElement);
writeCategory(document, categoryElement, item.getChildren());
} else if (item instanceof RadioItem) {
Element radioElement = document.createElement(RadioXmlConstants.RADIO_TAG);
radioElement.setAttribute(RadioXmlConstants.RADIO_IS_FAVORITE_ATTR, Boolean.toString(((RadioItem) item).isFavorite()));
Element radioNameElement = document.createElement(RadioXmlConstants.RADIO_NAME_TAG);
radioNameElement.setTextContent(URLEncoder.encode(item.getName(), "UTF-8"));
Element radioUrlElement = document.createElement(RadioXmlConstants.RADIO_URL_TAG);
radioUrlElement.setTextContent(URLEncoder.encode(((RadioItem) item).getUrl(), "UTF-8"));
radioElement.appendChild(radioNameElement);
radioElement.appendChild(radioUrlElement);
parentElement.appendChild(radioElement);
}
} catch (UnsupportedEncodingException e) {
Log.getInstance(RadioWriter.class).warn("Unable to encode value for item: " + item.getName());
}
}
}
}