use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultOfficeViewerScriptService method view.
@Override
public String view(AttachmentReference attachmentReference, Map<String, String> parameters) {
// Clear previous caught exception.
this.execution.getContext().removeProperty(OFFICE_VIEW_EXCEPTION);
try {
DocumentReference documentReference = attachmentReference.getDocumentReference();
// Check whether current user has view rights on the document containing the attachment.
if (!this.documentAccessBridge.isDocumentViewable(documentReference)) {
throw new RuntimeException("Inadequate privileges.");
}
// Create the view and render the result.
Syntax fromSyntax = this.documentAccessBridge.getTranslatedDocumentInstance(documentReference).getSyntax();
Syntax toSyntax = Syntax.XHTML_1_0;
return render(this.officeViewer.createView(attachmentReference, parameters), fromSyntax, toSyntax);
} catch (Exception e) {
// Save caught exception.
this.execution.getContext().setProperty(OFFICE_VIEW_EXCEPTION, e);
this.logger.error("Failed to view office document: " + attachmentReference, e);
return null;
}
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultCoreConfiguration method getDefaultDocumentSyntax.
/**
* @see CoreConfiguration#getDefaultDocumentSyntax()
* @since 2.3M1
*/
@Override
public Syntax getDefaultDocumentSyntax() {
// If the found value is an empty string then default to the configuration value in the main configuration
// source.
// TODO: In the future we would need the notion of initialized/not-initialized property values in the wiki.
// When this is implemented modify the code below.
String key = PREFIX + "defaultDocumentSyntax";
String syntaxId = this.configuration.getProperty(key, String.class);
if (StringUtils.isEmpty(syntaxId)) {
syntaxId = this.xwikiPropertiesConfiguration.getProperty(key, Syntax.XWIKI_2_1.toIdString());
}
// Try to parse the syntax and if it fails defaults to the XWiki Syntax 2.1
Syntax syntax;
try {
syntax = Syntax.valueOf(syntaxId);
} catch (ParseException e) {
this.logger.warn("Invalid default document Syntax [" + syntaxId + "], defaulting to [" + Syntax.XWIKI_2_1.toIdString() + "] instead", e);
syntax = Syntax.XWIKI_2_1;
}
return syntax;
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class XWikiDocument method getDefaultDocumentSyntax.
/**
* If there's no parser available for the specified syntax default to the XWiki 2.1 syntax.
*/
private Syntax getDefaultDocumentSyntax() {
Syntax syntax = Utils.getComponent(CoreConfiguration.class).getDefaultDocumentSyntax();
if (syntax == null || (!Utils.getComponentManager().hasComponent(Parser.class, syntax.toIdString()) && !Syntax.XWIKI_2_1.equals(syntax))) {
LOGGER.warn("Failed to find parser for the default syntax [{}]. Defaulting to xwiki/2.1 syntax.", syntax);
syntax = Syntax.XWIKI_2_1;
}
return syntax;
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class XWiki method createUser.
/**
* Create a new user.
*
* @param userName the name of the user (without the space)
* @param map extra datas to add to user profile object
* @param userRights the right of the user on his own profile page
* @param context see {@link XWikiContext}
* @return
* <ul>
* <li>1: ok</li>
* <li>-3: user already exists</li>
* </ul>
* @throws XWikiException failed to create the new user
*/
public int createUser(String userName, Map<String, ?> map, String userRights, XWikiContext context) throws XWikiException {
BaseClass userClass = getUserClass(context);
String content = "";
Syntax syntax = getDefaultDocumentSyntaxInternal();
return createUser(userName, map, new EntityReference(userClass.getDocumentReference().getName(), EntityType.DOCUMENT), content, syntax, userRights, context);
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class XWiki method createUser.
public int createUser(boolean withValidation, String userRights, XWikiContext context) throws XWikiException {
try {
XWikiRequest request = context.getRequest();
Map<String, String[]> map = Util.getObject(request, "register");
String content = "";
Syntax syntax = getDefaultDocumentSyntaxInternal();
// Read the values from the request.
String xwikiname = request.getParameter("xwikiname");
String password2 = request.getParameter("register2_password");
String password = (map.get("password"))[0];
String email = (map.get("email"))[0];
String template = request.getParameter("template");
String parent = request.getParameter("parent");
String validkey = null;
// Validate the values.
if (XWikiRightService.SUPERADMIN_USER.equalsIgnoreCase(xwikiname)) {
return -8;
}
try {
if (!context.getUtil().match(getConfiguration().getProperty("xwiki.validusername", "/^[a-zA-Z0-9_]+$/"), xwikiname)) {
return -4;
}
} catch (RuntimeException ex) {
LOGGER.warn("Invalid regular expression for xwiki.validusername", ex);
if (!context.getUtil().match("/^[a-zA-Z0-9_]+$/", xwikiname)) {
return -4;
}
}
if ((!password.equals(password2)) || (password.trim().equals(""))) {
// TODO: throw wrong password exception
return -2;
}
if ((template != null) && (!template.equals(""))) {
XWikiDocument tdoc = getDocument(template, context);
if ((!tdoc.isNew())) {
// FIXME: This ignores template objects, attachments, etc.
content = tdoc.getContent();
syntax = tdoc.getSyntax();
}
}
if ((parent == null) || (parent.equals(""))) {
parent = "XWiki.XWikiUsers";
}
// Mark the user as active or waiting email validation.
if (withValidation) {
map.put("active", new String[] { "0" });
validkey = generateValidationKey(16);
map.put("validkey", new String[] { validkey });
} else {
// Mark user active
map.put("active", new String[] { "1" });
}
// Create the user.
int result = createUser(xwikiname, map, getRelativeEntityReferenceResolver().resolve(parent, EntityType.DOCUMENT), content, syntax, userRights, context);
// Send validation mail, if needed.
if ((result > 0) && (withValidation)) {
// Send the validation email
try {
sendValidationEmail(xwikiname, password, email, validkey, "validation_email_content", context);
} catch (XWikiException e) {
LOGGER.warn("User created. Failed to send the mail to the created user.", e);
return -11;
}
}
return result;
} catch (XWikiException e) {
LOGGER.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_CREATE_USER, "Exception while creating user", e, null);
}
}
Aggregations