How to convert from XslTransform of VS2003 to XslCompiledTransform of VS2005? - visual-studio-2005

We are currently converting our project from VS2003 to VS2005 and I'm looking for the right way to convert the code using XslTransform to XslCompiledTransform.
The changing the class name is not the big deal, but when it comes to using
XslCompiledTransform's Transform method, I have a problem.
Before XslTransform's Transform method was accepting XPathDocument object and right now Transfrom method expect XmlReader instead:
Here is the code:
XslCompiledTransform xslt = new XslCompiledTransform();
XPathDocument doc = new XPathDocument(new StringReader(DS.GetXml().ToString()));
StringWriter sw = new StringWriter();
xslt.Transform(doc,null,sw,null);
Also, new Transform method expect System.Xml.XmlWriter instead of System.IO.StringWriter.
What is the best way to fix that?
Thank you

The following link describes the differences between the XslCompiledTransform and the XslTransform classes.
A section has also some code samples in both versions.

Related

How to configure vscode to create final var instead of class name for Java when assign statement to new local variable is triggered

I'm new with VSCode in Java. My request is pretty simple, with Intellij when it assigns method result to new local variable it generates final var myVariable such as follow :
final var employee = new Employee();
but in VSCode when I use the shortcut it generates
Employee employee = new Employee();
Is there any way to generate the same template as Intellij ?
Thanks for your help ;)
Currently AFAIK, it's not supported to add final modifier when extracting to a local variable.
But as a workaround, maybe you can try the source action: Change modifiers to final where possible.
You can find it in the source actions (in right-click context menu)

Map().set() does not add element in Collection, using NativeScript

I recently have had a problem when coding using NativeScript.
I tried using Map() object as a Collection, but its set() method seems not to work.
I use the following snippet :
var r = new Map();
r.set("one", "two");
console.dir(r);
It however outputs an empty Map(), and I do not know why...
For your convenience, here is a link to a NativeScript PlayGround: https://play.nativescript.org/?template=play-ng&id=evhIxX&v=2
I inserted the snippet inside home.components.ts
Thanks alot!
LMy
Actually it works, if you try r.get("one") then you will see two in console.
May be console.dir does not handle Map as expected. You may report that in the GitHub project.

Xpath Part NULL, with xpaths set via content control toolkit

I've been able to set, via code, the xpaths for the placeholders found in the document.
for (Object o : finderSdtRun.results) {
if (o instanceof SdtRun){
SdtPr sdtPr=((SdtRun) o).getSdtPr();
Tag t = sdtPr.getTag();
CTDataBinding ctDataBinding = Context.getWmlObjectFactory().createCTDataBinding();
//JAXBElement jaxbDB = Context.getWmlObjectFactory().createSdtPrDataBinding(ctDataBinding);
sdtPr.setDataBinding(ctDataBinding);
ctDataBinding.setXpath("tuttappostaferragost");
ctDataBinding.setStoreItemID("something");
ObjectFactory factory = new org.opendope.xpaths.ObjectFactory();
DataBinding db = factory.createXpathsXpathDataBinding();
db.setXpath("tuttappostaferragost");
db.setStoreItemID("something");
Xpaths.Xpath xp = factory.createXpathsXpath();
xp.setDataBinding(db);
xp.setId("something");
try {
wordMLPackage.getMainDocumentPart().getXPathsPart().getContents().getXpath().add(xp);
} catch (Docx4JException e) {
e.printStackTrace();
}
;
The problem is that, once set, they are not recognized by word, so I thought to add the created Xpaths to a new XpathPart, and then add it to the main Document part.
But I failed because the method:
wordMLPackage.getMainDocumentPart().getXPathsPart()
returns null. This sounded reasonable, since only content control was set, without any Xpath.
Then I set the Xpaths via content control toolkit and the same line of code like above, returned me null, which added a lot of confusion in my yet confused ideas.
Is there any way to tell the document that new Xpath have been added to the document?
I mean, if there is a way to add Xpath via code (the w:databinding w:storedItemId tags), why it is not possible to make it work?
In general I want to add Xpath and all information necessary, via code, avoiding the use of any toolkit.
Thank you :D
First, you have to decide whether you want plain old Word databinding, or the additional OpenDoPE capabilities (which use the content control tag to support repeats, conditionals etc).
You only need an XPaths part if you are using the OpenDoPE extensions.
I'll assume for now that you are just looking to do basic Word content control databinding.
To set that up programmatically, you need to add a custom xml part, and a rel from it to its itemProps.xml part, which contains something like:
<ds:datastoreItem ds:itemID="{5448916C-134B-45E6-B8FE-88CC1FFC17C3}" xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml">
<ds:schemaRefs/>
</ds:datastoreItem>
(to add a part B to part A, use partA.addTargetPart)
You can see it is this part with gives the custom xml part its itemID; this corresponds with the value you set in:
DataBinding db = factory.createXpathsXpathDataBinding();
db.setStoreItemID("something");
Then, set the XPath via the method you were using.

Save image (via ImageWriter / FileImageOutputStream) to the filesystem without use of a File object

As a learning task I am converting my software I use every day to NIO, with the somewhat arbitrary objective of having zero remaining instances of java.io.File.
I have been successful in every case except one. It seems an ImageWriter can only write to a FileImageOutputStream which requires a java.io.File.
Path path = Paths.get(inputFileName);
InputStream is = Files.newInputStream(path, StandardOpenOption.READ);
BufferedImage bi = ImageIO.read(is);
...
Iterator<ImageWriter> iter = ImageIO.getImageWritersBySuffix("jpg");
ImageWriter writer = iter.next();
ImageWriteParam param = writer.getDefaultWriteParam();
File outputFile = new File(outputFileName);
ImageOutputStream ios = new FileImageOutputStream(outputFile);
IIOImage iioi = new IIOImage(bi, null, null);
writer.setOutput(ios);
writer.write(null, iioi, param);
...
Is there a way to do this with a java.nio.file.Path? The java 8 api doc for ImageWriter only mentions FileImageOutputStream.
I understand there might only be a symbolic value to doing this, but I was under the impression that NIO is intended to provide a complete alternative to java.io.File.
A RandomAccessFile, constructed with just a String for a filename, can be supplied to the ImageOutputStream constructor constructor.
This doesn't "use NIO" any more than just using the File in the first place, but it doesn't require File to be used directly..
For direct support of Path (or to "use NIO"), the FileImageOutputStream (or RandomAccessFile) could be extended, or a type deriving from the ImageOutputStream interface created, but .. how much work is it worth?
The intended way to instantiate an ImageInputStream or ImageOutputStream in the javax.imageio API, is through the ImageIO.createImageInputStream() and ImageIO.createImageOutputStream() methods.
You will see that both these methods take Object as its parameter. Internally, ImageIO will use a service lookup mechanism, and delegate the creation to a provider able to create a stream based on the parameter. By default, there are providers for File, RandomAccessFile and InputStream.
But the mechanism is extendable. See the API doc for the javax.imageio.spi package for a starting point. If you like, you can create a provider that takes a java.nio.Path and creates a FileImageOutputStream based on it, or alternatively create your own implementation using some more fancy NIO backing (ie. SeekableByteChannel).
Here's source code for a sample provider and stream I created to read images from a byte array, that you could use as a starting point.
(Of course, I have to agree with #user2864740's thoughts on the cost/benefit of doing this, but as you are doing this for the sake of learning, it might make sense.)

Create a solution and add a project using "VisualStudio.DTE.10.0"

I'm trying to create a VS2010 solution and add a project from a stand-alone app (not an add-in). I can create an instance of VS2010, but I'm not able to determine how to create a project properly...I can only find an example of how to create a project using the EnvDTE80 object, which later causes an exception because the project file is in an earlier format and needs to be upgraded. I have this:
EnvDTE80.DTE2 dte2;
object obj;
System.Type t;
t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);
obj = System.Activator.CreateInstance(t, true);
dte2 = (EnvDTE80.DTE2)obj;
What I'm looking for is the equivalent of something like "EnvDTE100.DTE2" but don't know how to get there.
Thanks
You do not have to go via DTE object. The treatment to the object solution4 it's different you should do this
Type latestSolution = Type.GetTypeFromProgID("VisualStudio.10.0", true);
EnvDTE100.Solution4 vsSolution = (EnvDTE100.Solution4)Activator.CreateInstance(latestSolution, true);
I think I'm doing something similar, I have a application that creates a solution and loads two projects from templates that I created in VS2010. You're right in that it seems everything still uses the EnvDTE80, even in VS2010, but then we use it to create a 2010 solution:
System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
Object obj = System.Activator.CreateInstance(type, true);
EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)obj;
EnvDTE100.Solution4 soln = (EnvDTE100.Solution4)dte2.Solution;
Then you can call methods on the soln object to create your project (in my case its AddFromTemplate).

Resources