How to combine FileContentPattern with XmlPatterns ?

Hi,

I'm currently trying to implement a facet for an internal framework.

I have some problem to implement the "createSuitableFilePattern". The framework dectection is based on the presence of a Spring bean with a specficic value for the attribute 'class'

Here's how I try tho do that :

return FileContentPattern.fileContent()
        .xmlWithRootTagNamespace("http://www.springframework.org/schema/beans")
        .xmlWithRootTag("beans").and(XmlPatterns.xmlTag().withName("bean").withAttributeValue("class", "com.bsb.fluid.core.model.scanner.ScanningConfiguration"));


But this does not seem to work. The first part (before ".and") works, it detects correctly all spring configuration file, but the complete pattern does not work.

Is there a way to implement what I'm trying to do ?

I also noticed that facet configuration seems to have some kind of cache. Restarting does not always take changes of the method "createSuitableFilePattern" into account, I need to add/remove some plugins before it works correctly.

Is there a way to bypass that cache ?

Thanks

Gauthier

1 comment

I was finally able to implement what I wanted to do like this :

  public ElementPattern<FileContent> createSuitableFilePattern() {
    return FileContentPattern.fileContent()
      .xmlWithRootTagNamespace("http://www.springframework.org/schema/beans")
      .xmlWithRootTag("beans")
      .with(new PatternCondition<FileContent>("fluidCondition") {
        @Override
        public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) {
          StdXMLBuilder builder = new StdXMLBuilder();
          NanoXmlUtil.parse(CharArrayUtil.readerFromCharSequence(fileContent.getContentAsText()), builder);
          IXMLElement result = (IXMLElement)builder.getResult();
          for (Object beanObject : result.getChildrenNamed("bean")) {
            IXMLElement bean = (IXMLElement)beanObject;
            String aClass = bean.getAttribute("class", "");
            if ("com.bsb.fluid.core.model.scanner.ScanningConfiguration".equals(aClass)) {
              return true;
            }
          }
          return false;
        }
      });
  }


But I still have a lot of questions and misunderstandings. Is there any documentation on how to implement Facets somewhere ?

Thanks,

Gauthier

0

Please sign in to leave a comment.