Search in sources :

Example 71 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testJavaScriptClientLibraryWithRelativePath.

@Test
public void testJavaScriptClientLibraryWithRelativePath() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "src", "", "CDATA", "relative/script.js");
    in.addAttribute("", "type", "", "CDATA", "text/javascript");
    transformer.startElement(null, "script", null, in);
    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, only()).startElement(isNull(String.class), eq("script"), isNull(String.class), attributesCaptor.capture());
    assertEquals("relative/script.js", attributesCaptor.getValue().getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Test(org.junit.Test)

Example 72 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testJavaScriptClientLibrary.

@Test
public void testJavaScriptClientLibrary() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "src", "", "CDATA", PATH + ".js");
    in.addAttribute("", "type", "", "CDATA", "text/javascript");
    transformer.startElement(null, "script", null, in);
    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, only()).startElement(isNull(String.class), eq("script"), isNull(String.class), attributesCaptor.capture());
    assertEquals(PATH + "." + FAKE_STREAM_CHECKSUM + ".js", attributesCaptor.getValue().getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Test(org.junit.Test)

Example 73 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testJavaScriptClientLibraryWithDomainedPath.

@Test
public void testJavaScriptClientLibraryWithDomainedPath() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "src", "", "CDATA", "http://www.example.com/same/scheme/script.js");
    in.addAttribute("", "type", "", "CDATA", "text/javascript");
    transformer.startElement(null, "script", null, in);
    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, only()).startElement(isNull(String.class), eq("script"), isNull(String.class), attributesCaptor.capture());
    assertEquals("http://www.example.com/same/scheme/script.js", attributesCaptor.getValue().getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Test(org.junit.Test)

Example 74 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testCSSClientLibraryWithRelAttributeValueDiffersFromStylesheet.

@Test
public void testCSSClientLibraryWithRelAttributeValueDiffersFromStylesheet() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "href", "", "CDATA", PATH + ".css");
    in.addAttribute("", "type", "", "CDATA", "text/css");
    in.addAttribute("", "rel", "", "CDATA", "preload");
    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 + "." + 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 75 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testMinifiedCSSClientLibrary.

@Test
public void testMinifiedCSSClientLibrary() throws Exception {
    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." + 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)

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