use of net.heartsome.xml.SAXBuilder 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.SAXBuilder 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.SAXBuilder 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.SAXBuilder in project translationstudio8 by heartsome.
the class ReverseConversionValidateWithLibrary3 method readXliff.
/**
* @param xliff
* xliff 文件的路径
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
*/
private void readXliff(String xliff) throws SAXException, IOException, ParserConfigurationException {
builder = new SAXBuilder();
builder.setEntityResolver(new Catalogue(ConverterContext.catalogue));
doc = builder.build(xliff);
root = doc.getRootElement();
//$NON-NLS-1$
Element file = root.getChild("file");
//$NON-NLS-1$
dataType = file.getAttributeValue("datatype");
//$NON-NLS-1$ //$NON-NLS-2$
targetLanguage = file.getAttributeValue("target-language", Messages.getString("model.ReverseConversionValidateWithLibrary3.msg4"));
}
use of net.heartsome.xml.SAXBuilder in project translationstudio8 by heartsome.
the class TBXTemplateUtil method loadTemplate.
private void loadTemplate(String catalogueFile) throws SAXException, ParserConfigurationException, IOException {
SAXBuilder builder = new SAXBuilder();
if (!catalogueFile.equals("")) {
//$NON-NLS-1$
Catalogue cat = new Catalogue(catalogueFile);
builder.setEntityResolver(cat);
builder.setValidating(true);
}
//$NON-NLS-1$
File templateFile = new File(templatePath, templateFileName);
document = builder.build(templateFile.getAbsolutePath());
Element tbxXCS = document.getRootElement();
//$NON-NLS-1$
Element datCatSet = tbxXCS.getChild("datCatSet");
if (datCatSet != null) {
List<Element> specs = datCatSet.getChildren();
Iterator<Element> specsIt = specs.iterator();
while (specsIt.hasNext()) {
Element spec = specsIt.next();
//$NON-NLS-1$
Element contents = spec.getChild("contents");
if (contents != null) {
items.add(spec);
}
}
}
}
Aggregations