use of net.heartsome.xml.Element in project translationstudio8 by heartsome.
the class AutoConfiguration method recurse.
/**
* Recurse.
* @param r
* the r
*/
private void recurse(Element r) {
//$NON-NLS-1$
String text = "";
List<Node> content = r.getContent();
Iterator<Node> i = content.iterator();
while (i.hasNext()) {
Node n = i.next();
if (n.getNodeType() == Node.TEXT_NODE) {
text = text + n.getNodeValue().trim();
}
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element e = new Element(n);
recurse(e);
}
}
if (!text.equals("") && !segment.contains(r.getName())) {
//$NON-NLS-1$
segment.put(r.getName(), r.getName());
}
}
use of net.heartsome.xml.Element in project translationstudio8 by heartsome.
the class PluginHelpDialog method searchElement.
private void searchElement(Element root, String file, String text, boolean sensitive) throws UnsupportedEncodingException, IOException {
List<Element> children = root.getChildren();
Iterator<Element> it = children.iterator();
while (it.hasNext()) {
Element e = it.next();
if (!e.getAttributeValue("id", "").equals("")) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String txt = e.getTextNormalize();
if (!sensitive) {
txt = txt.toLowerCase();
}
if (txt.indexOf(text) != -1) {
if (//$NON-NLS-1$
e.getName().equals("p") || //$NON-NLS-1$
e.getName().equals("title") || //$NON-NLS-1$
e.getName().equals("h1") || //$NON-NLS-1$
e.getName().equals("h2") || //$NON-NLS-1$
e.getName().equals("h3") || //$NON-NLS-1$
e.getName().equals("h4") || //$NON-NLS-1$
e.getName().equals("h5") || e.getName().equals("h6")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
writeString("<a href=\"" + file + "#" + e.getAttributeValue("id") + "\">" + file + "</a>");
//$NON-NLS-1$
writeString("<br/>");
writeString(e.getTextNormalize());
//$NON-NLS-1$
writeString("<hr/>");
isFound = true;
}
}
}
searchElement(e, file, text, sensitive);
}
}
use of net.heartsome.xml.Element 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) {
}
}
use of net.heartsome.xml.Element in project translationstudio8 by heartsome.
the class PluginHelpDialog method recurseTree.
private void recurseTree(Element elementParent, TreeItem itemParent, String basePath) throws Exception {
List<Element> children = elementParent.getChildren();
for (int i = 0; i < children.size(); i++) {
Element element = children.get(i);
String url = element.getAttributeValue("url", "");
TreeItem item = new TreeItem(itemParent, SWT.NONE);
if (url.startsWith(".")) {
// relative path
url = CommonFunction.getAbsolutePath(basePath, url);
}
if (!url.toLowerCase().startsWith("http:")) {
File f = new File(url);
if (!f.exists() || !f.isAbsolute()) {
url = CommonFunction.getAbsolutePath(basePath, url);
}
}
item.setData(element.getName());
if (element.getName().equals("toc")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_TOC_CLOSED).createImage());
item.setText(element.getText());
if (url.startsWith(".")) {
url = CommonFunction.getAbsolutePath(basePath, url);
}
loadToc(item, new File(url).getCanonicalPath());
}
if (element.getName().equals("book")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_BOOK_CLOSED).createImage());
item.setText(element.getAttributeValue("title"));
recurseTree(element, item, basePath);
if (!url.equals("")) {
hashTable.put(item, new File(url).toURI().toURL().toString());
}
}
if (element.getName().equals("item")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_TOPIC).createImage());
item.setText(element.getText());
hashTable.put(item, new File(url).toURI().toURL().toString());
}
}
}
use of net.heartsome.xml.Element 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