Search in sources :

Example 66 with Attributes

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

the class StaticReferenceRewriteTransformerFactoryTest method test_without_config_is_noop.

@Test
public void test_without_config_is_noop() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "href", null, "CDATA", "/etc/clientlib/test.css");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("/etc/clientlib/test.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Example 67 with Attributes

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

the class StaticReferenceRewriteTransformerFactoryTest method test_with_nonrewritten_attribute.

@Test
public void test_with_nonrewritten_attribute() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    ctx.setProperty("prefixes", new String[] { "/etc/clientlib" });
    ctx.setProperty("host.pattern", "static{}.host.com");
    ctx.setProperty("host.count", 2);
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "src", null, "CDATA", "/etc/clientlib/testABC.css");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("/etc/clientlib/testABC.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Example 68 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testJavaScriptClientLibraryWithSameSchemePath.

@Test
public void testJavaScriptClientLibraryWithSameSchemePath() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "src", "", "CDATA", "//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("//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 69 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testJavaScriptClientLibraryWithInvalidExtension.

@Test
public void testJavaScriptClientLibraryWithInvalidExtension() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "src", "", "CDATA", PATH + ".vbs");
    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 + ".vbs", attributesCaptor.getValue().getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Test(org.junit.Test)

Example 70 with Attributes

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

the class VersionedClientlibsTransformerFactoryTest method testCSSClientLibraryWithInvalidExtension.

@Test
public void testCSSClientLibraryWithInvalidExtension() throws Exception {
    when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary);
    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "href", "", "CDATA", PATH + ".styles");
    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 + ".styles", 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