Search in sources :

Example 1 with PortletContext

use of javax.portlet.PortletContext in project uPortal by Jasig.

the class FilterConfigImplTest method testParams.

@Test
public void testParams() {
    final List<InitParamType> initParams = new ArrayList<InitParamType>();
    InitParamType p1 = new InitParamType();
    p1.setParamName("param1");
    p1.setParamValue("value1");
    InitParamType p2 = new InitParamType();
    p2.setParamName("param2");
    p2.setParamValue("value2");
    initParams.add(p1);
    initParams.add(p2);
    final String filterName = "filterWithParams";
    PortletContext portletContext = EasyMock.createMock(PortletContext.class);
    EasyMock.replay(portletContext);
    FilterConfigImpl impl = new FilterConfigImpl(filterName, initParams, portletContext);
    Assert.assertEquals(filterName, impl.getFilterName());
    Assert.assertEquals("value1", impl.getInitParameter("param1"));
    Assert.assertEquals("value2", impl.getInitParameter("param2"));
    Assert.assertNotNull(impl.getPortletContext());
}
Also used : ArrayList(java.util.ArrayList) InitParamType(org.apache.pluto.container.om.portlet.impl.InitParamType) PortletContext(javax.portlet.PortletContext) Test(org.junit.Test)

Example 2 with PortletContext

use of javax.portlet.PortletContext in project uPortal by Jasig.

the class AbstractDynamicSkinService method getSkinNames.

@Override
public /**
     * Returns the set of skins to use.  This implementation parses the skinList.xml file and returns the set of
     * skin-key element values.  If there is an error parsing the XML file, return an empty set.
     */
SortedSet<String> getSkinNames(PortletRequest request) {
    // Context to access the filesystem
    PortletContext ctx = request.getPortletSession().getPortletContext();
    // Determine the full path to the skins directory
    String skinsFilepath = ctx.getRealPath(this.localRelativeRootPath + "/skinList.xml");
    // Create File object to access the filesystem
    File skinList = new File(skinsFilepath);
    TreeSet<String> skins = new TreeSet<>();
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(skinList);
        doc.getDocumentElement().normalize();
        NodeList nList = doc.getElementsByTagName("skin-key");
        for (int temp = 0; temp < nList.getLength(); temp++) {
            org.w3c.dom.Element element = (org.w3c.dom.Element) nList.item(temp);
            String skinName = element.getTextContent();
            log.debug("Found skin-key value {}", skinName);
            skins.add(skinName);
        }
    } catch (SAXException | ParserConfigurationException | IOException e) {
        log.error("Error processing skinsFilepath {}", skinsFilepath, e);
    }
    return skins;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(net.sf.ehcache.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) TreeSet(java.util.TreeSet) PortletContext(javax.portlet.PortletContext) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 3 with PortletContext

use of javax.portlet.PortletContext in project uPortal by Jasig.

the class FilterConfigImplTest method testControl.

@Test
public void testControl() {
    final List<InitParamType> initParams = new ArrayList<InitParamType>();
    final String filterName = "controlFilter";
    PortletContext portletContext = EasyMock.createMock(PortletContext.class);
    EasyMock.replay(portletContext);
    FilterConfigImpl impl = new FilterConfigImpl(filterName, initParams, portletContext);
    Assert.assertEquals(filterName, impl.getFilterName());
    Assert.assertNull(impl.getInitParameter("someparam"));
    Assert.assertNull(impl.getInitParameter("someparam2"));
    Assert.assertNotNull(impl.getPortletContext());
}
Also used : ArrayList(java.util.ArrayList) InitParamType(org.apache.pluto.container.om.portlet.impl.InitParamType) PortletContext(javax.portlet.PortletContext) Test(org.junit.Test)

Example 4 with PortletContext

use of javax.portlet.PortletContext in project uPortal by Jasig.

the class AbstractDynamicSkinService method processLessFile.

/**
     * Less compile the include file into a temporary css file.  When done rename the temporary css file to the
     * correct output filename.  Since the less compilation phase takes several seconds, this insures the
     * output css file is does not exist on the filesystem until it is complete.
     * 
     * @param lessIncludeFilepath less include file that includes all dependencies
     * @param outputFilepath name of the output css file
     * @param lessCssJavascriptUrl lessCssJavascript compiler url
     * @throws IOException
     * @throws LessException
     */
private void processLessFile(DynamicSkinInstanceData data) throws IOException, LessException {
    final PortletContext ctx = data.getPortletRequest().getPortletSession().getPortletContext();
    final URL lessCssJavascriptUrl = ctx.getResource(this.lessCssJavascriptUrlPath);
    final LessSource lessSource = new LessSource(new File(this.getSkinLessPath(data)));
    if (log.isDebugEnabled()) {
        final String result = lessSource.getNormalizedContent();
        final File lessSourceOutput = new File(this.getSkinCssTempFileAbsolutePath(data) + "lesssource");
        IOUtils.write(result, new FileOutputStream(lessSourceOutput));
        log.debug("Full Less source from include file {0}, using lessCssJavascript at {1}" + ", is at {2}, output css will be written to {3}", this.getSkinLessPath(data), lessCssJavascriptUrl.toString(), lessSourceOutput, this.getSkinCssPath(data));
    }
    final LessCompiler compiler = new LessCompiler();
    compiler.setLessJs(lessCssJavascriptUrl);
    compiler.setCompress(true);
    final File tempOutputFile = new File(this.getSkinCssTempFileAbsolutePath(data));
    compiler.compile(lessSource, tempOutputFile);
    this.moveCssFileToFinalLocation(data, tempOutputFile);
}
Also used : LessSource(org.lesscss.LessSource) FileOutputStream(java.io.FileOutputStream) LessCompiler(org.lesscss.LessCompiler) PortletContext(javax.portlet.PortletContext) File(java.io.File) URL(java.net.URL)

Aggregations

PortletContext (javax.portlet.PortletContext)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 InitParamType (org.apache.pluto.container.om.portlet.impl.InitParamType)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 TreeSet (java.util.TreeSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Element (net.sf.ehcache.Element)1 LessCompiler (org.lesscss.LessCompiler)1 LessSource (org.lesscss.LessSource)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1