use of com.xpn.xwiki.objects.classes.TextAreaClass in project xwiki-platform by xwiki.
the class XWikiDocument method convertSyntax.
/**
* Convert the current document content from its current syntax to the new syntax passed as parameter.
*
* @param targetSyntax the syntax to convert to (e.g. {@code xwiki/2.0}, {@code xhtml/1.0}, etc)
* @throws XWikiException if an exception occurred during the conversion process
*/
public void convertSyntax(Syntax targetSyntax, XWikiContext context) throws XWikiException {
// convert content
setContent(performSyntaxConversion(getContent(), getDocumentReference(), getSyntax(), targetSyntax));
// convert objects
Map<DocumentReference, List<BaseObject>> objectsByClass = getXObjects();
for (List<BaseObject> objects : objectsByClass.values()) {
for (BaseObject bobject : objects) {
if (bobject != null) {
BaseClass bclass = bobject.getXClass(context);
for (Object fieldClass : bclass.getProperties()) {
if (fieldClass instanceof TextAreaClass && ((TextAreaClass) fieldClass).isWikiContent()) {
TextAreaClass textAreaClass = (TextAreaClass) fieldClass;
LargeStringProperty field = (LargeStringProperty) bobject.getField(textAreaClass.getName());
if (field != null) {
field.setValue(performSyntaxConversion(field.getValue(), getDocumentReference(), getSyntax(), targetSyntax));
}
}
}
}
}
}
// change syntax
setSyntax(targetSyntax);
}
use of com.xpn.xwiki.objects.classes.TextAreaClass in project xwiki-platform by xwiki.
the class XWikiDocumentMockitoTest method generateFakeClass.
/**
* Generate the fake class that is used for the test of {@link #readObjectsFromForm()} and
* {@link #readObjectsFromFormUpdateOrCreate()}.
*
* @return The fake BaseClass
*/
private BaseClass generateFakeClass() {
BaseClass baseClass = this.document.getXClass();
baseClass.addTextField("string", "String", 30);
baseClass.addTextAreaField("area", "Area", 10, 10);
baseClass.addTextAreaField("puretextarea", "Pure text area", 10, 10);
// set the text areas an non interpreted content
((TextAreaClass) baseClass.getField("puretextarea")).setContentType("puretext");
baseClass.addPasswordField("passwd", "Password", 30);
baseClass.addBooleanField("boolean", "Boolean", "yesno");
baseClass.addNumberField("int", "Int", 10, "integer");
baseClass.addStaticListField("stringlist", "StringList", "value1, value2");
return baseClass;
}
use of com.xpn.xwiki.objects.classes.TextAreaClass in project xwiki-platform by xwiki.
the class XWikiDocumentTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
this.defaultEntityReferenceSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
this.document = new XWikiDocument(new DocumentReference(DOCWIKI, DOCSPACE, DOCNAME));
this.document.setSyntax(Syntax.XWIKI_2_0);
this.document.setLanguage("en");
this.document.setDefaultLanguage("en");
this.document.setNew(false);
this.translatedDocument = new XWikiDocument();
this.translatedDocument.setSyntax(Syntax.XWIKI_2_0);
this.translatedDocument.setLanguage("fr");
this.translatedDocument.setNew(false);
getContext().put("isInRenderingEngine", true);
this.mockXWiki = mock(XWiki.class);
this.mockXWikiVersioningStore = mock(XWikiVersioningStoreInterface.class);
this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null));
this.mockXWikiStoreInterface = mock(XWikiStoreInterface.class);
this.document.setStore((XWikiStoreInterface) this.mockXWikiStoreInterface.proxy());
this.mockXWikiMessageTool = mock(XWikiMessageTool.class, new Class[] { ResourceBundle.class, XWikiContext.class }, new Object[] { null, getContext() });
this.mockXWikiMessageTool.stubs().method("get").will(returnValue("message"));
this.mockXWikiRightService = mock(XWikiRightService.class);
this.mockXWikiRightService.stubs().method("hasProgrammingRights").will(returnValue(true));
this.mockXWiki.stubs().method("getVersioningStore").will(returnValue(this.mockXWikiVersioningStore.proxy()));
this.mockXWiki.stubs().method("getStore").will(returnValue(this.mockXWikiStoreInterface.proxy()));
this.mockXWiki.stubs().method("getDocument").will(returnValue(this.document));
this.mockXWiki.stubs().method("getLanguagePreference").will(returnValue("en"));
this.mockXWiki.stubs().method("getSectionEditingDepth").will(returnValue(2L));
this.mockXWiki.stubs().method("getRightService").will(returnValue(this.mockXWikiRightService.proxy()));
getContext().setWiki((XWiki) this.mockXWiki.proxy());
getContext().put("msg", this.mockXWikiMessageTool.proxy());
this.baseClass = this.document.getxWikiClass();
this.baseClass.addTextField("string", "String", 30);
this.baseClass.addTextAreaField("area", "Area", 10, 10);
this.baseClass.addTextAreaField("puretextarea", "Pure text area", 10, 10);
// set the text areas an non interpreted content
((TextAreaClass) this.baseClass.getField("puretextarea")).setContentType("puretext");
this.baseClass.addPasswordField("passwd", "Password", 30);
this.baseClass.addBooleanField("boolean", "Boolean", "yesno");
this.baseClass.addNumberField("int", "Int", 10, "integer");
this.baseClass.addStaticListField("stringlist", "StringList", "value1, value2");
this.mockXWiki.stubs().method("getClass").will(returnValue(this.baseClass));
this.mockXWiki.stubs().method("getXClass").will(returnValue(this.baseClass));
this.baseObject = this.document.newObject(CLASSNAME, getContext());
this.baseObject.setStringValue("string", "string");
this.baseObject.setLargeStringValue("area", "area");
this.baseObject.setStringValue("passwd", "passwd");
this.baseObject.setIntValue("boolean", 1);
this.baseObject.setIntValue("int", 42);
this.baseObject.setStringListValue("stringlist", Arrays.asList("VALUE1", "VALUE2"));
this.mockXWikiStoreInterface.stubs().method("search").will(returnValue(new ArrayList<XWikiDocument>()));
// Set the default link label generator format to %np for some tests below.
// We need to do this since we don't depend on xwiki-platform-rendering-configuration-default (which contains
// an overridden RenderingConfiguration impl that sets the format to %np by default).
DefaultRenderingConfiguration renderingConfiguration = getComponentManager().getInstance(RenderingConfiguration.class);
renderingConfiguration.setLinkLabelFormat("%np");
}
use of com.xpn.xwiki.objects.classes.TextAreaClass in project xwiki-platform by xwiki.
the class XWikiDocumentMergeTest method before.
@Before
public void before() throws Exception {
this.oldcore.registerMockEnvironment();
this.currentDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
this.previousDocument = this.currentDocument.clone();
this.nextDocument = this.currentDocument.clone();
this.xclass = new BaseClass();
this.xclass.setDocumentReference(new DocumentReference("wiki", "classspace", "class"));
this.xclass.addTextField("string", "String", 30);
this.xclass.addTextAreaField("area", "Area", 10, 10);
this.xclass.addTextAreaField("puretextarea", "Pure text area", 10, 10);
// set the text areas an non interpreted content
((TextAreaClass) this.xclass.getField("puretextarea")).setContentType("puretext");
this.xclass.addPasswordField("passwd", "Password", 30);
this.xclass.addBooleanField("boolean", "Boolean", "yesno");
this.xclass.addNumberField("int", "Int", 10, "integer");
this.xclass.addStaticListField("stringlist", "StringList", "value1, value2");
this.xobject = new BaseObject();
this.xobject.setXClassReference(this.xclass.getDocumentReference());
this.xobject.setStringValue("string", "string");
this.xobject.setLargeStringValue("area", "area");
this.xobject.setStringValue("passwd", "passwd");
this.xobject.setIntValue("boolean", 1);
this.xobject.setIntValue("int", 42);
this.xobject.setStringListValue("stringlist", Arrays.asList("VALUE1", "VALUE2"));
this.configuration = new MergeConfiguration();
}
use of com.xpn.xwiki.objects.classes.TextAreaClass in project xwiki-platform by xwiki.
the class XWikiHibernateStore method loadXWikiCollectionInternal.
private void loadXWikiCollectionInternal(BaseCollection object1, XWikiDocument doc, XWikiContext inputxcontext, boolean bTransaction, boolean alreadyLoaded) throws XWikiException {
XWikiContext context = getExecutionXContext(inputxcontext, true);
BaseCollection object = object1;
try {
if (bTransaction) {
checkHibernate(context);
bTransaction = beginTransaction(false, context);
}
Session session = getSession(context);
if (!alreadyLoaded) {
try {
session.load(object, object1.getId());
} catch (ObjectNotFoundException e) {
// There is no object data saved
object = null;
return;
}
}
DocumentReference classReference = object.getXClassReference();
// If the class reference is null in the loaded object then skip loading properties
if (classReference != null) {
BaseClass bclass = null;
if (!classReference.equals(object.getDocumentReference())) {
// Let's check if the class has a custom mapping
bclass = object.getXClass(context);
} else {
// we will go in an endless loop
if (doc != null) {
bclass = doc.getXClass();
}
}
List<String> handledProps = new ArrayList<String>();
try {
if ((bclass != null) && (bclass.hasCustomMapping()) && context.getWiki().hasCustomMappings()) {
Session dynamicSession = session.getSession(EntityMode.MAP);
Object map = dynamicSession.load(bclass.getName(), object.getId());
// Let's make sure to look for null fields in the dynamic mapping
bclass.fromValueMap((Map) map, object);
handledProps = bclass.getCustomMappingPropertyList(context);
for (String prop : handledProps) {
if (((Map) map).get(prop) == null) {
handledProps.remove(prop);
}
}
}
} catch (Exception e) {
}
// Load strings, integers, dates all at once
Query query = session.createQuery("select prop.name, prop.classType from BaseProperty as prop where prop.id.id = :id");
query.setLong("id", object.getId());
for (Object[] result : (List<Object[]>) query.list()) {
String name = (String) result[0];
// custom mapping
if (handledProps.contains(name)) {
continue;
}
String classType = (String) result[1];
BaseProperty property = null;
try {
property = (BaseProperty) Class.forName(classType).newInstance();
property.setObject(object);
property.setName(name);
loadXWikiProperty(property, context, false);
} catch (Exception e) {
// WORKAROUND IN CASE OF MIXMATCH BETWEEN STRING AND LARGESTRING
try {
if (property instanceof StringProperty) {
LargeStringProperty property2 = new LargeStringProperty();
property2.setObject(object);
property2.setName(name);
loadXWikiProperty(property2, context, false);
property.setValue(property2.getValue());
if (bclass != null) {
if (bclass.get(name) instanceof TextAreaClass) {
property = property2;
}
}
} else if (property instanceof LargeStringProperty) {
StringProperty property2 = new StringProperty();
property2.setObject(object);
property2.setName(name);
loadXWikiProperty(property2, context, false);
property.setValue(property2.getValue());
if (bclass != null) {
if (bclass.get(name) instanceof StringClass) {
property = property2;
}
}
} else {
throw e;
}
} catch (Throwable e2) {
Object[] args = { object.getName(), object.getClass(), Integer.valueOf(object.getNumber() + ""), name };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading object '{0}' of class '{1}', number '{2}' and property '{3}'", e, args);
}
}
object.addField(name, property);
}
}
if (bTransaction) {
endTransaction(context, false, false);
}
} catch (Exception e) {
Object[] args = { object.getName(), object.getClass(), Integer.valueOf(object.getNumber() + "") };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading object '{0}' of class '{1}' and number '{2}'", e, args);
} finally {
try {
if (bTransaction) {
endTransaction(context, false, false);
}
} catch (Exception e) {
}
restoreExecutionXContext();
}
}
Aggregations