Repository(Element element) { this.element = element; id = element.getChildText("id"); name = element.getChildText("name"); url = element.getChildText("url"); layout = element.getChildText("layout"); if (element.hasSingleChild("snapshots")) { snapshots = new RepositoryPolicy(element.getSingleChild("snapshots")); } if (element.hasSingleChild("releases")) { releases = new RepositoryPolicy(element.getSingleChild("releases")); } }
/** * Sets repository releases details * * @param releases new repository releases details, if {@code null} then element will be removed * from xml if exists */ public Repository setReleases(RepositoryPolicy releases) { this.releases = releases; if (element != null) { if (releases == null) { element.removeChild("releases"); } else if (element.hasSingleChild("releases")) { releases.element = element.getSingleChild("releases").replaceWith(releases.asXMLElement("releases")); } else { element.appendChild(releases.asXMLElement("releases")); releases.element = element.getSingleChild("releases"); } } return this; }
/** * Sets repository snapshots details * * @param snapshots new repository snapshots details, if {@code null} then element will be removed * from xml if exists */ public Repository setSnapshots(RepositoryPolicy snapshots) { this.snapshots = snapshots; if (element != null) { if (snapshots == null) { element.removeChild("snapshots"); } else if (element.hasSingleChild("snapshots")) { snapshots.element = element.getSingleChild("snapshots").replaceWith(snapshots.asXMLElement("snapshots")); } else { element.insertChild(snapshots.asXMLElement("snapshots"), before("releases").or(inTheEnd())); snapshots.element = element.getSingleChild("snapshots"); } } return this; }
NewElement asXMLElement() { final NewElement repository = createElement("repository"); if (id != null) { repository.appendChild(createElement("id", id)); } if (name != null) { repository.appendChild(createElement("name", name)); } if (url != null) { repository.appendChild(createElement("url", url)); } if (layout != null) { repository.appendChild(createElement("layout", layout)); } if (snapshots != null) { repository.appendChild(snapshots.asXMLElement("snapshots")); } if (releases != null) { repository.appendChild(releases.asXMLElement("releases")); } return repository; }