| 1 | |
package org.jtheque.core.managers.update.repository; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jdom.Element; |
| 20 | |
import org.jtheque.core.managers.Managers; |
| 21 | |
import org.jtheque.core.managers.log.ILoggingManager; |
| 22 | |
import org.jtheque.core.utils.file.XMLException; |
| 23 | |
import org.jtheque.core.utils.file.XMLReader; |
| 24 | |
import org.jtheque.utils.StringUtils; |
| 25 | |
import org.jtheque.utils.bean.InternationalString; |
| 26 | |
import org.jtheque.utils.bean.Version; |
| 27 | |
import org.jtheque.utils.io.FileUtils; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public final class RepositoryReader { |
| 35 | |
private final Repository repository; |
| 36 | |
private final XMLReader reader; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public RepositoryReader() { |
| 42 | 0 | super(); |
| 43 | |
|
| 44 | 0 | repository = new Repository(); |
| 45 | 0 | reader = new XMLReader(); |
| 46 | 0 | } |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
public Repository read(String strUrl) { |
| 55 | |
try { |
| 56 | 0 | reader.openURL(strUrl); |
| 57 | |
|
| 58 | 0 | read(); |
| 59 | 0 | } catch (XMLException e) { |
| 60 | 0 | Managers.getManager(ILoggingManager.class).getLogger(getClass()).error(e, "Unable to get information from repository"); |
| 61 | |
} finally { |
| 62 | 0 | FileUtils.close(reader); |
| 63 | 0 | } |
| 64 | |
|
| 65 | 0 | return repository; |
| 66 | |
} |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private void read() throws XMLException { |
| 74 | 0 | readTitle(reader); |
| 75 | 0 | readApplication(reader); |
| 76 | 0 | readModules(reader); |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
private void readApplication(XMLReader reader) throws XMLException { |
| 86 | 0 | repository.setApplication(reader.readString("application", reader.getRootElement())); |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
private void readModules(XMLReader reader) throws XMLException { |
| 96 | 0 | for (Object currentNode : reader.getNodes("modules/module", reader.getRootElement())) { |
| 97 | 0 | ModuleDescription module = new ModuleDescription(); |
| 98 | |
|
| 99 | 0 | module.setId(reader.readString("id", currentNode)); |
| 100 | 0 | module.setName(reader.readString("name", currentNode)); |
| 101 | |
|
| 102 | 0 | if (StringUtils.isEmpty(reader.readString("core", currentNode))) { |
| 103 | 0 | module.setCoreVersion(Managers.getCore().getCoreCurrentVersion()); |
| 104 | |
} else { |
| 105 | 0 | module.setCoreVersion(new Version(reader.readString("core", currentNode))); |
| 106 | |
} |
| 107 | |
|
| 108 | 0 | module.setVersionsFileURL(reader.readString("versions", currentNode)); |
| 109 | |
|
| 110 | 0 | Element descriptionElement = reader.getNode("description", currentNode); |
| 111 | |
|
| 112 | 0 | InternationalString description = new InternationalString(); |
| 113 | |
|
| 114 | 0 | for (Object child : descriptionElement.getChildren()) { |
| 115 | 0 | Element childElement = (Element) child; |
| 116 | |
|
| 117 | 0 | description.put(childElement.getName(), childElement.getValue()); |
| 118 | 0 | } |
| 119 | |
|
| 120 | 0 | module.setDescription(description); |
| 121 | |
|
| 122 | 0 | repository.getModules().add(module); |
| 123 | 0 | } |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
private void readTitle(XMLReader reader) throws XMLException { |
| 133 | 0 | InternationalString title = new InternationalString(); |
| 134 | |
|
| 135 | 0 | Element titleElement = reader.getNode("title", reader.getRootElement()); |
| 136 | |
|
| 137 | 0 | for (Object child : titleElement.getChildren()) { |
| 138 | 0 | Element childElement = (Element) child; |
| 139 | |
|
| 140 | 0 | title.put(childElement.getName(), childElement.getValue()); |
| 141 | 0 | } |
| 142 | |
|
| 143 | 0 | repository.setTitle(title); |
| 144 | 0 | } |
| 145 | |
} |