1 | /** | | 1 | private void copyArgo(File file, String encoding, PrintWriter writer) |
2 | * Reads an XML file of uml format and extracts the persistence version | | 2 | throws IOException, MalformedURLException, OpenException, |
3 | * number from the root tag. | | 3 | UnsupportedEncodingException { |
4 | * | | 4 | |
5 | * @param inputStream the stream point to the XML file | | 5 | int pgmlCount = getPgmlCount(file); |
6 | * @return The ArgoUML release number | | 6 | boolean containsToDo = containsTodo(file); |
7 | * @throws OpenException on any error | | 7 | boolean containsProfile = containsProfile(file); |
8 | */ | | 8 | |
9 | protected String getReleaseVersion(InputStream inputStream) | | 9 | // first read the .argo file from Zip |
10 | throws OpenException { | | 10 | ZipInputStream zis = |
11 | | | 11 | openZipStreamAt(toURL(file), FileConstants.PROJECT_FILE_EXT); |
12 | BufferedReader reader = null; | | 12 | |
13 | try { | | 13 | if (zis == null) { |
14 | reader = new BufferedReader(new InputStreamReader(inputStream, Argo | | 14 | throw new OpenException( |
15 | .getEncoding())); | | 15 | "There is no .argo file in the .zargo"); |
16 | String versionLine = reader.readLine(); | | 16 | } |
17 | while (!versionLine.trim().startsWith("<version>")) { | | 17 | |
18 | versionLine = reader.readLine(); | | 18 | String line; |
19 | if (versionLine == null) { | | 19 | BufferedReader reader = |
20 | throw new OpenException( | | 20 | new BufferedReader(new InputStreamReader(zis, encoding)); |
21 | "Failed to find the release <version> tag"); | | 21 | // Keep reading till we hit the <argo> tag |
22 | } | | 22 | String rootLine; |
23 | } | | 23 | do { |
24 | versionLine = versionLine.trim(); | | 24 | rootLine = reader.readLine(); |
25 | int end = versionLine.lastIndexOf("</version>"); | | 25 | if (rootLine == null) { |
26 | return versionLine.trim().substring(9, end); | | 26 | throw new OpenException( |
27 | } catch (IOException e) { | | 27 | "Can't find an <argo> tag in the argo file"); |
28 | throw new OpenException(e); | | 28 | } |
29 | } catch (NumberFormatException e) { | | 29 | } while(!rootLine.startsWith("<argo")); |
30 | throw new OpenException(e); | | 30 | |
31 | } finally { | | 31 | |
32 | try { | | 32 | // Get the version from the tag. |
33 | if (inputStream != null) { | | 33 | String version = getVersion(rootLine); |
34 | inputStream.close(); | | 34 | writer.println("<uml version=\"" + version + "\">"); |
35 | } | | 35 | writer.println(rootLine); |
36 | if (reader != null) { | | 36 | LOG.info("Transfering argo contents"); |
37 | reader.close(); | | 37 | int memberCount = 0; |
38 | } | | 38 | while ((line = reader.readLine()) != null) { |
39 | } catch (IOException e) { | | 39 | if (line.trim().startsWith("<member")) { |
40 | // No more we can do here on failure | | 40 | ++memberCount; |
41 | } | | 41 | } |
42 | } | | 42 | if (line.trim().equals("</argo>") && memberCount == 0) { |
43 | } | | 43 | LOG.info("Inserting member info"); |
| | | 44 | writer.println("<member type='xmi' name='.xmi' />"); |
| | | 45 | for (int i = 0; i < pgmlCount; ++i) { |
| | | 46 | writer.println("<member type='pgml' name='.pgml' />"); |
| | | 47 | } |
| | | 48 | if (containsToDo) { |
| | | 49 | writer.println("<member type='todo' name='.todo' />"); |
| | | 50 | } |
| | | 51 | if (containsProfile) { |
| | | 52 | String type = ProfileConfiguration.EXTENSION; |
| | | 53 | writer.println("<member type='" + type + "' name='." |
| | | 54 | + type + "' />"); |
| | | 55 | } |
| | | 56 | } |
| | | 57 | writer.println(line); |
| | | 58 | } |
| | | 59 | if (LOG.isInfoEnabled()) { |
| | | 60 | LOG.info("Member count = " + memberCount); |
| | | 61 | } |
| | | 62 | zis.close(); |
| | | 63 | reader.close(); |
| | | 64 | } |