List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.craftercms.cstudio.publishing.processor.SearchUpdateFlattenXmlProcessor.java
License:Open Source License
private Document flattenXml(String root, File file, Set<String> flattenedFiles) throws IOException, DocumentException, URISyntaxException { SAXReader reader = new SAXReader(); SAXReader includeReader = new SAXReader(); try {//from www . j av a 2 s . c o m reader.setEncoding(charEncoding); Document document = reader.read(file); List<Element> includeElements = document.selectNodes(includeElementXPathQuery); if (CollectionUtils.isEmpty(includeElements)) { return document; } for (Element includeElement : includeElements) { String includeSrcPath = root + File.separatorChar + includeElement.getTextTrim(); if (StringUtils.isEmpty(includeSrcPath)) { continue; } File includeFile = new File(includeSrcPath); if (includeFile != null && includeFile.exists()) { flattenedFiles.add(includeSrcPath); Document includeDocument = flattenXml(root, includeFile, flattenedFiles); if (logger.isDebugEnabled()) { logger.debug("Include found in " + file.getAbsolutePath() + ": " + includeSrcPath); } doInclude(includeElement, includeSrcPath, includeDocument); } } return document; } finally { reader.resetHandlers(); reader = null; includeReader.resetHandlers(); includeReader = null; } }
From source file:org.craftercms.engine.freemarker.RenderComponentDirective.java
License:Open Source License
protected SiteItem getComponentFromNode(TemplateModel componentParam, Environment env) throws TemplateException { Element includeElementParent = unwrap(COMPONENT_PARAM_NAME, componentParam, Element.class, env); Element includeElement = includeElementParent.element(includeElementName); String componentPath = includeElement.getTextTrim(); return getComponent(componentPath, env); }
From source file:org.craftercms.studio.impl.v1.service.configuration.SiteEnvironmentConfigImpl.java
License:Open Source License
protected EnvironmentConfigTO loadConfiguration(String key) { String configLocation = getConfigPath().replaceFirst(StudioConstants.PATTERN_SITE, key) .replaceFirst(StudioConstants.PATTERN_ENVIRONMENT, getEnvironment()); configLocation = configLocation + "/" + getConfigFileName(); EnvironmentConfigTO config = null;//from www. ja v a 2s . c o m Document document = null; try { document = contentService.getContentAsDocument(key, configLocation); } catch (DocumentException e) { e.printStackTrace(); } if (document != null) { Element root = document.getRootElement(); config = new EnvironmentConfigTO(); String previewServerUrl = root.valueOf("preview-server-url"); config.setPreviewServerUrl(previewServerUrl); String openDropdown = root.valueOf("open-site-dropdown"); config.setOpenDropdown((openDropdown != null) ? Boolean.valueOf(openDropdown) : false); String previewServerUrlPattern = root.valueOf("preview-server-url-pattern"); config.setPreviewServerUrlPattern(previewServerUrlPattern); String orbeonServerUrlPattern = root.valueOf("form-server-url"); config.setFormServerUrlPattern(orbeonServerUrlPattern); String authoringServerUrl = root.valueOf("authoring-server-url"); config.setAuthoringServerUrl(authoringServerUrl); String authoringServerUrlPattern = root.valueOf("authoring-server-url-pattern"); config.setAuthoringServerUrlPattern(authoringServerUrlPattern); String liveServerUrl = root.valueOf("live-server-url"); config.setLiveServerUrl(liveServerUrl); String adminEmailAddress = root.valueOf("admin-email-address"); config.setAdminEmailAddress(adminEmailAddress); String cookieDomain = root.valueOf("cookie-domain"); config.setCookieDomain(cookieDomain); List<Element> channelGroupList = root.selectNodes("publishing-channels/channel-group"); for (Element element : channelGroupList) { PublishingChannelGroupConfigTO pcgConfigTo = new PublishingChannelGroupConfigTO(); Node node = element.selectSingleNode("label"); if (node != null) pcgConfigTo.setName(node.getText()); List<Element> channels = element.selectNodes("channels/channel"); for (Element channel : channels) { PublishingChannelConfigTO pcConfigTO = new PublishingChannelConfigTO(); pcConfigTO.setName(channel.getText()); if (!checkEndpointConfigured(key, pcConfigTO.getName())) { logger.error("Deployment endpoint \"" + pcConfigTO.getName() + "\" is not configured for site " + key); } pcgConfigTo.getChannels().add(pcConfigTO); } node = element.selectSingleNode("live-environment"); if (node != null) { String isLiveEnvStr = node.getText(); boolean isLiveEnvVal = (StringUtils.isNotEmpty(isLiveEnvStr)) && Boolean.valueOf(isLiveEnvStr); pcgConfigTo.setLiveEnvironment(isLiveEnvVal); if (isLiveEnvVal) { if (config.getLiveEnvironmentPublishingGroup() == null) { config.setLiveEnvironmentPublishingGroup(pcgConfigTo); } else { pcgConfigTo.setLiveEnvironment(false); logger.warn( "Multiple publishing groups assigned as live environment. Only one publishing group can be live environment. " + config.getLiveEnvironmentPublishingGroup().getName() + " is already set as live environment."); } } } node = element.selectSingleNode("order"); if (node != null) { String orderStr = node.getText(); if (StringUtils.isNotEmpty(orderStr)) { try { int orderVal = Integer.parseInt(orderStr); pcgConfigTo.setOrder(orderVal); } catch (NumberFormatException exc) { logger.info( String.format("Order not defined for publishing group (%s) config [path: %s]", pcgConfigTo.getName(), configLocation)); logger.info( String.format("Default order value (%d) will be used for publishing group [%s]", pcgConfigTo.getOrder(), pcgConfigTo.getName())); } } } List<Element> roles = element.selectNodes("roles/role"); Set<String> rolesStr = new HashSet<String>(); for (Element role : roles) { rolesStr.add(role.getTextTrim()); } pcgConfigTo.setRoles(rolesStr); config.getPublishingChannelGroupConfigs().put(pcgConfigTo.getName(), pcgConfigTo); } String previewDeploymentEndpoint = root.valueOf("preview-deployment-endpoint"); config.setPreviewDeploymentEndpoint(previewDeploymentEndpoint); config.setLastUpdated(new Date()); } return config; }
From source file:org.craftercms.studio.impl.v1.service.security.DemoSecurityProvider.java
License:Open Source License
protected void loadConfiguration() { Document document = null;// w w w.j a v a 2 s.c o m userMap = new HashMap<String, User>(); try { File file = new File(getConfigLocation()); SAXReader reader = new SAXReader(); document = reader.read(file); } catch (DocumentException e) { e.printStackTrace(); } if (document != null) { Element root = document.getRootElement(); List<Element> users = root.selectNodes(DOCUMENT_USER_ROOT); for (Element userElm : users) { User user = new User(); String username = userElm.valueOf(DOCUMENT_ELM_USERNAME); user.setUsername(username); String password = userElm.valueOf(DOCUMENT_ELM_PASSWORD); user.setPassword(password); String email = userElm.valueOf(DOCUMENT_ELM_EMAIL); user.setEmail(email); String firstName = userElm.valueOf(DOCUMENT_ELM_FIRSTNAME); user.setFirstName(firstName); String lastName = userElm.valueOf(DOCUMENT_ELM_LASTNAME); user.setLastName(lastName); List<Element> groupElms = userElm.selectNodes(DOCUMENT_ELM_GROUPS + "/" + DOCUMENT_ELM_GROUP); List<String> groupStrs = new ArrayList<>(); for (Element groupElem : groupElms) { groupStrs.add(groupElem.getTextTrim()); } user.setGroups(groupStrs); userMap.put(user.getUsername(), user); } configLastUpdate = new Date(); } }
From source file:org.etudes.component.app.melete.MeleteImportServiceImpl.java
License:Apache License
private void buildModuleTitle(Element titleEle, Module module) { boolean moduleTitleFlag = false; if (titleEle != null) { String title = titleEle.getTextTrim(); if (title != null && title.length() != 0) { module.setTitle(title);/*from w w w . j a v a2 s . com*/ moduleTitleFlag = true; } } if (!moduleTitleFlag) module.setTitle("Untitled Module"); return; }
From source file:org.etudes.component.app.melete.MeleteImportServiceImpl.java
License:Apache License
/** * Builds the module for each Item element under organization * * @param eleItem item element//from ww w. j av a 2 s. co m * @exception throws exception * revised by rashmi - change the whole structure of accessing elements */ private void buildModule(Element eleItem, Document document, String unZippedDirPath, String courseId) throws Exception { if (logger.isDebugEnabled()) logger.debug("Entering buildModule..."); // create module object Module module = new Module(); boolean moduleTitleFlag = false; if (eleItem.attribute("isvisible") != null) { if (((Attribute) eleItem.attribute("isvisible")).getValue().equals("false")) { CourseModule cmod = new CourseModule(courseId, -1, true, null, false, module); module.setCoursemodule(cmod); } } if (eleItem.elements("title") != null && eleItem.elements("title").size() != 0) { Element titleEle = (Element) eleItem.elements("title").get(0); if (titleEle != null) { String title = titleEle.getTextTrim(); if (title != null && title.length() != 0) { module.setTitle(title); moduleTitleFlag = true; } } } if (!moduleTitleFlag) module.setTitle("Untitled Module"); boolean keywords = false; boolean descr = false; if (eleItem.selectNodes("./imsmd:lom/imsmd:general") != null && eleItem.selectNodes("./imsmd:lom/imsmd:general").size() != 0) { Element generalElement = (Element) eleItem.selectNodes("./imsmd:lom/imsmd:general").get(0); List moduleMetadataList = generalElement.elements(); for (Iterator iter = moduleMetadataList.iterator(); iter.hasNext();) { Element metaElement = (Element) iter.next(); if (metaElement.getName().equals("description")) { String desc = metaElement.selectSingleNode(".//imsmd:langstring").getText(); module.setDescription(desc.trim()); descr = true; } if (metaElement.getName().equals("keyword")) { String modkeyword = metaElement.selectSingleNode(".//imsmd:langstring").getText(); if (modkeyword != null) { module.setKeywords(modkeyword.trim()); keywords = true; } } } } if (!keywords) module.setKeywords(module.getTitle()); if (!descr) module.setDescription(" "); createModule(module, courseId); // build sections try { sectionUtil = new SubSectionUtilImpl(); Document seqDocument = sectionUtil.createSubSection4jDOM(); for (Iterator iter = eleItem.elementIterator("item"); iter.hasNext();) { Element element = (Element) iter.next(); if (element.attributeValue("identifier").startsWith("NEXTSTEPS")) buildWhatsNext(element, document, module, unZippedDirPath); else buildSection(element, document, module, addBlankSection(null, seqDocument), unZippedDirPath, seqDocument, courseId); } // update module seqXml // logger.debug("checking seqXML now at the end of buildModule process" + seqDocument.asXML()); module.setSeqXml(seqDocument.asXML()); moduleDB.updateModule(module); } catch (Exception e) { // e.printStackTrace(); throw e; } if (logger.isDebugEnabled()) logger.debug("Exiting buildModule..."); }
From source file:org.etudes.component.app.melete.MeleteImportServiceImpl.java
License:Apache License
/** * Builds section for each item under module item * @param eleItem item element//from w w w .j a v a2 s. c om * @param document document * @param module Module * @throws Exception */ private void buildSection(Element eleItem, Document document, Module module, Element seqElement, String unZippedDirPath, Document seqDocument, String courseId) throws Exception { if (logger.isDebugEnabled()) logger.debug("Entering buildSection..."); Attribute identifier = eleItem.attribute("identifier"); // logger.debug("importing ITEM " + identifier.getValue()); Attribute identifierref = eleItem.attribute("identifierref"); Element eleRes; Section section = new Section(); MeleteResource meleteResource = new MeleteResource(); boolean sectionTitleFlag = false; boolean sectionCopyrightFlag = false; List elements = eleItem.elements(); for (Iterator iter = elements.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); //title if (element.getQualifiedName().equalsIgnoreCase("title")) { section.setTitle(element.getTextTrim()); sectionTitleFlag = true; } //item else if (element.getQualifiedName().equalsIgnoreCase("item")) { //call recursive here buildSection(element, document, module, addBlankSection(seqElement, seqDocument), unZippedDirPath, seqDocument, courseId); } //metadata else if (element.getQualifiedName().equalsIgnoreCase("imsmd:lom")) { // section instructions Element DescElement = null; if (eleItem.selectNodes("./imsmd:lom/imsmd:general/imsmd:description") != null && (eleItem.selectNodes("./imsmd:lom/imsmd:general/imsmd:description").size() != 0)) DescElement = (Element) eleItem.selectNodes("./imsmd:lom/imsmd:general/imsmd:description") .get(0); if (DescElement != null) { String instr = DescElement.selectSingleNode(".//imsmd:langstring").getText(); section.setInstr(instr.trim()); } // read license information Element rightsElement = null; if (eleItem.selectNodes("./imsmd:lom/imsmd:rights") != null && (eleItem.selectNodes("./imsmd:lom/imsmd:rights").size() != 0)) rightsElement = (Element) eleItem.selectNodes("./imsmd:lom/imsmd:rights").get(0); if (rightsElement != null) { Element licenseElement = rightsElement.element("description"); String licenseUrl = licenseElement.selectSingleNode(".//imsmd:langstring").getText(); if (licenseUrl != null) buildLicenseInformation(meleteResource, licenseUrl); sectionCopyrightFlag = true; } } // license end } // other attributes // logger.debug("setting section attribs"); String userId = UserDirectoryService.getCurrentUser().getEid(); String firstName = UserDirectoryService.getCurrentUser().getFirstName(); String lastName = UserDirectoryService.getCurrentUser().getLastName(); section.setTextualContent(true); section.setCreatedByFname(firstName); section.setCreatedByLname(lastName); section.setContentType("notype"); if (!sectionTitleFlag) section.setTitle("Untitled Section"); //default to no license if (!sectionCopyrightFlag) { meleteResource.setLicenseCode(RESOURCE_LICENSE_CODE); meleteResource.setCcLicenseUrl(RESOURCE_LICENSE_URL); } // save section object Integer new_section_id = sectionDB.addSection(module, section, true); section.setSectionId(new_section_id); seqElement.addAttribute("id", new_section_id.toString()); // now melete resource object if (identifierref != null) { eleRes = getResource(identifierref.getValue(), document); if (eleRes != null) { Attribute resHrefAttr = eleRes.attribute("href"); if (resHrefAttr != null) { String hrefVal = resHrefAttr.getValue(); // logger.debug("hrefVal:" + hrefVal); // check if file is missing if (hrefVal != null && hrefVal.length() != 0 && !(hrefVal.startsWith("http://") || hrefVal.startsWith("https://") || hrefVal.startsWith("mailto:"))) { hrefVal = getFileNamefromElement(eleRes.elements(), hrefVal); if (!meleteUtil.checkFileExists(unZippedDirPath + File.separator + hrefVal)) { logger.info("content file for section is missing so move ON"); return; } } // end missing file check // create meleteResourceObject List resElements = eleRes.elements(); createContentResource(module, section, meleteResource, hrefVal, resElements, unZippedDirPath, courseId); } // resHrefAttr check end } } if (logger.isDebugEnabled()) logger.debug("Exiting buildSection..."); }
From source file:org.etudes.component.app.melete.MeleteImportServiceImpl.java
License:Apache License
/** * Builds section for each item under module item * @param eleItem item element// w w w . j av a 2 s . com * @param document document * @param module Module * @throws Exception */ private void mergeSection(Element eleItem, Document document, Module module, Element seqElement, String unZippedDirPath, Document seqDocument, String courseId) throws Exception { if (logger.isDebugEnabled()) logger.debug("Entering mergeSection..."); Attribute identifier = eleItem.attribute("identifier"); // // logger.debug("importing ITEM " + identifier.getValue()); Attribute identifierref = eleItem.attribute("identifierref"); Element eleRes; Section section = new Section(); MeleteResource meleteResource = new MeleteResource(); boolean sectionTitleFlag = false; boolean sectionCopyrightFlag = false; List elements = eleItem.elements(); for (Iterator iter = elements.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); // title if (element.getQualifiedName().equalsIgnoreCase("title")) { section.setTitle(element.getTextTrim()); sectionTitleFlag = true; } // item else if (element.getQualifiedName().equalsIgnoreCase("item")) { // call recursive here buildSection(element, document, module, addBlankSection(seqElement, seqDocument), unZippedDirPath, seqDocument, courseId); } // metadata else if (element.getName().equalsIgnoreCase("imsmd:lom")) { // section instructions List<Element> modulegeneralList = element.elements(); List moduleMetadataList = modulegeneralList.get(0).elements(); for (Iterator iter2 = moduleMetadataList.iterator(); iter2.hasNext();) { Element metaElement = (Element) iter2.next(); if (metaElement.getName().equals("imsmd:description") && metaElement.element("imsmd:langstring") != null) { String instr = metaElement.element("imsmd:langstring").getText(); section.setInstr(instr.trim()); } } // read license information if (modulegeneralList.size() > 1) { List rightList = modulegeneralList.get(1).elements(); for (Iterator iter3 = rightList.iterator(); iter3.hasNext();) { Element rightsElement = (Element) iter3.next(); if (rightsElement.getName().equals("imsmd:description") && rightsElement.element("imsmd:langstring") != null) { String licenseUrl = rightsElement.element("imsmd:langstring").getText(); if (licenseUrl != null) { buildLicenseInformation(meleteResource, licenseUrl); sectionCopyrightFlag = true; } } } } } // license end } // other attributes // logger.debug("setting section attribs"); String userId = UserDirectoryService.getCurrentUser().getEid(); String firstName = UserDirectoryService.getCurrentUser().getFirstName(); String lastName = UserDirectoryService.getCurrentUser().getLastName(); section.setTextualContent(true); section.setCreatedByFname(firstName); section.setCreatedByLname(lastName); section.setContentType("notype"); if (!sectionTitleFlag) section.setTitle("Untitled Section"); // default to no license if (!sectionCopyrightFlag) { meleteResource.setLicenseCode(RESOURCE_LICENSE_CODE); meleteResource.setCcLicenseUrl(RESOURCE_LICENSE_URL); } // save section object Integer new_section_id = sectionDB.addSection(module, section, true); section.setSectionId(new_section_id); seqElement.addAttribute("id", new_section_id.toString()); // now melete resource object if (identifierref != null) { eleRes = getMergeResource(identifierref.getValue(), document); if (eleRes != null) { Attribute resHrefAttr = eleRes.attribute("href"); if (resHrefAttr != null) { String hrefVal = resHrefAttr.getValue(); // check if file is missing if (hrefVal != null && hrefVal.length() != 0 && !(hrefVal.startsWith("http://") || hrefVal.startsWith("https://") || hrefVal.startsWith("mailto:"))) { if (!meleteUtil.checkFileExists(unZippedDirPath + File.separator + hrefVal)) { logger.info("content file for section is missing so move ON"); return; } } // end missing file check // create meleteResourceObject List resElements = eleRes.elements(); createContentResource(module, section, meleteResource, hrefVal, resElements, unZippedDirPath, courseId); } // resHrefAttr check end } } if (logger.isDebugEnabled()) logger.debug("Exiting mergeSection..."); }
From source file:org.etudes.jforum.view.admin.ImportExportAction.java
License:Apache License
/** * creates forum for a category/*w w w . ja v a 2 s.co m*/ * * @param forumEle */ /*private Forum createForum(Element forumEle, Category category) throws Exception { if (logger.isDebugEnabled()) logger.debug("Entering createForum......"); List eleForumTitles = (List) forumEle.elements("title"); if (eleForumTitles == null || eleForumTitles.size() == 0) return null; // create the forum Element titleEle = (Element) forumEle.elements("title").get(0); int forumType = 0, forumAccessType = 0, forumGradeType = 0; float gradePoints = 0f; Date startDate = null, endDate = null; int lockEndDate = 0; int addToGradebook = 0; int minPosts = 0, minPostsRequired = 0; String parameters = forumEle.attributeValue("parameters"); if (parameters != null && parameters.trim().length() > 0) { String param[] = parameters.split("&"); for (int i = 0; i < param.length; i++) { if (param[i].startsWith("forumtype")) { try { if (param[i].indexOf('=') != -1) forumType = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("accesstype")) { try { if (param[i].indexOf('=') != -1) forumAccessType = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("gradetype")) { try { if (param[i].indexOf('=') != -1) forumGradeType = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("gradepoints")) { try { if (param[i].indexOf('=') != -1) gradePoints = Float.parseFloat(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("startdate")) { try { if (param[i].indexOf('=') != -1) { try { startDate = getDateFromString(param[i].substring(param[i].indexOf('=') + 1)); } catch (ParseException e) { } } } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("enddate")) { try { if (param[i].indexOf('=') != -1) { try { endDate = getDateFromString(param[i].substring(param[i].indexOf('=') + 1)); } catch (ParseException e) { } } } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("lockenddate")) { try { if (param[i].indexOf('=') != -1) lockEndDate = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("addtogradebook")) { try { if (param[i].indexOf('=') != -1) addToGradebook = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("minpostsrequired")) { try { if (param[i].indexOf('=') != -1) minPostsRequired = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("minposts")) { try { if (param[i].indexOf('=') != -1) minPosts = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } } } // forum types are 0,1,2 and access types are 0,1,2 if (forumType > 2) forumType = Forum.TYPE_NORMAL; if (forumAccessType > 2) forumAccessType = Forum.ACCESS_SITE; Forum f = new Forum(); if ((category.getStartDate()) == null && (category.getEndDate() == null)) { f.setStartDate(startDate); f.setEndDate(endDate); if (endDate != null) { f.setLockForum((lockEndDate == 1) ? true : false); } } else { f.setStartDate(null); f.setEndDate(null); } f.setIdCategories(category.getId()); f.setName(titleEle.getTextTrim()); f.setModerated(false); f.setType(forumType); f.setAccessType(forumAccessType); if (forumGradeType == Forum.GRADE_BY_FORUM || forumGradeType == Forum.GRADE_BY_TOPIC) f.setGradeType(forumGradeType); else f.setGradeType(Forum.GRADE_DISABLED); // description List genElements = forumEle.selectNodes("./imsmd:lom/imsmd:general"); if (genElements != null && genElements.size() > 0) { Element generalElement = (Element) genElements.get(0); Element descElement = generalElement.element("description"); String description = descElement.selectSingleNode(".//imsmd:langstring").getText(); if (description != null) f.setDescription(description.trim()); } int forumId = DataAccessDriver.getInstance().newForumDAO().addNew(f); f.setId(forumId); ForumRepository.addForum(f); // create grade if forum is grade by forum if (f.getGradeType() == Forum.GRADE_BY_FORUM) { Grade grade = new Grade(); grade.setContext(ToolManager.getCurrentPlacement().getContext()); grade.setForumId(forumId); try { grade.setPoints(gradePoints); } catch (NumberFormatException ne) { grade.setPoints(0f); } grade.setType(Forum.GRADE_BY_FORUM); Site site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext()); if (site.getToolForCommonId(SakaiSystemGlobals.getValue(ConfigKeys.GRADEBOOK_TOOL_ID)) != null) { grade.setAddToGradeBook((addToGradebook == 1) ? true : false); } else { grade.setAddToGradeBook(false); } if (minPostsRequired == 1) { grade.setMinimumPostsRequired(true); grade.setMinimumPosts(minPosts); } int gradeId = DataAccessDriver.getInstance().newGradeDAO().addNew(grade); grade.setId(gradeId); // add to gradebook if (grade.isAddToGradeBook()) { String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext(); JForumGBService jForumGBService = null; jForumGBService = (JForumGBService)ComponentManager.get("org.etudes.api.app.jforum.JForumGBService"); if (!jForumGBService.isAssignmentDefined(gradebookUid, f.getName())) { String url = null; Date gbItemEndDate = null; if ((f.getStartDate() != null) || (f.getEndDate() != null)) { gbItemEndDate = f.getEndDate(); } else if ((category.getStartDate() != null) || (category.getEndDate() != null)) { gbItemEndDate = category.getEndDate(); } jForumGBService.addExternalAssessment(gradebookUid, "discussions-" + String.valueOf(grade.getId()), url, f.getName(), grade.getPoints(), gbItemEndDate, I18n.getMessage("Grade.sendToGradebook.description")); } } }*/ private org.etudes.api.app.jforum.Forum createForum(Element forumEle, org.etudes.api.app.jforum.Category category) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Entering createForum......"); } List eleForumTitles = (List) forumEle.elements("title"); if (eleForumTitles == null || eleForumTitles.size() == 0) { return null; } // create the forum Element titleEle = (Element) forumEle.elements("title").get(0); int forumType = 0, forumAccessType = 0, forumGradeType = 0; float gradePoints = 0f; Date startDate = null, endDate = null, allowUntilDate = null; ; //int lockEndDate = 0; int hideUntilOpen = 0; int addToGradebook = 0; int minPosts = 0, minPostsRequired = 0; String parameters = forumEle.attributeValue("parameters"); if (parameters != null && parameters.trim().length() > 0) { String param[] = parameters.split("&"); for (int i = 0; i < param.length; i++) { if (param[i].startsWith("forumtype")) { try { if (param[i].indexOf('=') != -1) forumType = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("accesstype")) { try { if (param[i].indexOf('=') != -1) forumAccessType = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("gradetype")) { try { if (param[i].indexOf('=') != -1) forumGradeType = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("gradepoints")) { try { if (param[i].indexOf('=') != -1) gradePoints = Float.parseFloat(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("startdate")) { try { if (param[i].indexOf('=') != -1) { try { startDate = getDateFromString(param[i].substring(param[i].indexOf('=') + 1)); } catch (ParseException e) { } } } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("hideuntilopen")) { try { if (param[i].indexOf('=') != -1) hideUntilOpen = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("enddate")) { try { if (param[i].indexOf('=') != -1) { try { endDate = getDateFromString(param[i].substring(param[i].indexOf('=') + 1)); } catch (ParseException e) { } } } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } /*else if (param[i].startsWith("lockenddate")) { try { if (param[i].indexOf('=') != -1) lockEndDate = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } }*/ else if (param[i].startsWith("allowuntildate")) { try { if (param[i].indexOf('=') != -1) { try { allowUntilDate = getDateFromString(param[i].substring(param[i].indexOf('=') + 1)); } catch (ParseException e) { } } } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("addtogradebook")) { try { if (param[i].indexOf('=') != -1) addToGradebook = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("minpostsrequired")) { try { if (param[i].indexOf('=') != -1) minPostsRequired = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) logger.error(e); } } else if (param[i].startsWith("minposts")) { try { if (param[i].indexOf('=') != -1) minPosts = Integer.parseInt(param[i].substring(param[i].indexOf('=') + 1)); } catch (NumberFormatException e) { if (logger.isErrorEnabled()) { logger.error(e.toString(), e); } } } } } // forum types are 0,1,2 and access types are 0,1,2 if (forumType > 2) { forumType = Forum.TYPE_NORMAL; } if (forumAccessType > 2) { forumAccessType = Forum.ACCESS_SITE; } JForumForumService jforumForumService = (JForumForumService) ComponentManager .get("org.etudes.api.app.jforum.JForumForumService"); org.etudes.api.app.jforum.Forum forum = jforumForumService.newForum(); if ((category.getAccessDates().getOpenDate()) == null && (category.getAccessDates().getDueDate() == null) && (category.getAccessDates().getAllowUntilDate() == null)) { forum.getAccessDates().setOpenDate(startDate); if (startDate != null) { forum.getAccessDates().setHideUntilOpen((hideUntilOpen == 1) ? true : false); } forum.getAccessDates().setDueDate(endDate); forum.getAccessDates().setAllowUntilDate(allowUntilDate); /*if (endDate != null) { forum.getAccessDates().setLocked((lockEndDate == 1) ? true : false); }*/ } else { forum.getAccessDates().setOpenDate(null); forum.getAccessDates().setDueDate(null); } forum.setCategoryId(category.getId()); forum.setName(titleEle.getTextTrim()); //f.setModerated(false); forum.setType(forumType); forum.setAccessType(forumAccessType); forum.setCreatedBySakaiUserId(UserDirectoryService.getCurrentUser().getId()); if (forumGradeType == Forum.GRADE_BY_FORUM || forumGradeType == Forum.GRADE_BY_TOPIC) { forum.setGradeType(forumGradeType); } else { forum.setGradeType(Forum.GRADE_DISABLED); } // description List genElements = forumEle.selectNodes("./imsmd:lom/imsmd:general"); if (genElements != null && genElements.size() > 0) { Element generalElement = (Element) genElements.get(0); Element descElement = generalElement.element("description"); String description = descElement.selectSingleNode(".//imsmd:langstring").getText(); if (description != null) { forum.setDescription(description.trim()); } } // create grade if forum is grade by forum if (forum.getGradeType() == org.etudes.api.app.jforum.Grade.GradeType.FORUM.getType()) { // grade org.etudes.api.app.jforum.Grade grade = forum.getGrade(); grade.setContext(ToolManager.getCurrentPlacement().getContext()); try { grade.setPoints(gradePoints); } catch (NumberFormatException ne) { grade.setPoints(0f); } grade.setType(Forum.GRADE_BY_FORUM); Site site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext()); if (site.getToolForCommonId(SakaiSystemGlobals.getValue(ConfigKeys.GRADEBOOK_TOOL_ID)) != null) { grade.setAddToGradeBook((addToGradebook == 1) ? true : false); } else { grade.setAddToGradeBook(false); } if (minPostsRequired == 1) { grade.setMinimumPostsRequired(true); grade.setMinimumPosts(minPosts); } } try { jforumForumService.createForum(forum); } catch (JForumAccessException e) { // already verified access } if (logger.isDebugEnabled()) { logger.debug("Exiting createForum......"); } return forum; }
From source file:org.geolatte.featureserver.config.FeatureServerConfiguration.java
License:Open Source License
/** * Reparses the configurationfile/* ww w . j a va 2 s. c om*/ * * @throws ConfigurationException if something went wrong parsing the file */ protected void reparse() throws ConfigurationException { error = true; setProperties(); includeRules = new ArrayList<String>(); excludeRules = new ArrayList<String>(); try { SAXReader reader = new SAXReader(); Document document = reader.read(propertyFileName); if (document == null) { throw new ConfigurationException( String.format("No such properties file found: %s", propertyFileName)); } List includes = document.selectNodes("//FeatureServerConfig/Mapping/Tables/Include/Item"); List excludes = document.selectNodes("//FeatureServerConfig/Mapping/Tables/Exclude/Item"); for (int i = 0; i < includes.size(); i++) { Element el = (Element) includes.get(i); includeRules.add(el.getTextTrim()); LOGGER.info(String.format("Include rule added: \"%s\"", el.getTextTrim())); } for (int i = 0; i < excludes.size(); i++) { Element el = (Element) includes.get(i); excludeRules.add(el.getTextTrim()); LOGGER.info(String.format("Exclude rule added: %s", el.getTextTrim())); } List hibernateConfigProps = document .selectNodes("//FeatureServerConfig/HibernateConfiguration/property"); hibernateProperties.clear(); for (int i = 0; i < hibernateConfigProps.size(); i++) { Element el = (Element) hibernateConfigProps.get(i); String propertyName = el.attributeValue("name"); if (!propertyName.startsWith("hibernate")) { propertyName = "hibernate." + propertyName; } String propertyValue = el.getTextTrim(); hibernateProperties.put(propertyName, propertyValue); } Node schema = document.selectSingleNode("//FeatureServerConfig/Mapping/Tables/Schema"); if (schema != null) { dbaseSchema = schema.getText(); LOGGER.info(String.format("Schema is: %s", dbaseSchema)); } else { dbaseSchema = null; LOGGER.info(String.format("No schema specified.")); } errorMessage = null; error = false; } catch (DocumentException e) { LOGGER.error("Error reading configuration file: ", e); errorMessage = e.getMessage(); throw new ConfigurationException("Error parsing the configurationfile: " + e.getMessage(), e); } }