use of net.heartsome.xml.Document in project translationstudio8 by heartsome.
the class AutoConfiguration method run.
/**
* Run.
* @param input
* the input
* @param out
* the out
* @param catalogue
* the catalogue
* @throws SAXException
* the SAX exception
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ParserConfigurationException
* the parser configuration exception
*/
public void run(String input, String out, String catalogue) throws SAXException, IOException, ParserConfigurationException {
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new Catalogue(catalogue));
Document d = builder.build(input);
Element r = d.getRootElement();
segment = new Hashtable<String, String>();
recurse(r);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Document doc = new Document(null, "ini-file", "-//HEARTSOME//Converters 2.0.0//EN", "configuration.dtd");
Element root = doc.getRootElement();
Enumeration<String> keys = segment.keys();
while (keys.hasMoreElements()) {
//$NON-NLS-1$
Element e = new Element("tag", doc);
String key = keys.nextElement();
e.setText(key);
//$NON-NLS-1$ //$NON-NLS-2$
e.setAttribute("hard-break", "segment");
root.addContent(e);
//$NON-NLS-1$
root.addContent("\n");
}
XMLOutputter outputter = new XMLOutputter();
FileOutputStream output = new FileOutputStream(out);
outputter.output(doc, output);
output.close();
}
use of net.heartsome.xml.Document in project translationstudio8 by heartsome.
the class PluginHelpDialog method loadToc.
private void loadToc(TreeItem itemParent, String tocFile) throws Exception {
File file = new File(tocFile);
String basePath = "";
if (file.exists()) {
basePath = file.getParent();
}
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new Catalogue(PluginUtil.getCataloguePath()));
Document document = builder.build(tocFile);
Element root = document.getRootElement();
recurseTree(root, itemParent, basePath);
String url = root.getAttributeValue("url");
if (!url.equals("")) {
File f = new File(url);
if (!f.exists()) {
url = basePath + "/" + url;
}
hashTable.put(itemParent, new File(url).toURI().toURL().toString());
}
}
use of net.heartsome.xml.Document in project translationstudio8 by heartsome.
the class PluginHelpDialog method searchFile.
private void searchFile(String file, String text, boolean sensitive) throws SAXException, IOException, ParserConfigurationException {
SAXBuilder builder = new SAXBuilder();
//$NON-NLS-1$
builder.setEntityResolver(new Catalogue(PluginUtil.getCataloguePath()));
if (!file.startsWith("file:")) {
//$NON-NLS-1$
if (!file.startsWith("http:")) {
//$NON-NLS-1$
File f = new File(file);
file = f.toURI().toURL().toString();
}
}
URL url = new URL(file);
Document doc = builder.build(url);
Element root = doc.getRootElement();
searchElement(root, file, text, sensitive);
}
use of net.heartsome.xml.Document in project translationstudio8 by heartsome.
the class TBXTemplateUtil method getTemplateFiles.
public static Vector<String> getTemplateFiles(String catalogueFile, String templatePath, boolean needArray) {
Vector<String> result = new Vector<String>();
File templateDir = new File(templatePath);
String[] contents = templateDir.list();
if (contents != null) {
for (int i = 0; i < contents.length; i++) {
File currentFile = new File(templateDir.getAbsolutePath(), contents[i]);
if (currentFile.isFile()) {
try {
SAXBuilder builder = new SAXBuilder();
if (!catalogueFile.equals("")) {
//$NON-NLS-1$
Catalogue cat = new Catalogue(catalogueFile);
builder.setEntityResolver(cat);
}
Document doc = builder.build(currentFile.getAbsolutePath());
Element tbxXCS = doc.getRootElement();
//$NON-NLS-1$
Element datCatSet = tbxXCS.getChild("datCatSet");
if (datCatSet != null) {
result.add(currentFile.getName());
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
}
return result;
}
use of net.heartsome.xml.Document in project translationstudio8 by heartsome.
the class PluginHelpDialog method loadTree.
private void loadTree(String helpFile) {
try {
tree.removeAll();
hashTable.clear();
File file = new File(helpFile);
String basePath = "";
if (!file.isAbsolute()) {
helpFile = file.getCanonicalPath();
file = new File(helpFile);
}
basePath = file.getParent();
currentFilePath = helpFile;
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new Catalogue(PluginUtil.getCataloguePath()));
Document document = builder.build(helpFile);
Element root = document.getRootElement();
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText(root.getAttributeValue("title"));
getShell().setText(root.getAttributeValue("title"));
recurseTree(root, item, basePath);
item.setExpanded(true);
String url = root.getAttributeValue("url");
if (!url.equals("")) {
File f = new File(url);
if (!f.exists()) {
url = basePath + "/" + url;
}
browser.setUrl(new File(url).toURI().toURL().toString());
hashTable.put(item, url);
}
} catch (Exception e) {
}
}
Aggregations