/** * @return The syntax representing the syntax used for the document's content * @since 2.3M1 */ public Syntax getSyntax() { return this.doc.getSyntax(); }
/** * {@inheritDoc} * * @see com.xpn.xwiki.doc.XWikiDocument#getSyntax() */ @Override public Syntax getSyntax() { return getDocument().getSyntax(); }
@Override public Syntax getSyntax(DocumentReference reference) throws WikiComponentException { XWikiDocument componentDocument = this.getDocument(reference); return componentDocument.getSyntax(); }
/** * {@inheritDoc} * <p> * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. * * @see org.xwiki.bridge.DocumentModelBridge#getSyntaxId() * @deprecated since 2.3M1, use {link #getSyntax()} instead */ @Deprecated public String getSyntaxId() { return getSyntax().toIdString(); }
public void setContent(XDOM content) throws XWikiException { setContent(renderXDOM(content, getSyntax())); }
private String getCurrentContentSyntaxIdInternal(XWikiContext context) { String syntaxId = null; if (context.get("sdoc") != null) { // The content document syntaxId = ((XWikiDocument) context.get("sdoc")).getSyntax().toIdString(); } else if (context.getDoc() != null) { // The context document syntaxId = context.getDoc().getSyntax().toIdString(); } return syntaxId; }
/** * Return the content of a section. * * @param sectionNumber the index (+1) of the section in the list of all sections in the document. * @return the content of a section or null if the section can't be found. * @throws XWikiException error when trying to extract section content */ public String getContentOfSection(int sectionNumber) throws XWikiException { String content = null; if (is10Syntax()) { content = getContentOfSection10(sectionNumber); } else { List<HeaderBlock> headers = getFilteredHeaders(); if (headers.size() >= sectionNumber) { SectionBlock section = headers.get(sectionNumber - 1).getSection(); content = renderXDOM(new XDOM(Collections.<Block> singletonList(section)), getSyntax()); } } return content; }
/** * @return the syntax for the document to which the passed objects belongs to or the XWiki Syntax 1.0 if the * object document cannot be retrieved */ private Syntax getObjectDocumentSyntax(BaseCollection object, XWikiContext context) { Syntax syntax; try { XWikiDocument doc = context.getWiki().getDocument(object.getDocumentReference(), context); syntax = doc.getSyntax(); } catch (Exception e) { // Used to convert a Document Reference to string (compact form without the wiki part if it matches the // current wiki). EntityReferenceSerializer<String> compactWikiEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.class, "compactwiki"); LOG.warn("Error while getting the syntax corresponding to object [" + compactWikiEntityReferenceSerializer.serialize(object.getDocumentReference()) + "]. Defaulting to using XWiki 1.0 syntax. Internal error [" + e.getMessage() + "]"); syntax = Syntax.XWIKI_1_0; } return syntax; } }
@Override public List<Gadget> getGadgets(String source, MacroTransformationContext context) throws Exception { // use the passed source as a document reference DocumentReference sourceDocRef = getSourceDocumentReference(source); if (sourceDocRef == null) { return new ArrayList<>(); } // get the current document, read the objects and turn that into gadgets XWikiContext xContext = getXWikiContext(); XWiki xWiki = xContext.getWiki(); XWikiDocument sourceDoc = xWiki.getDocument(sourceDocRef, xContext); DocumentReference gadgetsClass = currentReferenceEntityResolver.resolve(GADGET_CLASS); List<BaseObject> gadgetObjects = sourceDoc.getXObjects(gadgetsClass); if (gadgetObjects == null) { return new ArrayList<>(); } return prepareGadgets(gadgetObjects, sourceDoc.getSyntax(), context); }
public void displayCustom(StringBuffer buffer, String fieldName, String prefix, String type, BaseObject object, XWikiContext context) throws XWikiException { String content = getCustomDisplay(); try { VelocityContext vcontext = Utils.getComponent(VelocityManager.class).getVelocityContext(); vcontext.put("name", fieldName); vcontext.put("prefix", prefix); vcontext.put("object", new com.xpn.xwiki.api.Object(object, context)); vcontext.put("type", type); vcontext.put("context", new com.xpn.xwiki.api.Context(context)); BaseProperty prop = (BaseProperty) object.safeget(fieldName); if (prop != null) { vcontext.put("value", prop.getValue()); } String classSyntax = context.getWiki().getDocument(getObject().getDocumentReference(), context).getSyntax().toIdString(); content = context.getDoc().getRenderedContent(content, classSyntax, context); } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_CLASSES, XWikiException.ERROR_XWIKI_CLASSES_CANNOT_PREPARE_CUSTOM_DISPLAY, "Exception while preparing the custom display of " + fieldName, e, null); } buffer.append(content); }
private boolean setWikiMacroClassesDocumentFields(XWikiDocument doc, String title) { boolean needsUpdate = false; if (StringUtils.isBlank(doc.getCreator())) { needsUpdate = true; doc.setCreator(XWikiRightService.SUPERADMIN_USER); } if (StringUtils.isBlank(doc.getAuthor())) { needsUpdate = true; doc.setAuthorReference(doc.getCreatorReference()); } if (StringUtils.isBlank(doc.getParent())) { needsUpdate = true; doc.setParent("XWiki.XWikiClasses"); } if (StringUtils.isBlank(doc.getTitle())) { needsUpdate = true; doc.setTitle(title); } if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) { needsUpdate = true; doc.setContent("{{include document=\"XWiki.ClassSheet\" /}}"); doc.setSyntax(Syntax.XWIKI_2_0); } return needsUpdate; }
/** * @return the sections in the current document * @throws XWikiException */ public List<DocumentSection> getSections() throws XWikiException { if (is10Syntax()) { return getSections10(); } else { List<DocumentSection> splitSections = new ArrayList<DocumentSection>(); List<HeaderBlock> headers = getFilteredHeaders(); int sectionNumber = 1; for (HeaderBlock header : headers) { // put -1 as index since there is no way to get the position of the header in the source int documentSectionIndex = -1; // Need to do the same thing than 1.0 content here String documentSectionLevel = StringUtils.repeat("1.", header.getLevel().getAsInt() - 1) + "1"; DocumentSection docSection = new DocumentSection(sectionNumber++, documentSectionIndex, documentSectionLevel, renderXDOM(new XDOM(header.getChildren()), getSyntax())); splitSections.add(docSection); } return splitSections; } }
content = renderXDOM(xdom, getSyntax());
@Override protected String render() throws EditException { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext); BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE); String editorCode = editorObject.getStringValue("code"); // Make sure the editor code is executed with the rights of the editor document author. XWikiDocument sdoc = editorDocument; // Execute the editor code in the context of the current document (because the editor code needs to access // the data that has been put on the script context). return xcontext.getDoc().getRenderedContent(editorCode, editorDocument.getSyntax().toIdString(), false, sdoc, xcontext); } catch (Exception e) { throw new EditException("Failed to render the editor code.", e); } }
public String extractTitle() { String title = ""; try { if (is10Syntax()) { title = extractTitle10(); } else { List<HeaderBlock> blocks = getXDOM().getChildrenByType(HeaderBlock.class, true); if (blocks.size() > 0) { HeaderBlock header = blocks.get(0); if (header.getLevel().compareTo(HeaderLevel.LEVEL2) <= 0) { XDOM headerXDOM = new XDOM(Collections.<Block> singletonList(header)); // transform TransformationContext context = new TransformationContext(headerXDOM, getSyntax()); Utils.getComponent(TransformationManager.class).performTransformations(headerXDOM, context); // render Block headerBlock = headerXDOM.getChildren().get(0); if (headerBlock instanceof HeaderBlock) { title = renderXDOM(new XDOM(headerBlock.getChildren()), Syntax.XHTML_1_0); } } } } } catch (Exception e) { // Don't stop when there's a problem rendering the title. } return title; }
/** * @param baseObject the object containing ui extension setup * @param roleType the role Type implemented * @param roleHint the role hint for this role implementation * @param componentManager The XWiki content manager * @throws ComponentLookupException If module dependencies are missing * @throws WikiComponentException When failing to parse content */ public AbstractAsyncContentBaseObjectWikiComponent(BaseObject baseObject, Type roleType, String roleHint, ComponentManager componentManager) throws ComponentLookupException, WikiComponentException { super(baseObject, roleType, roleHint); this.componentManager = componentManager; this.executor = componentManager.getInstance(BlockAsyncRendererExecutor.class); XWikiDocument ownerDocument = baseObject.getOwnerDocument(); this.parser = componentManager.getInstance(ContentParser.class); this.syntax = ownerDocument.getSyntax(); String content = baseObject.getStringValue(getContentPropertyName()); this.xdom = this.parser.parse(content, syntax, ownerDocument.getDocumentReference()); }
doc.setTitle("XWiki Aggregator URL Class"); if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) { needsUpdate = true; doc.setContent("{{include document=\"XWiki.ClassSheet\" /}}");
doc.setTitle(title); if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) { needsUpdate = true; doc.setContent("{{include reference=\"XWiki.ClassSheet\" /}}");
setSyntax(templatedoc.getSyntax());