use of org.xml.sax.Attributes in project ant-ivy by apache.
the class ResolveTest method testResolveConflict2.
@Test
public void testResolveConflict2() throws Exception {
// mod4.1 v 4.14 depends on
// - mod1.1 v 1.0 which depends on mod1.2 v 2.0
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
// - mod6.1 v 0.3 which depends on mod1.2 v 2.0
ResolveReport report = ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.14.xml"), getResolveOptions(new String[] { "*" }));
// dependencies
ConfigurationResolveReport crr = report.getConfigurationReport("default");
assertNotNull(crr);
assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).length);
assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).length);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.14");
File r = getConfigurationResolveReportInCache(ResolveOptions.getDefaultResolveId(mrid.getModuleId()), "default");
assertTrue(r.exists());
final boolean[] found = new boolean[] { false };
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(r, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) {
found[0] = true;
}
}
});
// the report should contain the evicted revision
assertTrue(found[0]);
assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists());
assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists());
assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
}
use of org.xml.sax.Attributes in project ant-ivy by apache.
the class ResolveTest method testMultiConfs.
@Test
public void testMultiConfs() throws Exception {
// mod 5.2 depends on mod5.1 conf B in its conf B and conf A in its conf A
// mod5.1 conf B publishes art51B
// mod5.1 conf A publishes art51A
ResolveReport report = ivy.resolve(new File("test/repositories/2/mod5.2/ivy-2.0.xml"), getResolveOptions(new String[] { "B", "A" }));
assertNotNull(report);
ModuleDescriptor md = report.getModuleDescriptor();
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "2.0");
assertEquals(mrid, md.getModuleRevisionId());
assertTrue(getResolvedIvyFileInCache(mrid).exists());
// dependencies
ModuleRevisionId depId = ModuleRevisionId.newInstance("org5", "mod5.1", "4.1");
ConfigurationResolveReport crr = report.getConfigurationReport("A");
assertNotNull(crr);
assertEquals(1, crr.getDownloadReports(depId).length);
File r = new File(cache, ResolveOptions.getDefaultResolveId(mrid.getModuleId()) + "-A.xml");
assertTrue(r.exists());
final boolean[] found = new boolean[] { false };
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(r, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if ("artifact".equals(qName) && "art51B".equals(attributes.getValue("name"))) {
found[0] = true;
}
}
});
assertFalse(found[0]);
assertTrue(getIvyFileInCache(depId).exists());
assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists());
assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists());
}
use of org.xml.sax.Attributes in project mdw-designer by CenturyLinkCloud.
the class TestResultsParser method parseXml.
public void parseXml() throws Exception {
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(suiteResults);
InputSource src = new InputSource(inputStream);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
parser.parse(src, new DefaultHandler() {
TestCase currentTestCase = null;
// attributes for workflow project
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.equals("testcase")) {
for (TestCase testCase : testCases) {
if (testCase.getPath().equals(attrs.getValue("name"))) {
currentTestCase = testCase;
String timestampStr = attrs.getValue("timestamp");
if (timestampStr != null) {
Calendar cal = DatatypeConverter.parseDateTime(timestampStr);
testCase.setStartDate(cal.getTime());
String timeStr = attrs.getValue("time");
if (timeStr != null) {
int ms = (int) Float.parseFloat(timeStr) * 1000;
cal.add(Calendar.MILLISECOND, ms);
testCase.setEndDate(cal.getTime());
// assume pass
testCase.setStatus(TestCase.STATUS_PASS);
}
}
}
}
} else if (qName.equals("failure")) {
if (currentTestCase != null) {
currentTestCase.setStatus(TestCase.STATUS_FAIL);
TestCaseRun firstRun = currentTestCase.getFirstRun();
if (firstRun != null)
firstRun.setMessage(attrs.getValue("message"));
}
} else if (qName.equals("error")) {
if (currentTestCase != null) {
currentTestCase.setStatus(TestCase.STATUS_ERROR);
TestCaseRun firstRun = currentTestCase.getFirstRun();
if (firstRun != null)
firstRun.setMessage(attrs.getValue("message"));
}
}
}
});
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException ex) {
}
}
}
}
use of org.xml.sax.Attributes in project mdw-designer by CenturyLinkCloud.
the class Discoverer method parseDirectoryResponse.
/**
* Use SAX for quick processing.
*/
private List<String> parseDirectoryResponse(String content) throws IOException, SAXException, ParserConfigurationException {
final List<String> urls = new ArrayList<>();
InputStream xmlStream = new ByteArrayInputStream(content.getBytes());
InputSource src = new InputSource(xmlStream);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
parser.parse(src, new DefaultHandler() {
boolean inHtml;
boolean inUl;
boolean inLi;
boolean inA;
String a;
String href;
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.equals("html"))
inHtml = true;
else if (// New Apache
qName.equals("ul") || qName.equals("tr"))
// format
// uses "tr"
// and "td",
// instead of
// "ul" and
// "li"
// elements
inUl = true;
else if (qName.equals("li") || qName.equals("td"))
inLi = true;
else if (qName.equals("a"))
inA = true;
if (inHtml && inUl && inLi && inA && href == null)
href = attrs.getValue("href");
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("a") && inHtml && inUl && inLi && href != null && (href.equals(a) || href.equals(a + "/") || href.substring(href.lastIndexOf("/", href.length() - 2) + 1).equals(a))) {
if (// parent
!href.startsWith("/") && !href.startsWith("../"))
// directories
urls.add(href);
else if (!href.substring(href.lastIndexOf("/", href.length() - 2) + 1).startsWith(// For new Apache directory
"/"))
// listing format
urls.add(href.substring(href.lastIndexOf("/", href.length() - 2) + 1));
}
if (qName.equals("html"))
inHtml = false;
else if (qName.equals("ul") || qName.equals("tr"))
inUl = false;
else if (qName.equals("li") || qName.equals("td"))
inLi = false;
else if (qName.equals("a")) {
inA = false;
href = null;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (inHtml && inUl && inLi && inA)
a = new String(ch).substring(start, start + length).trim();
else
a = null;
}
});
return urls;
}
use of org.xml.sax.Attributes in project mdw-designer by CenturyLinkCloud.
the class TabDescriptorProvider method getPageletTabs.
protected List<PageletTab> getPageletTabs(WorkflowElement element) {
List<PageletTab> tabs = null;
WorkflowProject project = element.getProject();
if (project.checkRequiredVersion(5, 5)) {
String elementType = element.getTitle();
List<PageletTab> allProjTabs = project.getPageletTabs();
if (allProjTabs != null) {
for (PageletTab pageletTab : allProjTabs) {
InputStream inStream = new ByteArrayInputStream(pageletTab.getXml().getBytes());
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
try {
SAXParser parser = parserFactory.newSAXParser();
final List<String> types = new ArrayList<String>();
parser.parse(inStream, new DefaultHandler() {
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.equalsIgnoreCase("PAGELET")) {
String appliesTo = attrs.getValue("APPLIES_TO");
if (appliesTo != null) {
for (String type : appliesTo.split(",")) types.add(type);
}
}
}
});
if (types.contains(elementType)) {
if (tabs == null)
tabs = new ArrayList<PageletTab>();
tabs.add(pageletTab);
}
} catch (Exception ex) {
// don't prevent processing
PluginMessages.log(ex);
// other pagelets
}
}
}
}
return tabs;
}
Aggregations