Skip to content

Commit

Permalink
#287: Add javadoc comments for specobject parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Jul 14, 2021
1 parent 4652edf commit bb18abf
Show file tree
Hide file tree
Showing 23 changed files with 336 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class SpecobjectImporterFactory extends RegexMatchingImporterFactory
{
private final SAXParserFactory saxParserFactory;

/**
* Create a new instance.
*/
public SpecobjectImporterFactory()
{
super("(?i).*\\.(xml|oreqm)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeContentHandler;

public class DependenciesHandlerBuilder
class DependenciesHandlerBuilder
{
private final ImportEventListener listener;
private final CallbackContentHandler handler;

public DependenciesHandlerBuilder(final ImportEventListener listener)
DependenciesHandlerBuilder(final ImportEventListener listener)
{
this.listener = listener;
this.handler = new CallbackContentHandler();
}

public TreeContentHandler build()
TreeContentHandler build()
{
this.handler.addCharacterDataListener("dependson",
data -> this.listener.addDependsOnId(SpecificationItemId.parseId(data)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeContentHandler;

public class FulfilledByHandlerBuilder
class FulfilledByHandlerBuilder
{
private final CallbackContentHandler handler;

public FulfilledByHandlerBuilder()
FulfilledByHandlerBuilder()
{
this.handler = new CallbackContentHandler();
}

public TreeContentHandler build()
TreeContentHandler build()
{
this.handler.addSubTreeHandler("ffbObj", this::createFulfillByObjectHandler);
return this.handler;
}

private CallbackContentHandler createFulfillByObjectHandler()
{
return new CallbackContentHandler() //
return new CallbackContentHandler()
.addCharacterDataListener("ffbId", data -> {})
.addCharacterDataListener("ffbType", data -> {})
.addIntDataListener("ffbVersion", data -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeContentHandler;

public class NeedsCoverageHandlerBuilder
class NeedsCoverageHandlerBuilder
{
private final ImportEventListener listener;
private final CallbackContentHandler handler;

public NeedsCoverageHandlerBuilder(final ImportEventListener listener)
NeedsCoverageHandlerBuilder(final ImportEventListener listener)
{
this.listener = listener;
this.handler = new CallbackContentHandler();
}

public TreeContentHandler build()
TreeContentHandler build()
{
return this.handler.addCharacterDataListener("needsobj",
this.listener::addNeededArtifactType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeContentHandler;

public class ProvidesCoverageHandlerBuilder
class ProvidesCoverageHandlerBuilder
{
private final ImportEventListener listener;
private final CallbackContentHandler handler;
private Builder providesCoverageIdBuilder;

public ProvidesCoverageHandlerBuilder(final ImportEventListener listener)
ProvidesCoverageHandlerBuilder(final ImportEventListener listener)
{
this.listener = listener;
this.handler = new CallbackContentHandler();
}

public TreeContentHandler build()
TreeContentHandler build()
{
this.handler.addElementListener("provcov",
elem -> this.providesCoverageIdBuilder = new Builder(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.itsallcode.openfasttrace.api.importer.ImportEventListener;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;

public class SingleSpecObjectsHandlerBuilder
class SingleSpecObjectsHandlerBuilder
{
private final CallbackContentHandler handler;
private final ImportEventListener listener;
Expand All @@ -37,7 +37,7 @@ public class SingleSpecObjectsHandlerBuilder
private String containedFileName = null;
private int containedLine = -1;

public SingleSpecObjectsHandlerBuilder(final ImportEventListener listener,
SingleSpecObjectsHandlerBuilder(final ImportEventListener listener,
final SpecificationItemId.Builder idBuilder, final Location.Builder locationBuilder)
{
this.listener = listener;
Expand All @@ -46,7 +46,7 @@ public SingleSpecObjectsHandlerBuilder(final ImportEventListener listener,
this.handler = new CallbackContentHandler();
}

public CallbackContentHandler build()
CallbackContentHandler build()
{
configureDataHandlers();
configureSubTreeHanlders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeContentHandler;

/**
* Register handlers for parsing an XML specobject document.
*/
public class SpecDocumentHandlerBuilder
{
private static final Logger LOG = Logger.getLogger(SpecDocumentHandlerBuilder.class.getName());
Expand All @@ -40,13 +43,26 @@ public class SpecDocumentHandlerBuilder
private final InputFile file;
private final ImportEventListener listener;

/**
* Create a new instance.
*
* @param file
* the parsed input file.
* @param listener
* the listener receiving import events.
*/
public SpecDocumentHandlerBuilder(final InputFile file, final ImportEventListener listener)
{
this.file = file;
this.listener = listener;
this.handler = new CallbackContentHandler();
}

/**
* Build the handler.
*
* @return the content handler.
*/
public TreeContentHandler build()
{
this.handler.setDefaultStartElementListener(startElement -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeElement;

public class SpecObjectsHandlerBuilder
class SpecObjectsHandlerBuilder
{
private final CallbackContentHandler handler;
private final InputFile file;
Expand All @@ -40,7 +40,7 @@ public class SpecObjectsHandlerBuilder
private final String defaultDoctype;
private Location.Builder locationBuilder;

public SpecObjectsHandlerBuilder(final InputFile file, final String defaultDoctype,
SpecObjectsHandlerBuilder(final InputFile file, final String defaultDoctype,
final ImportEventListener listener)
{
this.file = file;
Expand All @@ -49,7 +49,7 @@ public SpecObjectsHandlerBuilder(final InputFile file, final String defaultDocty
this.handler = new CallbackContentHandler();
}

public CallbackContentHandler build()
CallbackContentHandler build()
{
this.handler.addElementListener("specobject", this::handleStartElement,
endElement -> handleEndElement());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.CallbackContentHandler;
import org.itsallcode.openfasttrace.importer.specobject.xml.tree.TreeContentHandler;

public class TagsHandlerBuilder
class TagsHandlerBuilder
{
private final ImportEventListener listener;
private final CallbackContentHandler handler;

public TagsHandlerBuilder(final ImportEventListener listener)
TagsHandlerBuilder(final ImportEventListener listener)
{
this.listener = listener;
this.handler = new CallbackContentHandler();
}

public TreeContentHandler build()
TreeContentHandler build()
{
return this.handler.addCharacterDataListener("tag", this.listener::addTag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,42 @@
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

/**
* A SAX content handler that forwards events from an {@link XMLReader} a
* {@link EventContentHandler}.
*/
public class ContentHandlerAdapter extends DefaultHandler implements ContentHandlerAdapterController
{
private static final Logger LOG = Logger.getLogger(ContentHandlerAdapter.class.getName());

private final String fileName;
private final String filePath;
private final XMLReader xmlReader;
private final EventContentHandler delegate;
private Locator locator;
private ContentHandler originalContentHandler;

public ContentHandlerAdapter(final String fileName, final XMLReader xmlReader,
/**
* Create a new instance.
*
* @param filePath
* the path of the parsed file.
* @param xmlReader
* the {@link XMLReader}.
* @param delegate
* the content handler to which the parsing events should be
* forwared.
*/
public ContentHandlerAdapter(final String filePath, final XMLReader xmlReader,
final EventContentHandler delegate)
{
this.fileName = fileName;
this.filePath = filePath;
this.xmlReader = xmlReader;
this.delegate = delegate;
}

/**
* Initialize the delegate and register XML content handler.
*/
public void registerListener()
{
if (this.originalContentHandler != null)
Expand Down Expand Up @@ -89,7 +107,7 @@ public void endElement(final String uri, final String localName, final String qN

private Location getCurrentLocation()
{
return Location.create(this.fileName, this.locator.getLineNumber(),
return Location.create(this.filePath, this.locator.getLineNumber(),
this.locator.getColumnNumber());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
* #L%
*/

/**
* A controller that allows finishing the parsing.
*/
public interface ContentHandlerAdapterController
{
/**
* Tell the controller that this handler is finished with parsing the XML
* sub tree.
*/
void parsingFinished();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,40 @@
* #L%
*/

/**
* An event handler for XML parsing events.
*/
public interface EventContentHandler
{
/**
* Called before parsing begins.
*
* @param contentHandlerAdapter
* the controller.
*/
void init(ContentHandlerAdapterController contentHandlerAdapter);

/**
* Called when an XML element starts.
*
* @param event
* the start event.
*/
void startElement(StartElementEvent event);

/**
* Called when an XML element ends.
*
* @param event
* the end event.
*/
void endElement(EndElementEvent event);

/**
* Called when character data content is found.
*
* @param characters
* the character data.
*/
void characters(String characters);

void init(ContentHandlerAdapterController contentHandlerAdapter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

/**
* An {@link EntityResolver} that ignores all entities.
*/
public class IgnoringEntityResolver implements EntityResolver
{
private static final Logger LOG = Logger.getLogger(IgnoringEntityResolver.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;

/**
* Configures a SAX parser.
*/
public class SaxParserConfigurator
{
private SaxParserConfigurator()
{
}

/**
* Creates a new {@link SAXParserFactory} for secure processing.
*
* @return the configured factory.
*/
public static SAXParserFactory createSaxParserFactory()
{
final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
Expand Down
Loading

0 comments on commit bb18abf

Please sign in to comment.