Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 hbz, Pascal Christoph
* Copyright 2013, 2014 Deutsche Nationalbibliothek
Comment thread
TobiasNx marked this conversation as resolved.
Outdated
*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not hbz? Didin't you/we at hbz implement it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted as suggested

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you added M. Geipel as author. As he worked at the dnb we should than not delete dnb here, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. This is a reuse of the existing marcXmlHandler btw. this is also already heavily modified by hbz workers. I am not sure. Perhaps I should just refer to the other class? And delete Geipel?

* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,71 +29,121 @@

import java.text.Normalizer;


/**
* A pica xml handler.
*
* @author Pascal Christoph (dr0i)
* A Pica XML reader. To read marc data without namespace specification set option `namespace=""` or to null when using JAVA code.
* @author Tobias Bülte
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ,as not little of the code was just a reuse of the former code, you just add you name as author , not deleting the first one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still the creator of PpXmlHandler, PicaXmlHandler is a reuse of MarcXmlHandler which was created by Markus Michael Geipel

* @author Markus Michael Geipel
*
*/
@Description("A pica xml reader")
@Description("A Pica XML reader. To read pica data without namespace specification set option `namespace=\"\"`. To ignore namespace specification set option `ignorenamespace=\"true\". For PPXML see `handle-ppxml`")
@In(XmlReceiver.class)
@Out(StreamReceiver.class)
@FluxCommand("handle-picaxml")
public final class PicaXmlHandler extends DefaultXmlPipe<StreamReceiver> {

private static final String SUBFIELD = "subf";
private static final String DATAFIELD = "tag";
public static final String NAMESPACE = "info:srw/schema/5/picaXML-v1.0";

private static final String SUBFIELD = "subfield";
private static final String DATAFIELD = "datafield";
private static final String RECORD = "record";
private static final String NAMESPACE =
"http://www.oclcpica.org/xmlns/ppxml-1.0";
private static final String LEADER = "global";

private String attributeMarker = DEFAULT_ATTRIBUTE_MARKER;
private String currentTag = "";
private String namespace = NAMESPACE;
private StringBuilder builder = new StringBuilder();
private boolean ignoreNamespace;

/**
* Creates an instance of {@link PicaXmlHandler}.
*/
public PicaXmlHandler() {
}

/**
* Sets the namespace.
*
* <strong>Default value: {@value #NAMESPACE}</strong>
*
* @param namespace the namespace. Set to null if namespace shouldn't be checked. Set to empty string
* if the namespace is missing in the data.
*/
public void setNamespace(final String namespace) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one namespace valid (see below checkNamespacelogic). Everything not being tat namespace, i.e. also other namespaces, will be ignored. This should be documented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reuse of the mechanism from MarcXmlHandler

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reused the code and the documentation

this.namespace = namespace;
}

/**
* Sets whether to ignore the namespace.
*
* <strong>Default value: false</strong>
*
* @param ignoreNamespace true if the namespace should be ignored
*/
public void setIgnoreNamespace(final boolean ignoreNamespace) {
this.ignoreNamespace = ignoreNamespace;
}

private boolean checkNamespace(final String uri) {
return namespace == null || ignoreNamespace || namespace.equals(uri);
}

/**
* Sets the attribute marker.
*
* <strong>Default value:
* {@value org.metafacture.framework.helpers.DefaultXmlPipe#DEFAULT_ATTRIBUTE_MARKER}</strong>
*
* @param attributeMarker the attribute marker
*/
public void setAttributeMarker(final String attributeMarker) {
this.attributeMarker = attributeMarker;
}

/**
* Gets the attribute marker.
*
* @return the attribute marker
*/
public String getAttributeMarker() {
return attributeMarker;
}

@Override
public void startElement(final String uri, final String localName,
final String qName, final Attributes attributes) throws SAXException {
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException {
if (SUBFIELD.equals(localName)) {
builder = new StringBuilder();
currentTag = attributes.getValue("id");
currentTag = attributes.getValue("code");
}
else if (DATAFIELD.equals(localName)) {
getReceiver().startEntity(
attributes.getValue("id") + attributes.getValue("occ"));
final String tag = attributes.getValue("tag");
final String occurence = attributes.getValue("occurrence");
if (occurence != null) {
getReceiver().startEntity(tag + occurence);
}
else {
getReceiver().startEntity(tag);
}
}
else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) {
else if (RECORD.equals(localName) && checkNamespace(uri)) {
getReceiver().startRecord("");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested - but what if the the namespace ist set to be ignored? It won't work then, won't start the record, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the tests.

}
else if (LEADER.equals(localName)) {
builder = new StringBuilder();
currentTag = LEADER;
}
}

@Override
public void endElement(final String uri, final String localName,
final String qName) throws SAXException {
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
if (SUBFIELD.equals(localName)) {
getReceiver().literal(currentTag,
Normalizer.normalize(builder.toString().trim(), Normalizer.Form.NFC));
getReceiver().literal(currentTag, Normalizer.normalize(builder.toString().trim(), Normalizer.Form.NFC));
}
else if (DATAFIELD.equals(localName)) {
getReceiver().endEntity();
}
else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) {
else if (RECORD.equals(localName) && checkNamespace(uri)) {
getReceiver().endRecord();
}
}

@Override
public void characters(final char[] chars, final int start, final int length)
throws SAXException {
public void characters(final char[] chars, final int start, final int length) throws SAXException {
builder.append(chars, start, length);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2014 hbz, Pascal Christoph
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.metafacture.biblio.pica;

import org.metafacture.framework.FluxCommand;
import org.metafacture.framework.StreamReceiver;
import org.metafacture.framework.XmlReceiver;
import org.metafacture.framework.annotations.Description;
import org.metafacture.framework.annotations.In;
import org.metafacture.framework.annotations.Out;
import org.metafacture.framework.helpers.DefaultXmlPipe;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import java.text.Normalizer;

/**
* A pica ppxml handler.
*
* @author Pascal Christoph (dr0i)
*
*/
@Description("A pica ppxml reader")
@In(XmlReceiver.class)
@Out(StreamReceiver.class)
@FluxCommand("handle-ppxml")
public final class PpXmlHandler extends DefaultXmlPipe<StreamReceiver> {

private static final String SUBFIELD = "subf";
private static final String DATAFIELD = "tag";
private static final String RECORD = "record";
private static final String NAMESPACE =
"http://www.oclcpica.org/xmlns/ppxml-1.0";
private static final String LEADER = "global";
private String currentTag = "";
private StringBuilder builder = new StringBuilder();

/**
* Creates an instance of {@link PpXmlHandler}.
*/
public PpXmlHandler() {
}

@Override
public void startElement(final String uri, final String localName,
final String qName, final Attributes attributes) throws SAXException {
if (SUBFIELD.equals(localName)) {
builder = new StringBuilder();
currentTag = attributes.getValue("id");
}
else if (DATAFIELD.equals(localName)) {
getReceiver().startEntity(
attributes.getValue("id") + attributes.getValue("occ"));
}
else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) {
getReceiver().startRecord("");
}
else if (LEADER.equals(localName)) {
builder = new StringBuilder();
currentTag = LEADER;
}
}

@Override
public void endElement(final String uri, final String localName,
final String qName) throws SAXException {
if (SUBFIELD.equals(localName)) {
getReceiver().literal(currentTag,
Normalizer.normalize(builder.toString().trim(), Normalizer.Form.NFC));
}
else if (DATAFIELD.equals(localName)) {
getReceiver().endEntity();
}
else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) {
getReceiver().endRecord();
}
}

@Override
public void characters(final char[] chars, final int start, final int length)
throws SAXException {
builder.append(chars, start, length);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ decode-pica org.metafacture.biblio.pica.PicaDecoder
encode-pica org.metafacture.biblio.pica.PicaEncoder
remodel-pica-multiscript org.metafacture.biblio.pica.PicaMultiscriptRemodeler
handle-picaxml org.metafacture.biblio.pica.PicaXmlHandler
handle-ppxml org.metafacture.biblio.pica.PpXmlHandler

handle-mabxml org.metafacture.biblio.AlephMabXmlHandler
handle-comarcxml org.metafacture.biblio.ComarcXmlHandler
Expand Down
Loading
Loading