Eclipse plugin development AndroidXmlFormatter - eclipse

I am building an eclipse plugin which modifies an android XML(layout) file. I use a dom parser internally to produce the output XML. However the XML formatting is messed up.
I want to use the android xml-formatting mechanism. I tried this -
//xmlFile is a IFile
IDocumentProvider provider = new TextFileDocumentProvider(); provider.connect(xmlFile);
IDocument document = provider.getDocument(xmlFile);
xmlFile.setContents(inputStream, IFile.ENCODING_UTF_8, new NullProgressMonitor());
AndroidXmlFormatter a=new AndroidXmlFormatter();
IFormattingContext context=new FormattingContext();
context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
a.format(document, context);
But, the document isn't formatted. :(
What could be the problem? Are there alternatives for my problem?

Still did not find a definitive answer. As far as formatting goes, I used package com.android.ide.eclipse.adt.internal.editors.formatting to format xml default android-style.
XmlFormatPreferences xfp=XmlFormatPreferences.create();
xfp.joinLines=true;
xfp.removeEmptyLines=true;
xfp.useEclipseIndent=true;
return XmlPrettyPrinter.prettyPrint(xmlAsWriter.toString(), xfp, XmlFormatStyle.FILE, "\n");

Related

Changing jasper report parameters in runtime

I know, but we really need it.
We have a clear division of labor.
They create templates, I fill them in runtime according to some rules.
Can't teach my business to insert something like this and be sure they really did it ok(so can't move any logic to templates):
$P{risk_types}.get($F{risk_type}) ?: "UNDEFINED"
Also can not fill from files hardcoded in some adapter hadwritten by god-knows-who and unchangeable in runtime. It's a web app. Best option is to find a way to replace that file source from adapter to a ByteArrayStream.
SO:
Need to substitute contents of parameters(also default ones) at runtime.
example:
need to set JSON_INPUT_STREAM
Like this unsolved thread.
https://community.jaspersoft.com/questions/516611/changing-parameter-scriptlet
Really hope not to work on xml level, but xml also can't solve my problem as far as I tried.
Thank you!
The easiest and cleanest way we did this(bypassing usage of tons of deprecated documentation and unfinished bugged undocumented static antipatterned new features):
Create context with repository extension
SimpleJasperReportsContext jasperReportsContext = new SimpleJasperReportsContext();
jasperReportsContext.setExtensions(RepositoryService.class, Collections.singletonList(new MyRepositoryService(jasperReportsContext, yourOptionalParams)));
Fill this way(after compile and other usual actions)
JasperPrint print = JasperFillManager.getInstance(jasperReportsContext).fill(compiled, new HashMap<>());
Now your repository must extend default one to be hack-injected(cause of hodgie coded "isAssignableFrom") successfully
public class PrintFormsRepositoryService extends DefaultRepositoryService {
#Override
public InputStream getInputStream(RepositoryContext context, String uri) {
// return here your own good simple poj inputStream even from memory if you found source
// or pass to another repository service(default one probably)
return null;
}
}

How to add templates.xml using plugin?

Editor templates in eclipse can be imported from xml file. Instead of manually importing, wanted to create a plugin. Which will import the templates.xml kept in specified folder at start of the eclipse.
How this can be achieved?
You can use the JFace org.eclipse.jface.text.templates.persistence.TemplateReaderWriter to read a template.xml. Something like:
File file = .... file to read
TemplateReaderWriter reader = new TemplateReaderWriter();
InputStream input = new BufferedInputStream(new FileInputStream(file));
TemplatePersistenceData[] datas = reader.read(input, null);
(code to deal with errors and closing the input left out)
You can then put the data in a TemplateStore:
TemplateStore fTemplateStore = ... store to use
for (TemplatePersistenceData data: datas) {
fTemplateStore.add(data);
}
fTemplateStore.save();
The template store you use depends on which templates you are updating.
For the Java Editor template store you can get the store with
JavaPlugin.getDefault().getTemplateStore();
But the JavaPlugin is not part of the official Eclipse API.
The above code is a simplified version of the import code in org.eclipse.ui.texteditor.templates.TemplatePreferencePage

Xpages PDF creation using the XMLWorker class

Using SSJS I've successfully created a PDF using the simple HTML parser that comes with iText but the simple HTML parser doesn't respect CSS and is very limited. I downloaded the XMLWorker class from the iText site and have tried to use that instead but my knowledge of working out how to call Java packages is too limited. All the examples I can find use Java and refer to the classes directly, eg.
Document newPDF = new Document();
But in SSJS we have to use dot notation, eg.
var newPDF:com.itextpdf.text.Document = new com.itextpdf.text.Document();
This - I think - is where I stumble. My code looks like this:
function createLPO2(pReqDoc:NotesDocument) {
importPackage(com.itextpdf);
//importPackage(com.itextpdf.tool.xml.XMLWorkerHelper);
importPackage(java.io);
var con = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();
response.setContentType("application/pdf");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setHeader("Content-Disposition","attachment; filename=\"LPO_" + pReqDoc.getItemValueString("RequisitionNo") + ".pdf\"");
var newPDF:com.itextpdf.text.Document = new com.itextpdf.text.Document();
var writer = com.itextpdf.text.pdf.PdfWriter.getInstance(newPDF,response.getOutputStream());
var xmlWorkerHelper = com.itextpdf.tool.xml.XMLWorkerHelper.getInstance();
var strHTML = getTestHTML(); //this is the HTML used in the examples on the iText site
xmlWorkerHelper.parseXHtml(writer, newPDF, new java.io.StringReader(strHTML));
newPDF.close();
writer.close();
facesContext.responseComplete();
}
If I run this script as it is I get a script error on the Domino console. If I remove the comment on the line importPackage(com.itextpdf.tool.xml.XMLWorkerHelper); it gives a completely different error. I suspect I have to import the XMLWorkerHelper package and not just the com.itextpdf package. I thought if I opened the jar file using a tool like 7-zip I could work out the path, which is how I arrived at com.itextpdf.tool.xml.XMLWorkerHelper
Is this right? If so, why does my script fail?
Rob,
seriously, don't try to do that in SSJS. iText is all Java, if you try to mangle with it in a different language it will stress you out. Create a wrapper class that has a method that takes an OutputStream and whatever data (Document, View etc) you need. Obtain the OutputStream in your SSJS and call the function. Look for the XAgent XSnippet on OpenNTF and my blog series (the last two are missing - bear with me) on PDF creation.
One word of caution: iText is GPL, so you either GPL your software too, buy a commercial iText license or look for alternatives like Apache PDFBox or Apache FOP. Ah the second caution: HTML to PDF is a Pita. You could look at a commercial tool like e.g. from Swing software (or change your approach)

Does GWT have richtextbox which show RTF type data?

I'm using GWT Richtextbox, But this widget shows values which are simple text or HTML formatted.
Is there any way to show RTF data in a GWT-Richtext or GWT-htmlEditor widget? Or is there a widget in other GWT libraries which will do this?
I don't think so. About year ago we wanted to develop rtf browser on client side and we failed.
There is no GWT-Rtf libraries. You could try to find something written in javascript and then wrap it with JSNI, but I haven't seen such library as well. Someone told me that it might be possible with Activex, but we haven't even tried this method.
What are you trying to achieve? If you want to share documents with an RTF editor like, say, Microsoft Word, you should check to see if that editor can also work with HTML. I know that MS Word can edit HTML.
Alternatively, you might consider transposing RTF into HTML and back again on the server side. There are several Java libraries out there for doing that, and I believe that Flying Saucer is one of them.
You could use RTFEditorKit in combination with HTMLEditorKit to convert between the two server-side or in an applet. This way you can use GWT's rich text editor and output or input RTF.
public static String getHtmlFromRtf(InputStream fi){
Writer sOut = new StringWriter();
DefaultStyledDocument doc = new DefaultStyledDocument();
HTMLEditorKit htmlKit = new HTMLEditorKit();
RTFEditorKit rtf = new RTFEditorKit();
try
{
rtf.read( fi, doc, 0 );
htmlKit.write(sOut, doc, 0, doc.getLength());
}
catch (IOException e)
{
e.printStackTrace();
}
catch (BadLocationException e)
{
e.printStackTrace();
}
return sOut.toString();
}

GEF - How to open Editor in Composite?

My name is Oleg, I'm writing advanced feature - visual comparison of BPEL files.
I would like to use regular editors in "compare" panes (left and right)
As a first step I just want to open two editors (one for each file)
Later I can 'hack' them a little, make new parts green,
deleted parts red etc...
So my problem sounds pretty simple
I have:
- Composite
- Resource which describes .bpel file
And I gotta to open default editor for this Resource in this Composite.
I would appreciate any tips or suggestions!
What did I tried:
I've spent couple days trying to deeper understand GEF,
but after all I didn't found any simple solution for my
simple problem.
People from another project used:
org.eclipse.gmf.runtime.notation.Diagram
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer
diagramGraphicalViewer.setContents(diagram)
but my editor is GEF-based, not GMF-based.
As far as I understood I can't just open editor in composite
I have to use a lot of "extra" stuff - EditorManager,
Workbrenchs, some sites etc. etc.
After all I wrote some straightforward code but it doesn't
work. Likely I wrote it in absolutely wrong way, but let
me quote it just to make clear what do I actually need.
File file2open = new File(new Path("/p1/name2.bpel"), (Workspace) BPELPlugin.getPlugin().getWorkspace()) { };
BPELMultipageEditorPart editorPart = new BPELMultipageEditorPart();
FileEditorInput editorInput = new FileEditorInput(file2open);
EditorDescriptor editorDescriptor = null;
try {
editorDescriptor = (EditorDescriptor)IDE.getEditorDescriptor(file2open);
} catch (PartInitException e) {
e.printStackTrace();
}
WorkbenchPage workbrenchpage = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
EditorSite editorSite = new EditorSite(new EditorReference(workbrenchpage.getEditorManager(), editorInput, editorDescriptor), editorPart, workbrenchpage, editorDescriptor);
try {
editorPart.init(editorSite, editorInput);
} catch (PartInitException e) {
e.printStackTrace();
}
editorPart.createPartControl(mycomposite);
upd: finally I've implemented what I wanted, but not sure if someone else is interested :)
No, there's no good way to open editor in GEF viewer. Keep in mind:
1. "Editor" is Eclipse platform concept. I.e. it is not just a widget but a whole infrastructure. As you said - you would need IEditorSite and so on.
2. GEF figures are "lightweight". You whole GraphicalViewer is a single SWT widget and figures are drawn on it - they don't have OS widgets backing them.
So if you really need to nest an editor in GEF viewer you would have to place the SWT composite on top of viewer and manage its placement.
result of my work http://www.picamatic.com/view/3436443_bpelcompare/ source code: http://dl.dropbox.com/u/49126809/org.eclipse.emf.compare.ui.gef.zip