}
private void update(Document document) {
Element element = document.getElement();
org.w3c.dom.Document dom = element.getOwnerDocument();
ContextAdapter ctx = new ContextAdapter(JXPathContext.newContext(element));
if (!editingDefault) {
ctx.setValue("name", nameText.getText());
}
ctx.removeAll("category");
Pointer p = ctx.getPointer("description|schedule|transform|autoBookmark");
for (int i = 0; i < categories.length; i++) {
Element category = (Element) dom.createElement("category");
category.appendChild(dom.createTextNode(categories[i]));
if (p != null) {
element.insertBefore(category, (Element) p.getNode());
} else {
element.appendChild(category);
}
}
if (!editingDefault) {
String template = (String) templateCombo.getSelectedItem();
if (template.equals("_default")) {
ctx.remove("@template");
} else {
ctx.setValue("@template", template);
}
}
if (!editingDefault) {
ctx.setValue("uri", uriText.getText());
}
int depth = ((Integer) maxDepthSpinner.getValue()).intValue();
if (depth > 0) {
ctx.setValue("uri/@maxDepth", String.valueOf(depth));
} else {
ctx.remove("uri/@maxDepth");
}
document.resetStartingURI();
String restrict = (String) restrictCombo.getSelectedItem();
if (restrict.equals("none")) {
ctx.remove("uri/@restrict");
} else {
ctx.setValue("uri/@restrict", restrict);
}
if (referrerText.getText().length() > 0) {
ctx.setValue("uri/@referrer", referrerText.getText());
} else {
ctx.remove("uri/@referrer");
}
if (element.getNodeName().equals("feed")) {
populateFeedStructure(element);
}
String s = (String) scheduleCombo.getSelectedItem();
if (s.equals("none")) {
ctx.removeAll("schedule");
} else {
p = ctx.getPointer("schedule");
Element schedule;
if (p != null) {
schedule = (Element) p.getNode();
ctx.removeAll("schedule/*");
} else {
schedule = dom.createElement("schedule");
p = ctx.getPointer("transform|autoBookmark");
if (p != null) {
element.insertBefore(schedule, (Element) p.getNode());
} else {
element.appendChild(schedule);
}
}
populateSchedule(dom, schedule);
}
if (altTextCheck.isSelected() && (embeddedBppCombo.getSelectedIndex() == 0) &&
(standaloneBppCombo.getSelectedIndex() == 0)) {
ctx.removeAll("images");
}
if (altTextCheck.isSelected()) {
ctx.removeAll("images/@includeAltText");
} else {
p = ctx.getPointer("images");
if (p != null) {
Element images = (Element) p.getNode();
images.setAttribute("includeAltText", "no");
} else {
Element images = dom.createElement("images");
images.setAttribute("includeAltText", "no");
p = ctx.getPointer("category|description|schedule|transform|autoBookmark");
if (p != null) {
element.insertBefore(images, (Element) p.getNode());
} else {
element.appendChild(images);
}
}
}
if (embeddedBppCombo.getSelectedIndex() == 0) {
ctx.removeAll("images/embedded");
} else {
p = ctx.getPointer("images/embedded");
Element embedded;
if (p != null) {
embedded = (Element) p.getNode();
} else {
embedded = dom.createElement("embedded");
p = ctx.getPointer("images");
if (p != null) {
Element images = (Element) p.getNode();
p = ctx.getPointer("images/standalone");
if (p != null) {
Element standalone = (Element) p.getNode();
images.insertBefore(embedded, standalone);
} else {
images.appendChild(embedded);
}
} else {
Element images = dom.createElement("images");
p = ctx.getPointer("category|description|schedule|transform|autoBookmark");
if (p != null) {
element.insertBefore(images, (Element) p.getNode());
} else {
element.appendChild(images);
}
images.appendChild(embedded);
}
}
populateEmbedded(embedded);
}
if (standaloneBppCombo.getSelectedIndex() == 0) {
ctx.removeAll("images/standalone");
} else {
p = ctx.getPointer("images/standalone");
Element standalone;
if (p != null) {
standalone = (Element) p.getNode();
} else {
standalone = dom.createElement("standalone");
p = ctx.getPointer("images");
if (p != null) {
Element images = (Element) p.getNode();
images.appendChild(standalone);
} else {
Element images = dom.createElement("images");
p = ctx.getPointer("category|description|schedule|transform|autoBookmark");
if (p != null) {
element.insertBefore(images, (Element) p.getNode());
} else {
element.appendChild(images);
}
images.appendChild(standalone);
}
}
populateStandalone(standalone);
}
String[] inclusionPatterns = inclusionPanel.getPatterns();
String[] exclusionPatterns = exclusionPanel.getPatterns();
if (inclusionPatterns.length > 0 || exclusionPatterns.length > 0) {
Element uriPatterns;
p = ctx.getPointer("uriPatterns");
if (p != null) {
uriPatterns = (Element) p.getNode();
} else {
p = ctx.getPointer("images|category|description|schedule|transform|autoBookmark");
uriPatterns = dom.createElement("uriPatterns");
if (p != null) {
element.insertBefore(uriPatterns, (Element) p.getNode());
} else {
element.appendChild(uriPatterns);
}
}
ctx.removeAll("uriPatterns/*");
for (int i = 0; i < inclusionPatterns.length; i++) {
Element include = dom.createElement("include");
include.appendChild(dom.createTextNode(inclusionPatterns[i]));
uriPatterns.appendChild(include);
}
for (int i = 0; i < exclusionPatterns.length; i++) {
Element exclude = dom.createElement("exclude");
exclude.appendChild(dom.createTextNode(exclusionPatterns[i]));
uriPatterns.appendChild(exclude);
}
} else {
ctx.remove("uriPatterns");
}
ctx.remove("filename");
if (filenameText.getText().length() > 0) {
Element filename = dom.createElement("filename");
filename.appendChild(dom.createTextNode(filenameText.getText()));
element.insertBefore(filename, (Element) ctx.getPointer("uri").getNode());
}
populateAttributes(element);
document.configureParentTemplate();