| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck.xml.pom; |
| 19 | |
|
| 20 | |
import java.util.ArrayDeque; |
| 21 | |
import java.util.Deque; |
| 22 | |
import org.xml.sax.Attributes; |
| 23 | |
import org.xml.sax.SAXException; |
| 24 | |
import org.xml.sax.helpers.DefaultHandler; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 2 | public class PomHandler extends DefaultHandler { |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public static final String PROJECT = "project"; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public static final String GROUPID = "groupId"; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public static final String ARTIFACTID = "artifactId"; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public static final String VERSION = "version"; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public static final String PARENT = "parent"; |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public static final String NAME = "name"; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public static final String ORGANIZATION = "organization"; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public static final String DESCRIPTION = "description"; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public static final String LICENSES = "licenses"; |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public static final String LICENSE = "license"; |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public static final String URL = "url"; |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | 2 | private final Model model = new Model(); |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public Model getModel() { |
| 89 | 2 | return model; |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | 2 | private final Deque<String> stack = new ArrayDeque<String>(); |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | 2 | private License license = null; |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
private StringBuilder currentText; |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
@Override |
| 115 | |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
| 116 | 471 | currentText = new StringBuilder(); |
| 117 | 471 | stack.push(qName); |
| 118 | 471 | if (LICENSE.equals(qName)) { |
| 119 | 0 | license = new License(); |
| 120 | |
} |
| 121 | 471 | } |
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public void endElement(String uri, String localName, String qName) throws SAXException { |
| 133 | 471 | stack.pop(); |
| 134 | 471 | final String parentNode = stack.peek(); |
| 135 | 471 | if (PROJECT.equals(parentNode)) { |
| 136 | 29 | if (GROUPID.equals(qName)) { |
| 137 | 2 | model.setGroupId(currentText.toString()); |
| 138 | 27 | } else if (ARTIFACTID.equals(qName)) { |
| 139 | 2 | model.setArtifactId(currentText.toString()); |
| 140 | 25 | } else if (VERSION.equals(qName)) { |
| 141 | 1 | model.setVersion(currentText.toString()); |
| 142 | 24 | } else if (NAME.equals(qName)) { |
| 143 | 2 | model.setName(currentText.toString()); |
| 144 | 22 | } else if (ORGANIZATION.equals(qName)) { |
| 145 | 0 | model.setOrganization(currentText.toString()); |
| 146 | 22 | } else if (DESCRIPTION.equals(qName)) { |
| 147 | 1 | model.setDescription(currentText.toString()); |
| 148 | |
} |
| 149 | 442 | } else if (PARENT.equals(parentNode)) { |
| 150 | 3 | if (GROUPID.equals(qName)) { |
| 151 | 1 | model.setParentGroupId(currentText.toString()); |
| 152 | 2 | } else if (ARTIFACTID.equals(qName)) { |
| 153 | 1 | model.setParentArtifactId(currentText.toString()); |
| 154 | 1 | } else if (VERSION.equals(qName)) { |
| 155 | 1 | model.setParentVersion(currentText.toString()); |
| 156 | |
} |
| 157 | 439 | } else if (LICENSE.equals(parentNode)) { |
| 158 | 0 | if (license != null) { |
| 159 | 0 | if (NAME.equals(qName)) { |
| 160 | 0 | license.setName(currentText.toString()); |
| 161 | 0 | } else if (URL.equals(qName)) { |
| 162 | 0 | license.setUrl(currentText.toString()); |
| 163 | |
} |
| 164 | |
|
| 165 | |
|
| 166 | |
} |
| 167 | 439 | } else if (LICENSES.equals(parentNode)) { |
| 168 | 0 | if (LICENSE.equals(qName)) { |
| 169 | 0 | if (license != null) { |
| 170 | 0 | model.addLicense(license); |
| 171 | |
|
| 172 | |
|
| 173 | |
} |
| 174 | |
} |
| 175 | |
} |
| 176 | 471 | } |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
@Override |
| 187 | |
public void characters(char[] ch, int start, int length) throws SAXException { |
| 188 | 953 | currentText.append(ch, start, length); |
| 189 | 953 | } |
| 190 | |
} |