@Override public void updateModuleConfigDefaults(final boolean isNewNode) { final ModuleConfiguration config = getModuleConfiguration(); if (isNewNode) { // use defaults for new course building blocks config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, false); config.setConfigurationVersion(1); } }
private void create(MultipleSelectionElement selection, ICourse course, CourseNode parentNode) { SelectNodeObject node = (SelectNodeObject) selection.getUserObject(); if (selection.isMultiselect() && selection.isSelected(0)) { VFSItem item = node.getItem(); CourseNode newNode = null; if (item instanceof VFSLeaf) { // create node newNode = createCourseNode(item, "sp"); ModuleConfiguration moduleConfig = newNode.getModuleConfiguration(); String path = getRelativePath(item); moduleConfig.set(SPEditController.CONFIG_KEY_FILE, path); moduleConfig.setBooleanEntry(SPEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS, true); } else if (item instanceof VFSContainer) { // add structure newNode = createCourseNode(item, "st"); } int pos = -1; if (position >= 0 && selectedNode.getCourseNode().getIdent().equals(parentNode.getIdent())) { pos = position++; } if (pos < 0 || pos >= parentNode.getChildCount()) { course.getEditorTreeModel().addCourseNode(newNode, parentNode); } else { course.getEditorTreeModel().insertCourseNodeAt(newNode, parentNode, pos); } if (item instanceof VFSContainer) { parentNode = newNode; } } // recurse for (MultipleSelectionElement childElement : node.getChildren()) { create(childElement, course, parentNode); } }
/** * 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); } // Version 5 was ineffective since the delivery options were not set. We have to redo this and // save it as version 6 if (config.getConfigurationVersion() < 7) { String contentEncoding = (String) config.get(NodeEditController.CONFIG_CONTENT_ENCODING); if (contentEncoding != null && contentEncoding.equals("auto")) { contentEncoding = null; // new style for auto } String jsEncoding = (String) config.get(NodeEditController.CONFIG_JS_ENCODING); if (jsEncoding != null && jsEncoding.equals("auto")) { jsEncoding = null; // new style for auto } 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."); } }