Search in sources :

Example 76 with Attributes

use of org.xml.sax.Attributes in project acs-aem-commons by Adobe-Consulting-Services.

the class VersionedClientlibsTransformerFactoryTest method testCSSClientLibraryWithSameDomainedPath.

@Test
public void testCSSClientLibraryWithSameDomainedPath() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "href", "", "CDATA", "https://example.com/same/scheme/styles.css");
    in.addAttribute("", "type", "", "CDATA", "text/css");
    in.addAttribute("", "rel", "", "CDATA", "stylesheet");
    transformer.startElement(null, "link", null, in);
    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    assertEquals("https://example.com/same/scheme/styles.css", attributesCaptor.getValue().getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Test(org.junit.Test)

Example 77 with Attributes

use of org.xml.sax.Attributes in project acs-aem-commons by Adobe-Consulting-Services.

the class VersionedClientlibsTransformerFactoryTest method testMinifiedCSSClientLibraryWithEnforceMd5.

@Test
public void testMinifiedCSSClientLibraryWithEnforceMd5() throws Exception {
    PrivateAccessor.setField(factory, "enforceMd5", true);
    when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "href", "", "CDATA", PATH + ".min.css");
    in.addAttribute("", "type", "", "CDATA", "text/css");
    in.addAttribute("", "rel", "", "CDATA", "stylesheet");
    transformer.startElement(null, "link", null, in);
    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    assertEquals(PATH + ".min.ACSHASH" + FAKE_STREAM_CHECKSUM + ".css", attributesCaptor.getValue().getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Test(org.junit.Test)

Example 78 with Attributes

use of org.xml.sax.Attributes in project acs-aem-commons by Adobe-Consulting-Services.

the class ContentHandlerAdapterTest method test_adapted_methods.

@Test
public void test_adapted_methods() throws Exception {
    final Attributes attrs = new AttributesImpl();
    final char[] characters = new char[0];
    final char[] whitespace = new char[0];
    DefaultHandler adapter = new ContentHandlerAdapter(handler);
    adapter.setDocumentLocator(locator);
    adapter.startDocument();
    adapter.startPrefixMapping("prefix", "uri");
    adapter.endPrefixMapping("prefix");
    adapter.startElement("uri", "localName", "qName", attrs);
    adapter.endElement("uri", "localName", "qName");
    adapter.characters(characters, 1, 2);
    adapter.ignorableWhitespace(whitespace, 3, 4);
    adapter.processingInstruction("target", "data");
    adapter.skippedEntity("name");
    adapter.endDocument();
    verify(handler).setDocumentLocator(locator);
    verify(handler).startDocument();
    verify(handler).startPrefixMapping("prefix", "uri");
    verify(handler).endPrefixMapping("prefix");
    verify(handler).startElement("uri", "localName", "qName", attrs);
    verify(handler).endElement("uri", "localName", "qName");
    verify(handler).characters(characters, 1, 2);
    verify(handler).ignorableWhitespace(whitespace, 3, 4);
    verify(handler).processingInstruction("target", "data");
    verify(handler).skippedEntity("name");
    verify(handler).endDocument();
    verifyNoMoreInteractions(handler);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Test(org.junit.Test)

Example 79 with Attributes

use of org.xml.sax.Attributes in project ant-ivy by apache.

the class ResolveTest method testResolveConflict.

@Test
public void testResolveConflict() throws Exception {
    // mod4.1 v 4.1 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
    ResolveReport report = ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.1.xml"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.1");
    assertEquals(mrid, md.getModuleRevisionId());
    assertTrue(getResolvedIvyFileInCache(mrid).exists());
    // 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);
    File r = getConfigurationResolveReportInCache(ResolveOptions.getDefaultResolveId(md), "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());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Attributes(org.xml.sax.Attributes) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) SAXParser(javax.xml.parsers.SAXParser) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) JarFile(java.util.jar.JarFile) File(java.io.File) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Test(org.junit.Test)

Example 80 with Attributes

use of org.xml.sax.Attributes in project ant-ivy by apache.

the class ResolveTest method testLatest.

@Test
public void testLatest() throws Exception {
    // mod1.4 depends on latest mod1.2
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml"), getResolveOptions(new String[] { "default" }));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1");
    assertEquals(mrid, md.getModuleRevisionId());
    assertTrue(getResolvedIvyFileInCache(mrid).exists());
    // dependencies
    ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "2.2");
    ConfigurationResolveReport crr = report.getConfigurationReport("default");
    assertNotNull(crr);
    assertEquals(1, crr.getDownloadReports(depId).length);
    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 ("artifact".equals(qName) && "mod1.2".equals(attributes.getValue("name"))) {
                found[0] = true;
            }
        }
    });
    assertTrue(found[0]);
    assertTrue(getIvyFileInCache(depId).exists());
    assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Attributes(org.xml.sax.Attributes) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) SAXParser(javax.xml.parsers.SAXParser) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) JarFile(java.util.jar.JarFile) File(java.io.File) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Test(org.junit.Test)

Aggregations

Attributes (org.xml.sax.Attributes)279 DefaultHandler (org.xml.sax.helpers.DefaultHandler)74 SAXException (org.xml.sax.SAXException)66 AttributesImpl (org.xml.sax.helpers.AttributesImpl)50 SAXParser (javax.xml.parsers.SAXParser)48 Test (org.junit.Test)46 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)37 InputSource (org.xml.sax.InputSource)33 SAXParserFactory (javax.xml.parsers.SAXParserFactory)30 IOException (java.io.IOException)29 File (java.io.File)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)17 ArrayList (java.util.ArrayList)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 Test (org.junit.jupiter.api.Test)17 XMLReader (org.xml.sax.XMLReader)17 ContentHandler (org.xml.sax.ContentHandler)15 StringReader (java.io.StringReader)12 Transformer (org.apache.sling.rewriter.Transformer)10