Search in sources :

Example 6 with OLog

use of org.olat.core.logging.OLog in project OpenOLAT by OpenOLAT.

the class STCourseNode method getDisplayOption.

/**
 * @see org.olat.course.nodes.GenericCourseNode#getDefaultTitleOption()
 */
@Override
public String getDisplayOption() {
    // if nothing other defined, view content only, when a structure node
    // contains an html-file.
    OLog logger = Tracing.createLoggerFor(this.getClass());
    ModuleConfiguration config = getModuleConfiguration();
    String thisConf = super.getDisplayOption(false);
    if (thisConf == null && config.get(STCourseNodeEditController.CONFIG_KEY_DISPLAY_TYPE).equals(STCourseNodeEditController.CONFIG_VALUE_DISPLAY_FILE)) {
        if (logger.isDebug()) {
            logger.debug("no displayOption set, use default (content)", thisConf);
        }
        return CourseNode.DISPLAY_OPTS_CONTENT;
    }
    if (logger.isDebug()) {
        logger.debug("there is a config set, use it: " + thisConf);
    }
    return super.getDisplayOption();
}
Also used : OLog(org.olat.core.logging.OLog) ModuleConfiguration(org.olat.modules.ModuleConfiguration)

Example 7 with OLog

use of org.olat.core.logging.OLog in project OpenOLAT by OpenOLAT.

the class CPCourseNode method updateModuleConfigDefaults.

/**
 * Update the module configuration to have all mandatory configuration flags
 * set to usefull default values
 *
 * @param isNewNode true: an initial configuration is set; false: upgrading
 *          from previous node configuration version, set default to maintain
 *          previous behaviour
 */
@Override
public void updateModuleConfigDefaults(boolean isNewNode) {
    int CURRENTVERSION = 7;
    ModuleConfiguration config = getModuleConfiguration();
    if (isNewNode) {
        // use defaults for new course building blocks
        config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.FALSE.booleanValue());
        config.setBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU, Boolean.TRUE.booleanValue());
        // how to render files (include jquery etc)
        DeliveryOptions nodeDeliveryOptions = DeliveryOptions.defaultWithGlossary();
        nodeDeliveryOptions.setInherit(Boolean.TRUE);
        config.set(CPEditController.CONFIG_DELIVERYOPTIONS, nodeDeliveryOptions);
        config.setConfigurationVersion(CURRENTVERSION);
    } else {
        config.remove(NodeEditController.CONFIG_INTEGRATION);
        if (config.getConfigurationVersion() < 2) {
            // update new configuration options using default values for existing
            // nodes
            config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.TRUE.booleanValue());
            Boolean componentMenu = config.getBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU);
            if (componentMenu == null) {
                config.setBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU, Boolean.TRUE.booleanValue());
            }
            config.setConfigurationVersion(2);
        }
        if (config.getConfigurationVersion() < 3) {
            config.set(NodeEditController.CONFIG_CONTENT_ENCODING, NodeEditController.CONFIG_CONTENT_ENCODING_AUTO);
            config.set(NodeEditController.CONFIG_JS_ENCODING, NodeEditController.CONFIG_JS_ENCODING_AUTO);
            config.setConfigurationVersion(3);
        }
        // save it as version 6
        if (config.getConfigurationVersion() < 7) {
            String contentEncoding = (String) config.get(NodeEditController.CONFIG_CONTENT_ENCODING);
            if (contentEncoding != null && contentEncoding.equals("auto")) {
                // new style for auto
                contentEncoding = null;
            }
            String jsEncoding = (String) config.get(NodeEditController.CONFIG_JS_ENCODING);
            if (jsEncoding != null && jsEncoding.equals("auto")) {
                // new style for auto
                jsEncoding = null;
            }
            CPPackageConfig reConfig = null;
            DeliveryOptions nodeDeliveryOptions = (DeliveryOptions) config.get(CPEditController.CONFIG_DELIVERYOPTIONS);
            if (nodeDeliveryOptions == null) {
                // Update missing delivery options now, inherit from repo by default
                nodeDeliveryOptions = DeliveryOptions.defaultWithGlossary();
                nodeDeliveryOptions.setInherit(Boolean.TRUE);
                RepositoryEntry re = getReferencedRepositoryEntry();
                // Check if delivery options are set for repo entry, if not create default
                if (re != null) {
                    reConfig = CPManager.getInstance().getCPPackageConfig(re.getOlatResource());
                    if (reConfig == null) {
                        reConfig = new CPPackageConfig();
                    }
                    DeliveryOptions repoDeliveryOptions = reConfig.getDeliveryOptions();
                    if (repoDeliveryOptions == null) {
                        // migrate existing config back to repo entry using the default as a base
                        repoDeliveryOptions = DeliveryOptions.defaultWithGlossary();
                        reConfig.setDeliveryOptions(repoDeliveryOptions);
                        repoDeliveryOptions.setContentEncoding(contentEncoding);
                        repoDeliveryOptions.setJavascriptEncoding(jsEncoding);
                        CPManager.getInstance().setCPPackageConfig(re.getOlatResource(), reConfig);
                    } else {
                        // see if we have any different settings than the repo. if so, don't use inherit mode
                        if (contentEncoding != repoDeliveryOptions.getContentEncoding() || jsEncoding != repoDeliveryOptions.getJavascriptEncoding()) {
                            nodeDeliveryOptions.setInherit(Boolean.FALSE);
                            nodeDeliveryOptions.setContentEncoding(contentEncoding);
                            nodeDeliveryOptions.setJavascriptEncoding(jsEncoding);
                        }
                    }
                }
                // remove old config parameters
                config.remove(NodeEditController.CONFIG_CONTENT_ENCODING);
                config.remove(NodeEditController.CONFIG_JS_ENCODING);
                // replace with new delivery options
                config.set(CPEditController.CONFIG_DELIVERYOPTIONS, nodeDeliveryOptions);
            }
            config.setConfigurationVersion(7);
        }
    // else node is up-to-date - nothing to do
    }
    if (config.getConfigurationVersion() != CURRENTVERSION) {
        OLog logger = Tracing.createLoggerFor(CPCourseNode.class);
        logger.error("CP course node version not updated to lastest version::" + CURRENTVERSION + ", was::" + config.getConfigurationVersion() + ". Check the code, programming error.");
    }
}
Also used : OLog(org.olat.core.logging.OLog) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) RepositoryEntry(org.olat.repository.RepositoryEntry) DeliveryOptions(org.olat.core.gui.control.generic.iframe.DeliveryOptions)

Example 8 with OLog

use of org.olat.core.logging.OLog in project openolat by klemens.

the class CourseExtensionHelper method createNode.

/**
 * Creates a course node and appends it to the course. (not persisted yet)
 *
 * @param c course object
 * @param shortTitle short title for node
 * @param longTitle long title for node
 * @return created course node
 */
public static final CourseNode createNode(ICourse course, final String shortTitle, final String longTitle, final String type) {
    // create a node with default data
    CourseNodeConfiguration nodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
    CourseNode node = nodeConfig.getInstance();
    node.setShortTitle(shortTitle);
    node.setLongTitle(longTitle);
    // append node to course
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    final CourseEditorTreeModel cetm = course.getEditorTreeModel();
    final CourseNode rootNode = cetm.getCourseNode(course.getRunStructure().getRootNode().getIdent());
    course.getEditorTreeModel().addCourseNode(node, rootNode);
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    OLog log = Tracing.createLoggerFor(CourseExtensionHelper.class);
    if (log.isDebug())
        log.debug("Created new course node: " + nodeConfig.getAlias());
    return node;
}
Also used : OLog(org.olat.core.logging.OLog) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode)

Example 9 with OLog

use of org.olat.core.logging.OLog in project openolat by klemens.

the class PortletLink method init.

private static void init() {
    OLog logger = Tracing.createLoggerFor(LinksPortlet.class);
    if (logger.isDebug())
        logger.debug("START: Loading remote portlets content.");
    File configurationFile = new File(WebappHelper.getContextRealPath(CONFIG_FILE));
    // fxdiff: have file outside of war/olatapp
    File fxConfFolder = new File(WebappHelper.getUserDataRoot() + "/customizing/linksPortlet");
    if (!fxConfFolder.exists()) {
        fxConfFolder.mkdir();
    }
    File fxConfFile = new File(fxConfFolder + "/olat_portals_links.xml");
    fxConfXStreamFile = new File(fxConfFolder + "/olat_portals_xstream.xml");
    if (!fxConfFile.exists() && !fxConfXStreamFile.exists()) {
        try {
            fxConfFile.createNewFile();
            FileUtils.copyFileToFile(configurationFile, fxConfFile, false);
            logger.info("portal links portlet: copied initial config from " + CONFIG_FILE);
        } catch (IOException e) {
            new AssertException("could not copy an initial portal links config to olatdata", e);
        }
    }
    // this map contains the whole data
    HashMap<String, PortletInstitution> portletMap = new HashMap<String, PortletInstitution>();
    if (!fxConfXStreamFile.exists()) {
        SAXReader reader = new SAXReader();
        try {
            // fxdiff: read from fx-config-file in olatdata
            Document doc = reader.read(fxConfFile);
            Element rootElement = doc.getRootElement();
            List<Element> lstInst = rootElement.elements(ELEM_INSTITUTION);
            for (Element instElem : lstInst) {
                String inst = instElem.attributeValue(ATTR_INSTITUTION_NAME);
                List<Element> lstTmpLinks = instElem.elements(ELEM_LINK);
                List<PortletLink> lstLinks = new ArrayList<PortletLink>(lstTmpLinks.size());
                for (Element linkElem : lstTmpLinks) {
                    String title = linkElem.elementText(ELEM_LINK_TITLE);
                    String url = linkElem.elementText(ELEM_LINK_URL);
                    String target = linkElem.elementText(ELEM_LINK_TARGET);
                    String lang = linkElem.elementText(ELEM_LINK_LANG);
                    String desc = linkElem.elementText(ELEM_LINK_DESC);
                    String identifier = linkElem.elementText(ELEM_LINK_IDENT);
                    lstLinks.add(new PortletLink(title, url, target, lang, desc, identifier));
                }
                portletMap.put(inst, new PortletInstitution(inst, lstLinks));
            }
        } catch (Exception e) {
            logger.error("Error reading configuration file", e);
        } finally {
            content = portletMap;
        }
        // lazy migrate to new format
        saveLinkList(content);
        FileUtils.copyFileToFile(fxConfFile, new File(fxConfFile + ".bak"), true);
    } else {
        XStream xstream = XStreamHelper.createXStreamInstance();
        xstream.alias("LinksPortlet", Map.class);
        xstream.alias(ELEM_LINK, PortletLink.class);
        xstream.alias(ELEM_INSTITUTION, PortletInstitution.class);
        xstream.aliasAttribute(PortletInstitution.class, ATTR_INSTITUTION_NAME, ATTR_INSTITUTION_NAME);
        content = (HashMap<String, PortletInstitution>) XStreamHelper.readObject(xstream, fxConfXStreamFile);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) XStream(com.thoughtworks.xstream.XStream) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.dom4j.Document) AssertException(org.olat.core.logging.AssertException) IOException(java.io.IOException) OLog(org.olat.core.logging.OLog) File(java.io.File)

Example 10 with OLog

use of org.olat.core.logging.OLog in project openolat by klemens.

the class Log4JInitServlet method init.

@Override
public void init() {
    String file = getInitParameter("log4j-init-file");
    ClassPathResource res = new ClassPathResource(file);
    if (!res.exists()) {
        // creating basic log4j configuration which writes to console out, Only called when not yet configured
        ConsoleAppender appender = new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"), ConsoleAppender.SYSTEM_OUT);
        appender.setThreshold(Level.INFO);
        BasicConfigurator.configure(appender);
        OLog log = Tracing.createLoggerFor(getClass());
        log.info("*****************************************************************************************");
        log.info("You don't provide a log4j config file for your OLAT instance. OLAT will just log to standard out (e.g. catalina.out)." + " Please provide a proper log config file (log4j.xml, see olat/conf for an example or read the installation guide) " + "and place it into the root of the classpath e.g. tomcat/lib or WEB-INF/classes");
        log.info("*****************************************************************************************");
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) OLog(org.olat.core.logging.OLog) PatternLayout(org.apache.log4j.PatternLayout) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

OLog (org.olat.core.logging.OLog)10 ModuleConfiguration (org.olat.modules.ModuleConfiguration)4 XStream (com.thoughtworks.xstream.XStream)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ConsoleAppender (org.apache.log4j.ConsoleAppender)2 PatternLayout (org.apache.log4j.PatternLayout)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 SAXReader (org.dom4j.io.SAXReader)2 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)2 AssertException (org.olat.core.logging.AssertException)2 CourseNode (org.olat.course.nodes.CourseNode)2 CourseNodeConfiguration (org.olat.course.nodes.CourseNodeConfiguration)2 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)2 CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2