Schematron extends Localized { @Transient public String getRuleName() { if (file == null) { return "unnamed rule"; } int lastSegmentIndex = file.lastIndexOf(SEPARATOR); if (lastSegmentIndex < 0) { lastSegmentIndex = file.lastIndexOf(ALT_SEPARATOR); } if (lastSegmentIndex < 0) { lastSegmentIndex = 0; } else { lastSegmentIndex += 1; } String rule = file.substring(lastSegmentIndex, file.length() - EXTENSION_LENGTH); String lowerCaseRuleName = rule.toLowerCase(); for (SchematronRequirement requirement : SchematronRequirement.values()) { if (lowerCaseRuleName.endsWith("." + requirement.name().toLowerCase())) { return rule.substring(0, rule.length() - requirement.name().length() - 1); } } return rule; }  @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = ID_SEQ_NAME) @Column(nullable = false) int getId(); Schematron setId(int id); @Override String toString(); @Column(nullable = false, name = "schemaName") String getSchemaName(); void setSchemaName(String schemaName); @Column(nullable = false, name = "filename") String getFile(); void setFile(String file); @Override @ElementCollection(fetch = FetchType.LAZY, targetClass = String.class) @CollectionTable(joinColumns = @JoinColumn(name = "idDes"), name = "SchematronDes") @MapKeyColumn(name = "langId", length = 5) @Column(name = "label", nullable = false, length = 255) Map<String, String> getLabelTranslations(); int getDisplayPriority(); void setDisplayPriority(int displayPriority); @Transient String getRuleName(); @Transient SchematronRequirement getDefaultRequirement(); @Override boolean equals(Object o); @Override int hashCode(); static final Comparator<? super Schematron> DISPLAY_PRIORITY_COMPARATOR; }
@Test public void testGetRuleName() throws Exception { final Schematron schematron = new Schematron(); schematron.setFile("xyz/bcd/abc.xsl"); assertEquals("abc", schematron.getRuleName()); schematron.setFile(schematron.getFile().replace("/", "\\")); assertEquals("abc", schematron.getRuleName()); schematron.setFile("abc.xsl"); assertEquals("abc", schematron.getRuleName()); }