Search in sources :

Example 41 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class DefaultAuthorExecutor method before.

@Override
public AutoCloseable before(DocumentReference authorReference) {
    DefaultAuthorExecutorContext suContext;
    XWikiContext xwikiContext = this.xcontextProvider.get();
    if (xwikiContext != null) {
        suContext = new DefaultAuthorExecutorContext();
        // Make sure to have the right secure document
        suContext.currentSecureDocument = (XWikiDocument) xwikiContext.get(XWikiDocument.CKEY_SDOC);
        XWikiDocument secureDocument = new XWikiDocument(new DocumentReference(authorReference != null ? authorReference.getWikiReference().getName() : "xwiki", "SUSpace", "SUPage"));
        secureDocument.setContentAuthorReference(authorReference);
        secureDocument.setAuthorReference(authorReference);
        secureDocument.setCreatorReference(authorReference);
        xwikiContext.put(XWikiDocument.CKEY_SDOC, secureDocument);
        // Make sure to disable XWikiContext#dropPermission hack
        suContext.xwikiContextDropPermissionHack = xwikiContext.remove(XWikiConstant.DROPPED_PERMISSIONS);
        // Make sure to disable Document#dropPermission hack
        ExecutionContext econtext = this.execution.getContext();
        if (econtext != null) {
            suContext.documentDropPermissionHack = econtext.getProperty(XWikiConstant.DROPPED_PERMISSIONS);
            econtext.removeProperty(XWikiConstant.DROPPED_PERMISSIONS);
        }
    } else {
        suContext = null;
    }
    return suContext;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 42 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class InternalSkinManager method getCurrentSkinId.

public String getCurrentSkinId(boolean testRights) {
    String skin;
    XWikiContext xcontext = this.xcontextProvider.get();
    if (xcontext != null) {
        // Try to get it from context
        skin = (String) xcontext.get(CKEY_SKIN);
        if (StringUtils.isNotEmpty(skin)) {
            return skin;
        } else {
            skin = null;
        }
        // Try to get it from URL
        if (xcontext.getRequest() != null) {
            skin = xcontext.getRequest().getParameter("skin");
            if (StringUtils.isNotEmpty(skin)) {
                return skin;
            } else {
                skin = null;
            }
        }
        // Try to get it from preferences (user -> space -> wiki -> xwiki.properties)
        skin = this.allConfiguration.getProperty("skin");
        if (skin != null) {
            return skin;
        }
    }
    // Try to get it from xwiki.cfg
    skin = getDefaultSkinId();
    if (xcontext != null) {
        // TODO: shouldn't we make sure anyone see the skin whatever right he have ?
        if (testRights) {
            XWikiDocument document = this.wikiSkinUtils.getSkinDocument(skin);
            if (document != null) {
                if (!this.authorization.hasAccess(Right.VIEW, document.getDocumentReference())) {
                    this.logger.debug("Cannot access configured wiki skin [{}] due to access rights, using the default skin.", skin);
                    skin = getDefaultSkinId();
                }
            }
        }
        // Set found skin in the context
        xcontext.put(CKEY_SKIN, skin);
    }
    return skin;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext)

Example 43 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class SkinEnvironmentResource method getURL.

@Override
public String getURL(boolean forceSkinAction) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiURLFactory urlf = xcontext.getURLFactory();
    URL url;
    if (forceSkinAction) {
        url = urlf.createSkinURL(this.resourceName, "skins", getRepository().getId(), xcontext);
    } else {
        url = urlf.createSkinURL(this.resourceName, getRepository().getId(), xcontext);
    }
    return urlf.getURL(url, xcontext);
}
Also used : XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) XWikiContext(com.xpn.xwiki.XWikiContext) URL(java.net.URL)

Example 44 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class DownloadAction method pushDocumentInContext.

private void pushDocumentInContext(Map<String, Object> backupObjects, DocumentReference documentReference) throws XWikiException {
    XWikiContext xcontext = getContext();
    // Backup current context state
    XWikiDocument.backupContext(backupObjects, xcontext);
    // Make sure to get the current XWikiContext after ExcutionContext clone
    xcontext = getContext();
    // Change context document
    xcontext.getWiki().getDocument(documentReference, xcontext).setAsContextDoc(xcontext);
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext)

Example 45 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class R40000XWIKI6990DataMigration method getLiquibaseChangeLog.

@Override
public String getLiquibaseChangeLog() throws DataMigrationException {
    final XWikiHibernateBaseStore store = getStore();
    this.configuration = store.getConfiguration();
    final StringBuilder sb = new StringBuilder(12000);
    final List<PersistentClass> classes = new ArrayList<PersistentClass>();
    detectDatabaseProducts(store);
    if (this.logger.isDebugEnabled()) {
        if (this.isOracle) {
            this.logger.debug("Oracle database detected, proceeding to all updates manually with deferred constraints.");
        }
        if (this.isMySQL && !this.isMySQLMyISAM) {
            this.logger.debug("MySQL innoDB database detected, proceeding to simplified updates with cascaded updates.");
        }
        if (this.isMySQLMyISAM) {
            this.logger.debug("MySQL MyISAM database detected, proceeding to all updates manually without constraints.");
        }
        if (this.isMSSQL) {
            this.logger.debug("Microsoft SQL Server database detected, proceeding to simplified updates with cascaded u" + "pdates. During data type changes, Primary Key constraints and indexes are temporarily dropped.");
        }
    }
    // Build the list of classes to check for updates
    classes.add(getClassMapping(BaseObject.class.getName()));
    for (Class<?> klass : PROPERTY_CLASS) {
        classes.add(getClassMapping(klass.getName()));
    }
    for (Class<?> klass : STATS_CLASSES) {
        classes.add(getClassMapping(klass.getName()));
    }
    // Initialize the counter of Change Logs
    this.logCount = 0;
    // do not prevent type changes, we skip all this processing for MySQL table stored using the MyISAM engine.
    if (!this.isMySQLMyISAM) {
        for (PersistentClass klass : classes) {
            this.fkTables.addAll(getForeignKeyTables(klass));
        }
    }
    // Drop all FK constraints
    for (Table table : this.fkTables) {
        appendDropForeignKeyChangeLog(sb, table);
    }
    // Process internal classes
    for (PersistentClass klass : classes) {
        // The same table mapped for StringListProperty and LargeStringProperty
        if (klass.getMappedClass() != StringListProperty.class) {
            // Update key types
            appendDataTypeChangeLogs(sb, klass);
        }
    }
    // Process dynamic and custom mapping
    final XWikiContext context = getXWikiContext();
    try {
        processCustomMappings((XWikiHibernateStore) store, new CustomMappingCallback() {

            @Override
            public void processCustomMapping(XWikiHibernateStore store, String name, String mapping, boolean hasDynamicMapping) throws XWikiException {
                if (INTERNAL.equals(mapping) || hasDynamicMapping) {
                    PersistentClass klass = R40000XWIKI6990DataMigration.this.configuration.getClassMapping(name);
                    if (!R40000XWIKI6990DataMigration.this.isMySQLMyISAM) {
                        List<Table> tables = getForeignKeyTables(klass);
                        for (Table table : tables) {
                            if (!R40000XWIKI6990DataMigration.this.fkTables.contains(table)) {
                                // Drop FK constraints for custom mapped class
                                appendDropForeignKeyChangeLog(sb, table);
                                R40000XWIKI6990DataMigration.this.fkTables.add(table);
                            }
                        }
                    }
                    // Update key types for custom mapped class
                    appendDataTypeChangeLogs(sb, klass);
                }
            }
        }, context);
    } catch (XWikiException e) {
        throw new DataMigrationException("Unable to process custom mapped classes during schema updated", e);
    }
    // Add FK constraints back, activating cascaded updates
    for (Table table : this.fkTables) {
        appendAddForeignKeyChangeLog(sb, table);
    }
    // Oracle doesn't support cascaded updates, so we still need to manually update each table
    if (this.isOracle) {
        this.fkTables.clear();
    }
    logProgress("%d schema updates required.", this.logCount);
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("About to execute this Liquibase XML: {}", sb.toString());
    }
    return sb.toString();
}
Also used : Table(org.hibernate.mapping.Table) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) XWikiHibernateBaseStore(com.xpn.xwiki.store.XWikiHibernateBaseStore) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException) XWikiException(com.xpn.xwiki.XWikiException) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)564 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)203 XWikiException (com.xpn.xwiki.XWikiException)195 DocumentReference (org.xwiki.model.reference.DocumentReference)150 XWiki (com.xpn.xwiki.XWiki)106 BaseObject (com.xpn.xwiki.objects.BaseObject)104 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)55 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)43 ExecutionContext (org.xwiki.context.ExecutionContext)43 Session (org.hibernate.Session)37 InitializationException (org.xwiki.component.phase.InitializationException)36 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)34 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)33 WikiReference (org.xwiki.model.reference.WikiReference)31 Before (org.junit.Before)29 EntityReference (org.xwiki.model.reference.EntityReference)28 QueryException (org.xwiki.query.QueryException)28 Execution (org.xwiki.context.Execution)27 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)24