1 package org.apache.maven.plugin.cxx.utils.svn;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.xml.sax.helpers.DefaultHandler;
22 import org.xml.sax.SAXException;
23 import org.xml.sax.Attributes;
24
25 import java.util.regex.Pattern;
26
27
28
29
30
31 public class SvnInfo extends DefaultHandler
32 {
33 private String url = null;
34 private String root = null;
35 private String relativeUrl = null;
36 private long revision = -1;
37
38 public void reset()
39 {
40 url = null;
41 root = null;
42 relativeUrl = null;
43 revision = -1;
44 }
45
46 public boolean isValide()
47 {
48 return url != null && root != null && relativeUrl != null && revision != -1;
49 }
50
51 public String getSvnUrl()
52 {
53 return url;
54 }
55
56 public String getSvnRoot()
57 {
58 return root;
59 }
60
61 public String getSvnRelativeUrl()
62 {
63 return relativeUrl;
64 }
65
66 public long getRevision()
67 {
68 return revision;
69 }
70
71 public String toString()
72 {
73 return "r" + revision + " " + root + " " + relativeUrl;
74 }
75
76 private boolean bUrl = false;
77 private boolean bRoot = false;
78 private boolean bRelativeUrl = false;
79
80 @Override
81 public void startElement( String uri, String localName, String qName, Attributes attributes )
82 throws SAXException
83 {
84 if ( qName.equalsIgnoreCase( "entry" ) )
85 {
86 String sRev = attributes.getValue( "revision" );
87 try
88 {
89 revision = Long.parseLong( sRev );
90 }
91 catch ( Exception e )
92 {
93 throw new SAXException( "URI or folder svn revision not found", e );
94 }
95 }
96 else if ( qName.equalsIgnoreCase( "url" ) )
97 {
98 bUrl = true;
99 }
100 else if ( qName.equalsIgnoreCase( "root" ) )
101 {
102 bRoot = true;
103 }
104 else if ( qName.equalsIgnoreCase( "relative-url" ) )
105 {
106 bRelativeUrl = true;
107 }
108 }
109
110 @Override
111 public void characters( char ch[], int start, int length ) throws SAXException
112 {
113 if ( bUrl )
114 {
115 url = new String( ch, start, length );
116 bUrl = false;
117 }
118 else if ( bRoot )
119 {
120 root = new String( ch, start, length );
121 bRoot = false;
122 }
123 else if ( bRelativeUrl )
124 {
125 relativeUrl = new String( ch, start, length );
126 bRelativeUrl = false;
127 }
128 }
129
130 @Override
131 public void endDocument() throws SAXException
132 {
133 if ( relativeUrl == null && url != null && root != null )
134 {
135 relativeUrl = url.replaceFirst( Pattern.quote( root ), "^" );
136 }
137 }
138 }