use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class WikiManager method saveWikiPage.
/**
* persists a wiki page on the filesystem. It moves the recent page and the
* metadata to the versions folder with the version on the tail and saves new
* page with metadata to the wiki folder. Does not need to be synchronized as
* editing is locked on page level by the
*
* @see WikiMainController
* @param ores
* @param page
*/
public void saveWikiPage(OLATResourceable ores, WikiPage page, boolean incrementVersion, Wiki wiki) {
// cluster_OK by guido
VFSContainer versionsContainer = getWikiContainer(ores, VERSION_FOLDER_NAME);
VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
// rename existing content file to version x and copy it to the version
// container
VFSItem item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
if (item != null && incrementVersion) {
if (page.getVersion() > 0) {
versionsContainer.copyFrom(item);
VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
String fileName = page.getPageId() + "." + WIKI_FILE_SUFFIX + "-" + page.getVersion();
copiedItem.rename(fileName);
}
item.delete();
}
// rename existing meta file to version x and copy it to the version
// container
item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
if (item != null && incrementVersion) {
// TODO renaming and coping does not work. Bug?? felix fragen
if (page.getVersion() > 0) {
versionsContainer.copyFrom(item);
VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
String fileName = page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX + "-" + page.getVersion();
copiedItem.rename(fileName);
}
item.delete();
}
// store recent content file
VFSLeaf leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_FILE_SUFFIX);
if (leaf == null)
throw new AssertException("Tried to save wiki page with id (" + page.getPageId() + ") and Olatresource: " + ores.getResourceableId() + " but page already existed!");
FileUtils.save(leaf.getOutputStream(false), page.getContent(), "utf-8");
// store recent properties file
leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
if (leaf == null)
throw new AssertException("could not create file for wiki page " + page.getPageId() + ", ores: " + ores.getResourceableTypeName() + ":" + ores.getResourceableId() + ", wikicontainer:" + wikiContentContainer);
if (incrementVersion)
page.incrementVersion();
// update modification time
if (!page.getContent().equals(""))
page.setModificationTime(System.currentTimeMillis());
Properties p = getPageProperties(page);
try {
OutputStream os = leaf.getOutputStream(false);
p.store(os, "wiki page meta properties");
os.close();
// if (incrementVersion) page.incrementVersion();
} catch (IOException e) {
throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
}
// reset view count of the page
page.setViewCount(0);
// update cache to inform all nodes about the change
if (wikiCache != null) {
wikiCache.update(OresHelper.createStringRepresenting(ores), wiki);
}
if (ThreadLocalUserActivityLogger.getLoggedIdentity() != null) {
// do logging only for real user
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_UPDATE, getClass());
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class WikiToCPExport method wikiPageToHtml.
protected String wikiPageToHtml(WikiPage page) {
StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append("<head>\n");
sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
sb.append("<style type=\"text/css\">img {float:right;padding:10px;}</style>\n");
// sb.append("<script type=\"text/javascript\" src=\"cp_offline_menu_mat/jsMath/easy/load.js\"></script>\n");
sb.append("<script type=\"text/javascript\" src=\"cp_offline_menu_mat/wiki.js\"></script>\n");
sb.append("<script type=\"text/javascript\" src=\"mapping.js\"></script>\n");
sb.append("<link rel=\"StyleSheet\" href=\"cp_offline_menu_mat/wiki.css\" type=\"text/css\" media=\"screen, print\">\n");
sb.append("</head>\n");
sb.append("<body>\n");
sb.append("<h3>").append(getTranslatedWikiPageName(page)).append("</h3>");
sb.append("<hr><div id=\"olat-wiki\">");
try {
ParserDocument doc = parser.parseHTML(page.getContent());
sb.append(doc.getContent());
} catch (Exception e) {
throw new OLATRuntimeException("error while parsing from wiki to CP. ores:" + ores.getResourceableId(), e);
}
sb.append("</div></body></html>");
return sb.toString();
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class WikiMarkupRenderer method render.
/**
* @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
* org.olat.core.gui.render.StringOutput,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.render.URLBuilder,
* org.olat.core.gui.translator.Translator,
* org.olat.core.gui.render.RenderResult, java.lang.String[])
*/
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
WikiMarkupComponent wikiComp = (WikiMarkupComponent) source;
AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
boolean iframePostEnabled = flags.isIframePostEnabled();
ParserInput input = new ParserInput();
input.setWikiUser(null);
input.setAllowSectionEdit(false);
input.setDepth(10);
input.setContext("");
// input.setTableOfContents(null);
input.setLocale(new Locale("en"));
// input.setVirtualWiki(Long.toString(wikiComp.getOres().getResourceableId()));
input.setTopicName("dummy");
input.setUserIpAddress("0.0.0.0");
OlatWikiDataHandler dataHandler = new OlatWikiDataHandler(wikiComp.getOres(), wikiComp.getImageBaseUri());
input.setDataHandler(dataHandler);
StringOutput out = new StringOutput(100);
ubu.buildURI(out, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
String uri = out.toString();
ParserDocument parsedDoc = null;
String uniqueId = "o_wiki".concat(wikiComp.getDispatchID());
try {
uri = URLDecoder.decode(uri, "utf-8");
input.setVirtualWiki(uri.substring(1, uri.length() - 1));
if (iframePostEnabled) {
String targetUrl = " onclick=\"o_XHREvent(jQuery(this).attr('href'),false,true); return false;\"";
input.setURLTarget(targetUrl);
}
sb.append("<div style=\"min-height:" + wikiComp.getMinHeight() + "px\" id=\"");
sb.append(uniqueId);
sb.append("\">");
JFlexParser parser = new JFlexParser(input);
parsedDoc = parser.parseHTML(wikiComp.getWikiContent());
} catch (UnsupportedEncodingException e) {
// encoding utf-8 should be ok
} catch (Exception e) {
throw new OLATRuntimeException(this.getClass(), "error while rendering wiki page with content:" + wikiComp.getWikiContent(), e);
}
// Use global js math formatter for latex formulas
sb.append(Formatter.formatLatexFormulas(parsedDoc.getContent()));
sb.append("</div>");
// set targets of media, image and external links to target "_blank"
sb.append("<script type=\"text/javascript\">/* <![CDATA[ */ ");
String instanceUrl = Settings.getServerContextPathURI();
sb.append("changeAnchorTargets('").append(uniqueId).append("','").append(instanceUrl).append("');");
sb.append("/* ]]> */</script>");
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class Wiki method assignPropertiesToPage.
public static WikiPage assignPropertiesToPage(VFSLeaf leaf) {
Properties p = new Properties();
if (leaf != null) {
try (InputStream is = leaf.getInputStream()) {
p.load(is);
} catch (IOException e) {
throw new OLATRuntimeException("Wiki page couldn't be read! Pagename:" + leaf.getName(), e);
}
String pageName = p.getProperty(WikiManager.PAGENAME);
if (pageName == null) {
log.warn("wiki properties page is persent but without content. Name:" + leaf.getName());
return null;
}
String initialPageName = p.getProperty(WikiManager.INITIAL_PAGENAME);
WikiPage page = new WikiPage(pageName, initialPageName);
String oldPageNames = p.getProperty(WikiManager.OLD_PAGENAME);
if (StringHelper.containsNonWhitespace(oldPageNames)) {
String[] names = oldPageNames.split("[,]");
if (names.length > 0) {
page.setOldPageNames(Arrays.asList(names));
}
}
page.setCreationTime(p.getProperty(WikiManager.C_TIME));
page.setVersion(p.getProperty(WikiManager.VERSION));
page.setForumKey(p.getProperty(WikiManager.FORUM_KEY));
page.setInitalAuthor(p.getProperty(WikiManager.INITIAL_AUTHOR));
page.setModificationTime(p.getProperty(WikiManager.M_TIME));
page.setModifyAuthor(p.getProperty(WikiManager.MODIFY_AUTHOR));
page.setViewCount(p.getProperty(WikiManager.VIEW_COUNT));
page.setUpdateComment(p.getProperty(WikiManager.UPDATE_COMMENT));
return page;
} else {
return new WikiPage("dummy");
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class SearchClientProxy method spellCheck.
/**
* Uses Request/reply mechanism for synchronous operation.
* @see org.olat.search.service.searcher.OLATSearcher#spellCheck(java.lang.String)
*/
public Set<String> spellCheck(String query) throws ServiceNotAvailableException {
Session session = null;
try {
session = acquireSession();
TextMessage requestMessage = session.createTextMessage(query);
Message returnedMessage = doSearchRequest(session, requestMessage);
if (returnedMessage != null) {
@SuppressWarnings("unchecked") List<String> spellStringList = (List<String>) ((ObjectMessage) returnedMessage).getObject();
return new HashSet<String>(spellStringList);
} else {
// null returnedMessage
throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot receive messages!!!");
}
} catch (JMSException e) {
throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot send messages!!!");
} catch (ServiceNotAvailableException e) {
throw e;
} catch (Throwable th) {
throw new OLATRuntimeException("ClusteredSearchRequester.spellCheck() error!!!", th);
} finally {
releaseSession(session);
}
}
Aggregations