Get the tileset file names for TMXTiledMap - iphone

What's the best way to retrieve an array containing the file names of the files used to load a certain CCTMXTiledMap ? I need to get the tileset file names because I want to dispose of them personally from the Cache in a future.

According to the documentation and declaration of CCTMXTiledMap, you'll want to walk the property NSMutableArray* objectGroups. Otherwise, you'll need to maintain your own data structure.
This thread contains robust documentation and examples that should help you.

Open the tmx file, it is an xml file, and search for
it has a tag with a source attribute.
<tileset firstgid="1" name="sewer_tileset" tilewidth="24"
tileheight="24"> <image source="sewer_tileset.png" trans="ff00ff"
width="192" height="217"/> </tileset>
you can parse the xml and just find all tileset->images.
You will need an xml parser if you want to do it on the phone, here is a good tutorial on that :http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project

Related

manipulating Microsoft Word DOCX files that have links and track changes using Python

I have been using the excellent python-docx package to read, modify, and write Microsoft Word files. The package supports extracting the text from each paragraph. It also allows accessing a paragraph a "run" at a time, where the run is a set of characters that have the same font information. Unfortunately, when you access a paragraph by runs, you lose the links, because the package does not support links. The package also does not support accessing change tracking information.
My problem is that I need to access change tracking information. Or, more specifically, I need to copy paragraphs that have change tracking indicated from one document to another.
I've tried doing this at the XML level. For example, this code snippet appends the contents of file1.docx to file2.docx:
from docx import Document
doc1 = Document("file1.docx")
doc2 = Document("file2.docx")
doc2.element.body.append(doc1.element.body)
doc2.save("file2-appended.docx")
When I try to open the file on my Mac for complicated files, I get this error:
But if I click OK, the contents are there. The manipulation also works without problem for very simple files.
What am I missing?
The .element attribute is really an "internal" interface and should be named ._element. In most other places I have named it that. What you're getting there is the root element of the document part. You can see what it is by calling:
print(doc2.element.xml)
That element has one and only one w:body element below it, which is what you get when with doc2.element.body (.xml will work on that too, btw, if you want to inspect that element).
What your code is doing is appending one body element at the end of another w:body element and thereby forming invalid XML. The WordprocessingML vocabulary is quite strict about what element can follow another and how many and so forth. The only surprise for me is that it actually sometimes works for you, I take it :)
If you want to manipulate the XML directly, which is what the ._element attribute is there for, you need to do it carefully, in view of the (complex) WordprocessingML XML Schema.
Unlike when you stick to the published API, there's no safety net once ._element (or .element) appears in your code.
Inside the body XML can be relationships to external document parts, like images and hyperlinks. These will only be valid within the document in which they appear. This might explain why some files can be repaired.

How to create pathfield generically so that it handles all extensions in cq5

When we take a pathfield value in jsp, need to provide harcoded ".html" or ".pdf".
Is there any way to make pathfield generic, hence no need to provide hard coded extensions? So if a user selects .pdf it will display a pdf file and if user selects .html it will open a html file.
Not sure if there is a OOB way to do this. Alternatively, You can create a script/custom jstl tag which take path as input, load resource and find out resource type and generate path with correct extn as output.
Call this script from all your components which generate links.
Another option is you extend com.day.cq.rewriter.pipeline.RequestRewriter and in rewriteLink() function write your logic to set correct extn.

MS Word, DOCX, Open XML - Apply themes by changing XMLs

Need to apply theme from one word document (DOCX) to another via manipulating the XMLs.
The road I'm going through is -
word/themes folder contains at least one theme#.xml and could have the rels folder containg relationship files. I decided not to touch the rels folder and copy all theme#.xmls (as could be more than one) present in word/theme folder. This is working for me.
I have two concerns over it:
1. Do I need to add theme1.xml.rels file present in word\theme_rels as well? It contains mapping to one image in word\media folder. Do I need to add the image mapping too?
2. For few themes such as "Quotable", the theme1.xml contains one reference in 'a:fmtScheme' node to relationship id, probably for DrawingML and shapes.
for ex:
<a:blipFill rotWithShape="1">
<a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1">
As the "rId1" here refers to styles.xml and maintained in word_rels\document.xml.rels, my concern is the word_rels\document.xml.rels mapping to styles.xml could not be rId1 in the document to which theme is getting applied (for instance this could be rId5 for styles.xml). So, Do I need to change this in theme1.xml while copying to work it properly.
Any help would be greatly appreciated.
If this XML appears in theme1.xml, 'rId1' is a key in theme1.xml.rels, not the document.xml.rels. The relationship ids (rId#) are unique within a 'source' XML document but are not unique within the overall package (.docx file).
Since this one is a <a:blip> element, the relationship will be to an image part, e.g. image1.jpg. I suspect this one is a large-ish quotation mark image that appears in front of a pull-out quote.
If you want it to show up properly, you'll want to make sure those relationships and their target parts are reconstructed in your target package. That would mean "yes", you would want to add the theme1.xml.rels file in the right place, as well as the image file it refers to.

Possibility of more then one xml input to jet?

Can we give more then one xml input to jet(java emitter template)?
If we can, then please give me an example.
You can't do it directly, but there are several techniques you can use to specify multiple XML's as input.
You can name one XML file inside the other or create a third XML file that simply names the two inputs (or however many you have). Say you have an XML file named in the input XML to JET:
<inputs>
<input name="...full file name here..." />
<inputs>
You can load this file in for use in JET like this:
<c:load url="{/inputs/input/#name}" var="root"/>
The load tag reads a file (defaults to XML, but other types can be input.) and makes its contents available via the variable name you specify ("root" in this case). Normally the url attribute expects a String value that is the file name, but since we're using an attribute out of the model we use the curly brackets and xpath notation to indicate the attribute value to use as the file name.
Once you've loaded the file in you can access its contents. For example, if the root element in that XML file was and it had an attribute named company, then you attribute could access that attribute value with the c:get
<c:get select="$root/policies/#company" />
You can load as many files as you want. Just use a different variable name to refer to the root of each parsed file.
You could get a bit more complex and store your multiple files in the same directory using a naming convention. Then you could just specify the one directory path and derive the file names for all of your inputs.

how to add new element to the existing node in xml

i have an xml file like this.
<?xml version="1.0" encoding="UTF-8"?>
<imageset>
<category>
<image>SQUIRREL</image>
<image>FOX</image>
<image>TIGER</image>
<image>LION</image>
</category>
</imageset>
Now i need to add another elemnt to the parent node imageset like this.
eg: i need to add <image>DOG</image>
SQUIRREL
FOX
TIGER
LION
DOG
i know that to get elements by node wise we need to use xml parse.
But i don't know to write element to the same xml file.
How can i done can any one please help me.
Thank u in advance.
If you are on iPhone you can use either a SAX parser called The "NSXMLParser" class
or you can use a DOM parser Like NSXML for this one You want to use DOM Like NSXML since you want to edit the file. On iPhone they Took NSXMLDocument out due to it being too resource intensive. Use something like either "Kiss XML" or "Touch Base XML".
If you are not familier with parsing XML its really simple and easy I suggest since you are on the iPhone use the ADC Documentation here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html
Its a great tutorial!