use of org.jdom.transform.JDOMSource in project intellij-community by JetBrains.
the class XsltDocumentationProvider method getDocumentation.
@Nullable
private String getDocumentation(String name, String type) {
try {
final Transformer transformer = getTemplate().newTransformer();
transformer.setParameter("element", name);
transformer.setParameter("type", type);
final StringWriter writer = new StringWriter();
transformer.transform(new JDOMSource(getDocumentationDocument()), new StreamResult(writer));
final String s = writer.toString();
final Matcher matcher = check.matcher(s);
if (matcher.find()) {
if (matcher.group(1).equals("true")) {
return s.replaceFirst("<META.+?>", "");
}
}
} catch (Exception e) {
Logger.getInstance(getClass().getName()).error(e);
}
return null;
}
use of org.jdom.transform.JDOMSource in project voldemort by voldemort.
the class ClusterMapper method readCluster.
@SuppressWarnings("unchecked")
public Cluster readCluster(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder(false);
Document doc = builder.build(input);
if (verifySchema) {
Validator validator = this.schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if (!root.getName().equals(CLUSTER_ELMT))
throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
String name = root.getChildText(CLUSTER_NAME_ELMT);
List<Zone> zones = new ArrayList<Zone>();
for (Element node : (List<Element>) root.getChildren(ZONE_ELMT)) zones.add(readZone(node));
List<Node> servers = new ArrayList<Node>();
for (Element node : (List<Element>) root.getChildren(SERVER_ELMT)) servers.add(readServer(node));
return new Cluster(name, servers, zones);
} catch (JDOMException e) {
throw new MappingException(e);
} catch (SAXException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
use of org.jdom.transform.JDOMSource in project voldemort by voldemort.
the class StoreDefinitionsMapper method readStoreList.
public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(input);
if (verifySchema) {
Validator validator = schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if (!root.getName().equals(STORES_ELMT))
throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
for (Object store : root.getChildren(STORE_ELMT)) stores.add(readStore((Element) store));
for (Object view : root.getChildren(VIEW_ELMT)) stores.add(readView((Element) view, stores));
return stores;
} catch (JDOMException e) {
throw new MappingException(e);
} catch (SAXException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
Aggregations