I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Saturday, 20 July 2013

Apache Log Files Analysis

I might be doing this a lot of apache log file analysis in a few days so might as well take look at the the open source (and others) project there are t to perform this task.

I discovered the following projects:

  • logQL (GPL v3)
  • WebLog Expert ( with an Lite Freeware version)

The first one seems nice simple and the GUI is kept very simple. While the second one seems to have a lot of features. However, I have not tried to see exactly which one are available in the lite version.

I might also add a number of other libraires here.

Friday, 12 July 2013

Axiom - XML Processing for Axis and others

I have been taking a look at the Apache Axis2 Web Service framework. Reading the documentation, I was reminded of the Axiom framework used for the processing of XML. Therefore, I will gather here a few informations which I find useful. These info come partially from quickstart-samples. The example are changed a little to be adapted to my way of thinking. This is also a documentation for me.


In addition to be used to process XML efficiently, Axiom can be used to process MTOM messages which are used in SOAP to transport binary data.
Again on the quickstart-samples page, there are some examples. But I will use a separate POST for this.


How to retrieve child elements from root:

public void processXmlFile(File file, String namespace, String elementName) throws IOException, OMException {
// initialize the file input stream to be closed in this method
InputStream in = new FileInputStream(file);
// get the root element
OMElement root = OMXMLBuilderFactory.createOMBuilder(in).getDocumentElement();

// Process the content of the file
OMElement element = root.getFirstChildWithName(
new QName("-http://maven.apache.org/POM/4.0.0", "url"));
if (element == null) {
System.out.println("No <"+elementName+"> element found");
} else {
System.out.println(elementName" = " + element.getText());
}

// Because Axiom uses deferred parsing, the stream must be closed AFTER
// processing the document (unless OMElement#build() is called)
in.close();
}

Schema validation

How to perform partial schema validation (from quickstart-samples).

public void validate(InputStream in, URL schemaUrl) throws Exception {
  SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8");
  SOAPEnvelope envelope = builder.getSOAPEnvelope();
  OMElement bodyContent = envelope.getBody().getFirstElement();
  SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema = schemaFactory.newSchema(schemaUrl);
  Validator validator = schema.newValidator();
  validator.validate(bodyContent.getSAXSource(true));
}

quickstart-samples presents also a way to do it with a DOMSource instead of the SAXSource.


Perform on chunks of an XML Document


Often it is useful to perform just on a particular chunk of the XML document.

public interface FragmentProcessor {

    public QName getTagName();

    public void processFragment(OEMElement);

}

  public void processFragments(InputStream in, FragmentProcessor fragmentProcessor) throws XMLStreamException {
    // Create an XMLStreamReader without building the object model
    XMLStreamReader reader =
       OMXMLBuilderFactory.createOMBuilder(in).getDocument().getXMLStreamReader(false);
    QName tagName = fragmentProcessor.getTagName();
    while (reader.hasNext()) {
       if (reader.getEventType() == XMLStreamReader.START_ELEMENT &&
          reader.getName().equals(tagName)) {
             OMElement element =
                OMXMLBuilderFactory.createStAXOMBuilder(reader).getDocumentElement();
             // Make sure that all events belonging to the element are consumed so that
             // that the XMLStreamReader points to a well defined location (namely the
             // event immediately following the END_ELEMENT event).
             element.build();
             // Now process the element.
             fragmentProcessor.processFragment(element);
          } else {
             reader.next();
          }
       }
   }

Wednesday, 10 July 2013

Maven Apt and Code Snippets

For a documentation and course I will give I am using the document creation properties from apt of maven. For a documentation of the format see:
the APT format. In order to give an example, you can use a very simple snippet:

    ------
    The APT format ( or the html title of the document)
    ------
    Me the author
    ------
    2013-7-9


The title at the top of the page (not indented)

  The first introduction paragraph.... which is indented so that it is clear that it is a paragraph.

* The first subsection

  Another paragraph also indented

** a subsection with two * in order to mark it as a sub subsection

  A third paragraph followed by an ordered list with numbers

    [[1]] first element

    [[1]] second element


This create the following snippet HTML fragment (in a given generated page).



<h2>The title at the top of the page (not indented)
<a name="The_title_at_the_top_of_the_page_not_indented"></a></h2>

<p>The first introduction paragraph.... which is indented so that it is clear that it is a paragraph.</p>

<div class="section"><h3>The first subsection

<a name="The_first_subsection"></a>

</h3><p>Another paragraph</p>

<div class="section"><h4>a subsection with two * in order to mark it as a sub subsection<a name="a_subsection_with_two__in_order_to_mark_it_as_a_sub_subsection"></a></h4>

<p>A third paragraph followed by an ordered list with numbers</p>

<ol style="list-style-type: decimal"><li>first element</li><li>second element</li></ol></div></div></div>

In order to get snippets, then I use snippet macros as described in: Guide to the Snippet Macro.

Thursday, 4 July 2013

Eclipse installation Problem onWindows7 with cygwin unzip

Once or twice I had problem using unzip to unpack the eclipse code under windows7. Thanks to this answer, it could start eclipse normally. After downloading eclipse:

$> cd dirtoput-eclipse
$> unzip pathwhere-eclipsezipis/eclipse...-version.zip
$> cd eclipse
$> find . -name "*.dll" -exec chmod +x {} \;