Search in sources :

Example 1 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class JSPWikiMarkupParser method initialize.

// FIXME: parsers should be pooled for better performance.
private void initialize() {
    initInlineImagePatterns();
    m_camelCasePattern = (Pattern) m_engine.getAttribute(CAMELCASE_PATTERN);
    if (m_camelCasePattern == null) {
        try {
            m_camelCasePattern = m_compiler.compile(WIKIWORD_REGEX, Perl5Compiler.DEFAULT_MASK | Perl5Compiler.READ_ONLY_MASK);
        } catch (MalformedPatternException e) {
            log.fatal("Internal error: Someone put in a faulty pattern.", e);
            throw new InternalWikiException("Faulty camelcasepattern in TranslatorReader", e);
        }
        m_engine.setAttribute(CAMELCASE_PATTERN, m_camelCasePattern);
    }
    // 
    // Set the properties.
    // 
    Properties props = m_engine.getWikiProperties();
    String cclinks = (String) m_context.getPage().getAttribute(PROP_CAMELCASELINKS);
    if (cclinks != null) {
        m_camelCaseLinks = TextUtil.isPositive(cclinks);
    } else {
        m_camelCaseLinks = TextUtil.getBooleanProperty(props, PROP_CAMELCASELINKS, m_camelCaseLinks);
    }
    Boolean wysiwygVariable = (Boolean) m_context.getVariable(RenderingManager.WYSIWYG_EDITOR_MODE);
    if (wysiwygVariable != null) {
        m_wysiwygEditorMode = wysiwygVariable.booleanValue();
    }
    m_plainUris = m_context.getBooleanWikiProperty(PROP_PLAINURIS, m_plainUris);
    m_useOutlinkImage = m_context.getBooleanWikiProperty(PROP_USEOUTLINKIMAGE, m_useOutlinkImage);
    m_useAttachmentImage = m_context.getBooleanWikiProperty(PROP_USEATTACHMENTIMAGE, m_useAttachmentImage);
    m_allowHTML = m_context.getBooleanWikiProperty(PROP_ALLOWHTML, m_allowHTML);
    m_useRelNofollow = m_context.getBooleanWikiProperty(PROP_USERELNOFOLLOW, m_useRelNofollow);
    if (m_engine.getUserManager().getUserDatabase() == null || m_engine.getAuthorizationManager() == null) {
        disableAccessRules();
    }
    m_context.getPage().setHasMetadata();
}
Also used : MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) Properties(java.util.Properties) InternalWikiException(org.apache.wiki.InternalWikiException)

Example 2 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class WebContainerAuthorizer method initialize.

/**
 * Initializes the authorizer for.
 * @param engine the current wiki engine
 * @param props the wiki engine initialization properties
 */
public void initialize(WikiEngine engine, Properties props) {
    m_engine = engine;
    m_containerAuthorized = false;
    // FIXME: Error handling here is not very verbose
    try {
        m_webxml = getWebXml();
        if (m_webxml != null) {
            // Add the J2EE 2.4 schema namespace
            m_webxml.getRootElement().setNamespace(Namespace.getNamespace(J2EE_SCHEMA_25_NAMESPACE));
            m_containerAuthorized = isConstrained("/Delete.jsp", Role.ALL) && isConstrained("/Login.jsp", Role.ALL);
        }
        if (m_containerAuthorized) {
            m_containerRoles = getRoles(m_webxml);
            log.info("JSPWiki is using container-managed authentication.");
        } else {
            log.info("JSPWiki is using custom authentication.");
        }
    } catch (IOException e) {
        log.error("Initialization failed: ", e);
        throw new InternalWikiException(e.getClass().getName() + ": " + e.getMessage(), e);
    } catch (JDOMException e) {
        log.error("Malformed XML in web.xml", e);
        throw new InternalWikiException(e.getClass().getName() + ": " + e.getMessage(), e);
    }
    if (m_containerRoles.length > 0) {
        String roles = "";
        for (Role containerRole : m_containerRoles) {
            roles = roles + containerRole + " ";
        }
        log.info(" JSPWiki determined the web container manages these roles: " + roles);
    }
    log.info("Authorizer WebContainerAuthorizer initialized successfully.");
}
Also used : IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) InternalWikiException(org.apache.wiki.InternalWikiException)

Example 3 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class PageRenamer method renamePage.

/**
 *  Renames a page.
 *
 *  @param context The current context.
 *  @param renameFrom The name from which to rename.
 *  @param renameTo The new name.
 *  @param changeReferrers If true, also changes all the referrers.
 *  @return The final new name (in case it had to be modified)
 *  @throws WikiException If the page cannot be renamed.
 */
public String renamePage(final WikiContext context, final String renameFrom, final String renameTo, final boolean changeReferrers) throws WikiException {
    // 
    if (renameFrom == null || renameFrom.length() == 0) {
        throw new WikiException("From name may not be null or empty");
    }
    if (renameTo == null || renameTo.length() == 0) {
        throw new WikiException("To name may not be null or empty");
    }
    // 
    // Clean up the "to" -name so that it does not contain anything illegal
    // 
    String renameToClean = MarkupParser.cleanLink(renameTo.trim());
    if (renameToClean.equals(renameFrom)) {
        throw new WikiException("You cannot rename the page to itself");
    }
    // 
    // Preconditions: "from" page must exist, and "to" page must not yet exist.
    // 
    WikiEngine engine = context.getEngine();
    WikiPage fromPage = engine.getPage(renameFrom);
    if (fromPage == null) {
        throw new WikiException("No such page " + renameFrom);
    }
    WikiPage toPage = engine.getPage(renameToClean);
    if (toPage != null) {
        throw new WikiException("Page already exists " + renameToClean);
    }
    // 
    // Options
    // 
    m_camelCase = TextUtil.getBooleanProperty(engine.getWikiProperties(), JSPWikiMarkupParser.PROP_CAMELCASELINKS, m_camelCase);
    Set<String> referrers = getReferencesToChange(fromPage, engine);
    // 
    // Do the actual rename by changing from the frompage to the topage, including
    // all of the attachments
    // 
    // Remove references to attachments under old name
    @SuppressWarnings("unchecked") Collection<Attachment> attachmentsOldName = engine.getAttachmentManager().listAttachments(fromPage);
    for (Attachment att : attachmentsOldName) {
        WikiPage fromAttPage = engine.getPage(att.getName());
        engine.getReferenceManager().pageRemoved(fromAttPage);
    }
    engine.getPageManager().getProvider().movePage(renameFrom, renameToClean);
    if (engine.getAttachmentManager().attachmentsEnabled()) {
        engine.getAttachmentManager().getCurrentProvider().moveAttachmentsForPage(renameFrom, renameToClean);
    }
    // 
    // Add a comment to the page notifying what changed.  This adds a new revision
    // to the repo with no actual change.
    // 
    toPage = engine.getPage(renameToClean);
    if (toPage == null)
        throw new InternalWikiException("Rename seems to have failed for some strange reason - please check logs!");
    toPage.setAttribute(WikiPage.CHANGENOTE, fromPage.getName() + " ==> " + toPage.getName());
    toPage.setAuthor(context.getCurrentUser().getName());
    engine.getPageManager().putPageText(toPage, engine.getPureText(toPage));
    // 
    // Update the references
    // 
    engine.getReferenceManager().pageRemoved(fromPage);
    engine.updateReferences(toPage);
    // 
    if (changeReferrers) {
        updateReferrers(context, fromPage, toPage, referrers);
    }
    // 
    // re-index the page including its attachments
    // 
    engine.getSearchManager().reindexPage(toPage);
    @SuppressWarnings("unchecked") Collection<Attachment> attachmentsNewName = engine.getAttachmentManager().listAttachments(toPage);
    for (Attachment att : attachmentsNewName) {
        WikiPage toAttPage = engine.getPage(att.getName());
        // add reference to attachment under new page name
        engine.updateReferences(toAttPage);
        engine.getSearchManager().reindexPage(att);
    }
    // Currently not used internally by JSPWiki itself, but you can use it for something else.
    WikiEventManager.fireEvent(this, new WikiPageRenameEvent(this, renameFrom, renameToClean));
    // 
    return renameToClean;
}
Also used : InternalWikiException(org.apache.wiki.InternalWikiException) WikiException(org.apache.wiki.api.exceptions.WikiException) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) WikiEngine(org.apache.wiki.WikiEngine) InternalWikiException(org.apache.wiki.InternalWikiException) WikiPageRenameEvent(org.apache.wiki.event.WikiPageRenameEvent)

Example 4 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class JSPWikiMarkupParser method makeSectionTitle.

private String makeSectionTitle(String title) {
    title = title.trim();
    String outTitle;
    try {
        JSPWikiMarkupParser dtr = getCleanTranslator();
        dtr.setInputReader(new StringReader(title));
        CleanTextRenderer ctt = new CleanTextRenderer(m_context, dtr.parse());
        outTitle = ctt.getString();
    } catch (IOException e) {
        log.fatal("CleanTranslator not working", e);
        throw new InternalWikiException("CleanTranslator not working as expected, when cleaning title" + e.getMessage(), e);
    }
    return outTitle;
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) CleanTextRenderer(org.apache.wiki.render.CleanTextRenderer) InternalWikiException(org.apache.wiki.InternalWikiException)

Example 5 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class JSPWikiMarkupParser method makeHeading.

/**
 *  Returns XHTML for the heading.
 *
 *  @param level The level of the heading.  @see Heading
 *  @param title the title for the heading
 *  @param hd a List to which heading should be added
 *  @return An Element containing the heading
 */
public Element makeHeading(int level, String title, Heading hd) {
    Element el = null;
    String pageName = m_context.getPage().getName();
    String outTitle = makeSectionTitle(title);
    hd.m_level = level;
    switch(level) {
        case Heading.HEADING_SMALL:
            el = new Element("h4").setAttribute("id", makeHeadingAnchor(pageName, outTitle, hd));
            break;
        case Heading.HEADING_MEDIUM:
            el = new Element("h3").setAttribute("id", makeHeadingAnchor(pageName, outTitle, hd));
            break;
        case Heading.HEADING_LARGE:
            el = new Element("h2").setAttribute("id", makeHeadingAnchor(pageName, outTitle, hd));
            break;
        default:
            throw new InternalWikiException("Illegal heading type " + level);
    }
    return el;
}
Also used : Element(org.jdom2.Element) InternalWikiException(org.apache.wiki.InternalWikiException)

Aggregations

InternalWikiException (org.apache.wiki.InternalWikiException)12 WikiPage (org.apache.wiki.WikiPage)4 IOException (java.io.IOException)3 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)2 WikiEngine (org.apache.wiki.WikiEngine)2 JDOMException (org.jdom2.JDOMException)2 File (java.io.File)1 StringReader (java.io.StringReader)1 Principal (java.security.Principal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 MissingResourceException (java.util.MissingResourceException)1 NoSuchElementException (java.util.NoSuchElementException)1 Properties (java.util.Properties)1 TimeZone (java.util.TimeZone)1 JspWriter (javax.servlet.jsp.JspWriter)1 MatchResult (org.apache.oro.text.regex.MatchResult)1 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)1 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)1