use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.
the class BookMaker method checkCrossLinks.
private void checkCrossLinks(String name, XhtmlNode node) {
if (node.getNodeType() == NodeType.Element && node.getName().equals("a")) {
String href = node.getAttribute("href");
if (href != null) {
if (!pages.containsKey(href)) {
boolean found = false;
if (href.endsWith(".xsd") || href.endsWith(".xml") || href.endsWith(".xml.html") || href.endsWith(".json") || href.endsWith(".zip"))
found = true;
else if (pages.containsKey(href))
found = true;
else if (href.startsWith("http:") || href.startsWith("https:") || href.startsWith("mailto:") || href.startsWith("ftp:"))
found = true;
else if (href.startsWith("v2/") || href.startsWith("v3/") || href.startsWith("../")) {
found = true;
node.setAttribute("href", "http://hl7.org/fhir" + href);
}
if (!found && href.contains("#")) {
String[] parts = href.split("#");
if (parts == null || parts.length == 0) {
parts = new String[] { name };
} else if (parts[0].equals(""))
parts[0] = name;
found = pages.containsKey(parts[0]);
if (found && parts[1] != null && !parts[1].equals("")) {
found = findTarget(pages.get(parts[0]), parts[1]);
if (!found)
try {
if (new File("c:\\temp\\source.html").exists())
new XhtmlComposer(XhtmlComposer.HTML).compose(new FileOutputStream("c:\\temp\\source.html"), pages.get(parts[0]));
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (!found && !new File(page.getFolders().dstDir + href).exists() && !href.equals("qa.html")) {
issues.add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, -1, -1, name, "broken link in " + name + ": <a href=\"" + href + "\">" + node.allText() + "</a>", IssueSeverity.ERROR));
}
}
}
} else {
if (!(node.getNodeType() == NodeType.Element && "div".equals(node.getName()) && "index-only-no-book".equals(node.getAttribute("class"))))
for (XhtmlNode c : node.getChildNodes()) checkCrossLinks(name, c);
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.
the class HTMLLinkChecker method check.
private void check(Entry e) throws Exception {
if (new File(Utilities.path(page.getFolders().dstDir, e.filename)).exists()) {
e.checked = true;
checkNormativeStatus(e.filename);
XhtmlDocument doc;
try {
doc = new XhtmlParser().parse(new FileInputStream(Utilities.path(page.getFolders().dstDir, e.filename)), "html");
checkAnchors(doc, e);
checkLinks(doc, e);
stripDivs(doc);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new XhtmlComposer(XhtmlComposer.HTML).compose(stream, doc);
e.bytes = stream.toByteArray();
if (e.bytes == null || e.bytes.length == 0)
throw new Exception("File is empty");
} catch (Exception e1) {
throw new Exception("Error parsing " + Utilities.path(page.getFolders().dstDir, e.filename), e1);
}
} else {
reportError(e.filename, "Unable to find file " + e.filename);
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.
the class LogicalModelProcessor method genLogicalModelTable.
private String genLogicalModelTable(StructureDefinition sd, String prefix) throws Exception {
ProfileUtilities pu = new ProfileUtilities(page.getWorkerContext(), null, this);
XhtmlNode x = pu.generateTable(sd.getId() + "-definitions.html", sd, sd.hasSnapshot() ? false : true, page.getFolders().dstDir, false, sd.getId(), true, prefix, prefix, true, false, null, true, false);
return new XhtmlComposer(XhtmlComposer.HTML).compose(x);
}
use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.
the class SourceParser method loadConformancePackage.
private void loadConformancePackage(Profile ap, List<ValidationMessage> issues, WorkGroup wg) throws FileNotFoundException, IOException, Exception {
if (ap.getSourceType() == ConformancePackageSourceType.Spreadsheet) {
OldSpreadsheetParser sparser = new OldSpreadsheetParser(ap.getCategory(), new CSFileInputStream(ap.getSource()), Utilities.noString(ap.getId()) ? ap.getSource() : ap.getId(), ap.getSource(), definitions, srcDir, logger, registry, version, context, genDate, false, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
sparser.setFolder(Utilities.getDirectoryForFile(ap.getSource()));
sparser.parseConformancePackage(ap, definitions, Utilities.getDirectoryForFile(ap.getSource()), ap.getCategory(), issues, wg);
errors.addAll(sparser.getErrors());
} else if (ap.getSourceType() == ConformancePackageSourceType.StructureDefinition) {
Resource rf;
try {
rf = new XmlParser().parse(new CSFileInputStream(ap.getSource()));
} catch (Exception e) {
throw new Exception("Error parsing " + ap.getSource() + ": " + e.getMessage(), e);
}
if (!(rf instanceof StructureDefinition))
throw new Exception("Error parsing Profile: not a structure definition");
StructureDefinition sd = (StructureDefinition) rf;
sd.setVersion(version.toCode());
ap.putMetadata("id", sd.getId() + "-pack");
ap.putMetadata("date", sd.getDateElement().asStringValue());
ap.putMetadata("title", sd.getTitle());
ap.putMetadata("status", sd.getStatus().toCode());
ap.putMetadata("description", new XhtmlComposer(XhtmlComposer.HTML).compose(sd.getText().getDiv()));
if (ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg")) {
wg = definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"));
ap.putMetadata("workgroup", wg.getCode());
}
ap.setTitle(sd.getTitle());
new ProfileUtilities(page.getWorkerContext(), null, null).setIds(sd, false);
ap.getProfiles().add(new ConstraintStructure(sd, definitions.getUsageIG(ap.getCategory(), "Parsing " + ap.getSource()), wg == null ? wg(sd) : wg, fmm(sd), sd.getExperimental()));
} else if (ap.getSource() != null) {
parseConformanceDocument(ap, ap.getId(), new CSFile(ap.getSource()), ap.getCategory(), wg);
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project kindling by HL7.
the class Publisher method fixExampleReferences.
private String fixExampleReferences(String path, String narrative) throws Exception {
if (narrative == null)
return "";
XhtmlNode node = new XhtmlParser().parseFragment(narrative);
checkExampleLinks(path, node);
return new XhtmlComposer(XhtmlComposer.HTML).compose(node);
}
Aggregations