I am new to XWiki and not a Java Developer. I would like to develop a simple AppWithinMinutes app (Let us call it ServerCatalog) for a list of servers with their properties like OS, Environment, etc.. That is all doable. I can develop that from AppWithinMinites UI.
I also have developed a macro which lists all pages by tags.
Now for example, when Someone creates an entry in my ServerCatalog say SERVERD56 Where D stands for Development environment.
when we display that Entry, I also want to execute my macro that I developed so that it can list all pages that matches the tag SERVERX56.
Note that I replaced D with X So before executing macro, I want to manipulate that page title and remove Environment prefix (in this case D for Development Environment) with X.
I hope it is clear of what I want to accomplish. Please let me know if it is unclear.
If someone can assist me on doing it, I will truly appreciate that.
EDITS:
As suggested by Eduard Moraru, I tried following things:
I have created a custom macro called "PageListByTag".
Since python has more control over string operations, I added following at the end of ServerCatalogSheet
.
.
.
.
{{/html}}
{{/velocity}}
{{python}}
title = document.getTitle()
newTitle = title[:6] + "X" + title[6+1:]
print(newTitle)
{{/python}}
There are several problems with it..
my html tag is already ended. I can't inject any new content in it anymore
I can't add python code inside velocity tags as nested scripting is not allowed by XWiki
I still don't know how to call my macro inside python code if I want to use python
If I can replace 6th character in a string using velocity, then everything works. I can use macro inside velocity script since it is within that html boundaries.
As far as I understand, you want to customize the "sheet" of the application which is used when displaying an application entry.
If you have a look a the documentation's section on customization, you get a lot of starting points on where you should be looking:
https://extensions.xwiki.org/xwiki/bin/view/Extension/App%20Within%20Minutes%20Application#HCustomization
This line would be interesting (but also the above links on how XWiki applications work):
The sheet, which is used to display and edit application entries (e.g. HolidaySheet)
In your case, it the document to customize (edit in wiki syntax mode) should be ServerCatalog.Code.ServerCatalogSheet
Inside that document, you have code automatically generated by AWM to which you can add a call to your macro.
## AWM generated code...
...
## Customization:
{{displayAssociatedPages /}}
Then, inside this macro (called displayAssociatedPages, in this example), you could do something like:
{{velocity}}
#set ($title = $doc.title)
## OR #set ($title = $doc.name), depending if your pages have titles
#if ($title.startsWith('SERVERD'))
#set ($tag = $title.replaceFirst('SERVERD', 'SERVERX'))
##
## We can reuse and customize this snippet: https://snippets.xwiki.org/xwiki/bin/view/Extension/Display%20pages%20with%20a%20specific%20tag/
##
#set ($references = $xwiki.tag.getDocumentsWithTag($tag))
#foreach($reference in $references)
#set ($document = $xwiki.getDocument($reference))
#set ($label = $document.getTitle())
[[$label>>$reference]]
#end
#end
{{/velocity}}
API documentation and more info at https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/API/
Also, you should understand that once you customize an AWM application, you should be careful when editing it with AWM itself. For example, if you add a new field, AFAIK, you risk having the customizations done to your sheet, as in the above example, overwritten, so you should recover them from document history and re-apply them.
Related
I want a page break after every chapter and every section.
We can get page breaks in restructured text, anywhere we want using:
.. raw::pdf
PageBreak
The good thing is this works both with rst2pdf as well as rinohtype. However, the advantage with rinohtype is we can achieve the same without adding the above code manually after every section using stylesheets.
I am just not sure how we can do that using stylesheets, can anyone help?
Using a custom style sheet, you can force page breaks before arbitrary sections by setting the page_break style attribute (in the upcoming 0.5.0 release, page_break can be set on any flowable, not just sections).
To insert a page break at an arbitrary point:
Indicate where to insert the page break:
or using the class directive (or rst-class in Sphinx) before a body element, or
assign a class to a directive by setting the :class: attribute
Define a style with a selector matching the class name. This is achieved by means of the has_class selector attribute.
The page break will be inserted before the corresponding element.
Here's an example, assuming you're using rinohtype 0.4.3.dev1 or later:
Your reStructuredText file:
.. image:: images/screenshot.png
:class: page-break
A regular paragraph.
.. rst-class:: page-break
This paragraph will trigger a page break.
Your custom style sheet:
[page-break-paragraph : Paragraph(has_class="page-break")]
base = default
page_break = any
[page-break-image : Image(has_class="page_break")]
base = image
page_break = any
Note that the newly defined styles will also determine the styling of the page-breaking element. To style them like other elements in the document, you need to set their base style to the default style. Refer to the style log to figure out which styles these are.
See issue #186 for some more details about page breaks in reStructuredText and rinohtype.
I'm creating a custom theme for Liferay, I wish to include the footer within each page layout individually. Unfortunately, I don't appear to have access to the $full_templates_path variable within the page layout files. I have had no luck manually storing the value with #set and then accessing that value within the included template.
In a vanilla theme, processing of files is something like this:
portal_normal.vm:
1) some init, doctype, etc.
2) #parse("$full_templates_path/header.vm")
3) $theme.include($content_include)
a) custom_layout_1.tpl
b) chat portlet
4) #parse("$full_templates_path/footer.vm")
For layout purposes, I need to deviate from this pattern, like so:
portal_normal.vm
1) some init, doctype, etc.
2) #parse("$full_templates_path/header.vm")
3) $theme.include($content_include)
a) custom_layout_1.tpl
i) #parse("$full_templates_path/footer.vm")
b) chat portlet
When I try this, tomcat errors out because $full_templates_path is not defined within custom_layout_1.tpl. I tried to fix this problem by doing the following within portal_normal.vm
#set($full_footer_path = "$full_templates_path/footer.vm")
$theme.include($content_include)
And then, within custom_layout_1.tpl, I do this where I'd like the footer markup emitted:
#parse("$full_footer_path")
However, tomcat still errors out, saying that $full_footer_path is not defined.
When I hard-code the value of $full_templates_path into #parse statement in custom_layout_1.tpl, everything works fine, but that seems like a hack to me.
Ideally, this should do the right thing for the right reasons, not just because I used a lot of duct tape.
Any suggestions for ways to implement the inclusion of a template file from within a custom page layout?
The issue could be due to your velocity configuration.
The following property should be false velocimacro.permissions.allow.inline.local.scope if you want to access variables set in one template to be accessible in another
You may have miss-typed your question but shouldn't #set($full_footer_path = "$full_templates_path/footer.vm" have a close bracket at the end...
#set( $full_footer_path = "$full_templates_path/footer.vm" )
It might also help to wrap $full_templates_path in curly braces to distinguish it from the rest of the text i.e ${full_templates_path}
I have a page I'd like to embed a news-feed widget into (so that the feed from some remote site will be displayed in my site).
While there are quite a few free news-feed widgets available out there (a partial list is here: http://allwebco-templates.com/support/S_script_newsfeed.htm), They all require insertion of complex code into the html page, while all the parameters are hard-coded into the generated code, which looks something like this:
insertedWidgetText = "<script id=\"scrnewsblock10795953\" type=\"text/javascript\">...script specific parameters go here...</script>"
let feedWidget = toWidgetBody [hamlet|#{preEscapedText insertedWidgetText}|]
This doesn't integrate well with Yesod's approach as it requires specifying to Hamlet that the content is preEscapedText, which in turn disables the ability to use Hamlet's processing to alter parameters of the widget dynamically (So in case I want the widget to use a different source, for example, I need to statically change the quoted text and cannot use Hamlet's variable substitution).
Of course I could do some text manipulation myself, tailor built for the widget I'm using, but that doesn't seem like the "right" solution (especially if I want to have the embedded text in some external file and not in the middle of my code as in the example above).
Can the above mentioned issue have a better solution than the one I thought about?
Is there an implementation of a news-feed widget in Haskell/Yesod that I can use as a plugin?
Note: I'm a very poor javascript programmer, but solutions in that direction are also welcomed.
Thanks,
I'm trying to create a Custom Part that just drops text into the page. I've created a part using the GUI that I called "Side Feature" and I added a text field called "Featured". I am trying put it on the side bar which I created on my layout, but I don't know how to move it to the sidebar. It shows up on my main content.
How do I move it to the sidebar? I tried using "#Display(Model.Featured)", but that doesn't seem to work. I also read about the placement.info file, but I'm not too sure how that would work in this sense.
I couldn't find a tutorial/blog post online similar to this. Most of them were too advanced. I am very new to Orchard.
You can't without code or additional module: sidebar is a zone for widgets, not for content parts. Placement info only works for local zones within the global Content zone.
If you want to do it through code, follow this: http://weblogs.asp.net/bleroy/archive/2011/03/26/dispatching-orchard-shapes-to-arbitrary-zones.aspx
If you want to use a module, look for Origami on the gallery.
How to capture the Whole web page when using QTP?
I am aware of 'CaptureBitmap' method for the screenshot. But how to capture the Whole page? Help !!
What do you want to capture? If it's the HTML you can create a checkpoint on the Page test object and check the HTML source checkbox in the HTML verification section.
If you want to capture an image of the page then you can only capture the visible part with CaptureBitmap there is no way to get an image of the scrolled out parts (unless you scroll and use multiple captures).
Use Browser("").Capturebitmap.
This takes the screenshot of the visible browser.
Use the sendkeys method to do a page down, then use Browser("").Capturebitmap again!
A full screen shot can be taken by toggling QTP's run settings rather than using CaptureBitmap. We can tell QTP to always take screen shots, interact with the page (or object) we wish to capture (e.g. call .Exist(0)) and this will feed a screen shot in to the results.
The code to do this:
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Options.Run.ImageCaptureForTestResults = "Always"
Browser("index:=0").Page("index:=0").sync
App.Options.Run.ImageCaptureForTestResults = "OnError"
Technically this seems to be capturing the html and then presenting this to the user in the run results, rather than an actual image of the browser's presentation of the html. But still, this means we can see what's on the page but not visible.
I have went through lot of surfing but couldn't get right answer or I coudn't implement what I found due to restriction of using third party APIs in my office. By using dot net factory, we can use dot net libraries to take screen shots and merge them. refer the below page for complete code
http://www.testbasket.com/2015/08/capture-whole-web-page-using-uftqtp.html
However here i have pasted the contents from the page and hope it helps.
In order to do take the screenshot of complete page, I have used DotNetFactory and System.Drawing dot net library.
Lets go step by step to the solution,
As part of implementing the solution, we need to get the height and weight of the entire page. In order to get that we using DOM of a page using .object method.
#Get the Full Height of Page
FullHeight = Browser("Wikipedia, the free encycloped").Object.document.body.scrollheight
#Get the Full width of Page
Fullwidth = Browser("Wikipedia, the free encycloped").Object.document.body.scrollwidth
Once we found the complete page size, we need to find the client size (how much browser can show)
#Get the visible height - Viewable part of the page
BrowserHeight = Browser("Wikipedia, the free encycloped").Object.document.body.clientHeight
#Get the visible width - Viewable part of the page
Browserwidth = Browser("Wikipedia, the free encycloped").Object.document.body.clientwidth
Next we need to import required dot net libraries using Dot Net Factory
Set oGraphics=DotNetFactory.CreateInstance("System.Drawing.Graphics")
Set oPoint=DotNetFactory.CreateInstance("System.Drawing.Point")
Set oImgFormat=DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat","System.Drawing", Nothing)
Set oImageLib = DotNetFactory.CreateInstance("System.Drawing.Image")
Set oPens=DotNetFactory.CreateInstance("System.Drawing.Pens","System.Drawing")
As a final step, we need to loop through the page and take screenprints separately. finally using Dotnet library we will merge the images using graphics. draw method. It is easy to implement, complete set of code is available in the above mentioned link for reference
If you would like a single screenshot of the whole page, try using SnagIt.
There's a handy PDF with more info on how to go about it (http://download.techsmith.com/snagit/docs/comserver/enu/snagitcom.pdf)
In QTP it might look like this:
Sub Capture_Scroll_Image ()
Set objShell = CreateObject("WScript.Shell")
Set oSnag = CreateObject("SNAGIT.ImageCapture")
oSnag.IncludeCursor = False
oSnag.OutputImageFile.FileType = 5
oSnag.OutputImageFile.FileNamingMethod = 1
oSnag.OutputImageFile.Directory = "C:\Screens\"
oSnag.OutputImageFile.Filename = "Name"
oSnag.EnablePreviewWindow = False
oSnag.AutoScrollOptions.AutoScrollMethod= 1
oSnag.Capture()
Wait (1)
objShell.SendKeys "{ENTER}"
capDone = oSnag.IsCaptureDone
Do Until oSnag.IsCaptureDone
Loop
Set oSnag=Nothing
Set objShell=NothingEnd Sub
End Sub