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;
}
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;
}
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);
}
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);
}
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();
}
Aggregations