1 package com.atlassian.seraph.util;
2
3
4
5
6
7
8 public class ServerInformationParser
9 {
10
11
12
13
14
15
16
17
18
19
20
21 public static ServerInformation parse(String serverInformationText)
22 {
23 if (!serverInformationText.contains("/"))
24 {
25 throw new IllegalArgumentException("Server information is not present: " + serverInformationText);
26 }
27
28 int slashLoc = serverInformationText.indexOf("/");
29 String name = serverInformationText.substring(0, slashLoc);
30
31
32 if (serverInformationText.indexOf(" ", slashLoc) == -1)
33 {
34
35 String version = serverInformationText.substring(slashLoc + 1);
36 return new ServerInformation(name, version);
37 }
38 else
39 {
40
41 int spaceLoc = serverInformationText.indexOf(" ", slashLoc);
42 String version = serverInformationText.substring(slashLoc + 1, spaceLoc);
43 String otherInformation = serverInformationText.substring(spaceLoc + 2, serverInformationText.length() - 1);
44 return new ServerInformation(name, version, otherInformation);
45 }
46 }
47
48
49
50
51
52
53 public static class ServerInformation
54 {
55 private final String name;
56 private final String version;
57 private final String otherInformation;
58
59 private ServerInformation(String name, String version)
60 {
61 this(name, version, null);
62 }
63
64 private ServerInformation(String name, String version, String otherInformation)
65 {
66 this.name = name;
67 this.version = version;
68 this.otherInformation = otherInformation;
69 }
70
71 public String getName()
72 {
73 return name;
74 }
75
76 public String getVersion()
77 {
78 return version;
79 }
80
81 public String getOtherInformation()
82 {
83 return otherInformation;
84 }
85
86 public boolean isApacheTomcat()
87 {
88 return "Apache Tomcat".equals(name);
89 }
90 }
91 }