use of com.mindbright.security.x509.Attribute in project s1tbx by senbox-org.
the class BinaryDBReader method DecodeElement.
private static void DecodeElement(final BinaryFileReader reader, final Map metaMap, final Element child, final String suffix) {
String name = "";
try {
final Attribute nameAttrib = child.getAttribute("name");
final Attribute typeAttrib = child.getAttribute("type");
final Attribute numAttrib = child.getAttribute("num");
if (nameAttrib != null && typeAttrib != null && numAttrib != null) {
name = nameAttrib.getValue();
if (suffix != null)
name += suffix;
final int type = Integer.parseInt(typeAttrib.getValue());
final int num = Integer.parseInt(numAttrib.getValue());
switch(type) {
case Skip:
{
// blank
reader.skipBytes(num);
break;
}
case An:
{
metaMap.put(name, reader.readAn(num));
break;
}
case In:
{
metaMap.put(name, (int) reader.readIn(num));
break;
}
case B1:
{
metaMap.put(name, reader.readB1());
break;
}
case B2:
{
metaMap.put(name, reader.readB2());
break;
}
case B4:
{
metaMap.put(name, reader.readB4());
break;
}
case B8:
{
metaMap.put(name, reader.readB8());
break;
}
case Fn:
{
metaMap.put(name, reader.readFn(num));
break;
}
case En:
{
metaMap.put(name, reader.readEn(num));
break;
}
case Debug:
{
System.out.print(" = ");
for (int i = 0; i < num; ++i) {
final String tmp = reader.readAn(1);
if (!tmp.isEmpty() && !tmp.equals(" "))
System.out.print(tmp);
}
System.out.println();
break;
}
default:
{
throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos());
}
}
}
} catch (Exception e) {
if (e.getCause() != null)
SystemUtils.LOG.severe(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name);
else
SystemUtils.LOG.severe(' ' + e.toString() + ':' + " for " + name);
}
}
use of com.mindbright.security.x509.Attribute in project s1tbx by senbox-org.
the class BinaryDBReader method DecodeElementDebug.
private void DecodeElementDebug(final BinaryFileReader reader, final Map metaMap, final Element child, final String suffix) {
String name = "";
try {
final Attribute nameAttrib = child.getAttribute("name");
final Attribute typeAttrib = child.getAttribute("type");
final Attribute numAttrib = child.getAttribute("num");
if (nameAttrib != null && typeAttrib != null && numAttrib != null) {
name = nameAttrib.getValue();
if (suffix != null)
name += suffix;
final int type = Integer.parseInt(typeAttrib.getValue());
final int num = Integer.parseInt(numAttrib.getValue());
System.out.print(" " + reader.getCurrentPos() + ' ' + (reader.getCurrentPos() - startPos + 1) + ' ' + name + ' ' + type + ' ' + num);
switch(type) {
case Skip:
{
// blank
reader.skipBytes(num);
break;
}
case An:
{
final String tmp = reader.readAn(num);
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case In:
{
final int tmp = (int) reader.readIn(num);
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case B1:
{
final int tmp = reader.readB1();
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case B2:
{
final int tmp = reader.readB2();
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case B4:
{
final int tmp = reader.readB4();
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case B8:
{
final long tmp = reader.readB8();
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case Fn:
{
double tmp = reader.readFn(num);
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case En:
{
double tmp = reader.readEn(num);
System.out.print(" = " + tmp);
metaMap.put(name, tmp);
break;
}
case Debug:
{
System.out.print(" = ");
for (int i = 0; i < num; ++i) {
final String tmp = reader.readAn(1);
if (!tmp.isEmpty() && !tmp.equals(" "))
System.out.print(tmp);
}
System.out.println();
break;
}
default:
{
throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos());
}
}
System.out.println();
}
} catch (Exception e) {
if (e.getCause() != null)
SystemUtils.LOG.severe(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name);
else
SystemUtils.LOG.severe(' ' + e.toString() + ':' + " for " + name);
// throw new IllegalBinaryFormatException(e.toString(), reader.getCurrentPos());
}
}
use of com.mindbright.security.x509.Attribute in project s1tbx by senbox-org.
the class NetCDFUtils method addAttributes.
public static MetadataElement addAttributes(final MetadataElement parentElem, final String elemName, final List<Attribute> attribList) {
final MetadataElement globalElem = new MetadataElement(elemName);
parentElem.addElement(globalElem);
for (Attribute at : attribList) {
createMetadataAttributes(globalElem, at, at.getName());
}
return globalElem;
}
use of com.mindbright.security.x509.Attribute in project kitodo-production by kitodo.
the class ExportXmlLog method startMultipleExport.
/**
* This method exports the production metadata for al list of processes as a
* single file to a given stream.
*
* @param docketDataList
* a list of Docket data
* @param outputStream
* The output stream, to write the docket to.
*/
void startMultipleExport(Iterable<DocketData> docketDataList, OutputStream outputStream) {
Document answer = new Document();
Element root = new Element("processes");
answer.setRootElement(root);
Namespace xmlns = Namespace.getNamespace(NAMESPACE);
Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.addNamespaceDeclaration(xsi);
root.setNamespace(xmlns);
Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
root.setAttribute(attSchema);
for (DocketData docketData : docketDataList) {
Document doc = createDocument(docketData, false);
Element processRoot = doc.getRootElement();
processRoot.detach();
root.addContent(processRoot);
}
XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat());
try {
outp.output(answer, outputStream);
} catch (IOException e) {
logger.error("Generating XML Output failed.", e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
logger.error("Closing the output stream failed.", e);
}
}
}
}
use of com.mindbright.security.x509.Attribute in project kitodo-production by kitodo.
the class ExportXmlLog method createDocument.
/**
* This method creates a new xml document with process metadata.
*
* @param docketData
* the docketData to export
* @return a new xml document
*/
private Document createDocument(DocketData docketData, boolean addNamespace) {
Element processElm = new Element("process");
final Document doc = new Document(processElm);
processElm.setAttribute("processID", String.valueOf(docketData.getProcessId()));
Namespace xmlns = Namespace.getNamespace(NAMESPACE);
processElm.setNamespace(xmlns);
// namespace declaration
if (addNamespace) {
Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
processElm.addNamespaceDeclaration(xsi);
Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
processElm.setAttribute(attSchema);
}
// process information
ArrayList<Element> processElements = new ArrayList<>();
Element processTitle = new Element("title", xmlns);
processTitle.setText(docketData.getProcessName());
processElements.add(processTitle);
Element project = new Element("project", xmlns);
project.setText(docketData.getProjectName());
processElements.add(project);
Element date = new Element("time", xmlns);
date.setAttribute("type", "creation date");
date.setText(String.valueOf(docketData.getCreationDate()));
processElements.add(date);
Element ruleset = new Element("ruleset", xmlns);
ruleset.setText(docketData.getRulesetName());
processElements.add(ruleset);
Element comment = new Element("comment", xmlns);
comment.setText(docketData.getComment());
processElements.add(comment);
List<Element> processProperties = prepareProperties(docketData.getProcessProperties(), xmlns);
if (!processProperties.isEmpty()) {
Element properties = new Element(PROPERTIES, xmlns);
properties.addContent(processProperties);
processElements.add(properties);
}
// template information
ArrayList<Element> templateElements = new ArrayList<>();
Element template = new Element("original", xmlns);
ArrayList<Element> templateProperties = new ArrayList<>();
if (docketData.getTemplateProperties() != null) {
for (Property prop : docketData.getTemplateProperties()) {
Element property = new Element(PROPERTY, xmlns);
property.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle());
if (prop.getValue() != null) {
property.setAttribute(VALUE, replacer(prop.getValue()));
} else {
property.setAttribute(VALUE, "");
}
Element label = new Element(LABEL, xmlns);
label.setText(prop.getTitle());
property.addContent(label);
templateProperties.add(property);
if (prop.getTitle().equals("Signatur")) {
Element secondProperty = new Element(PROPERTY, xmlns);
secondProperty.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle() + "Encoded");
if (prop.getValue() != null) {
secondProperty.setAttribute(VALUE, "vorl:" + replacer(prop.getValue()));
Element secondLabel = new Element(LABEL, xmlns);
secondLabel.setText(prop.getTitle());
secondProperty.addContent(secondLabel);
templateProperties.add(secondProperty);
}
}
}
}
if (!templateProperties.isEmpty()) {
Element properties = new Element(PROPERTIES, xmlns);
properties.addContent(templateProperties);
template.addContent(properties);
}
templateElements.add(template);
Element templates = new Element("originals", xmlns);
templates.addContent(templateElements);
processElements.add(templates);
// digital document information
ArrayList<Element> docElements = new ArrayList<>();
Element dd = new Element("digitalDocument", xmlns);
List<Element> docProperties = prepareProperties(docketData.getWorkpieceProperties(), xmlns);
if (!docProperties.isEmpty()) {
Element properties = new Element(PROPERTIES, xmlns);
properties.addContent(docProperties);
dd.addContent(properties);
}
docElements.add(dd);
Element digdoc = new Element("digitalDocuments", xmlns);
digdoc.addContent(docElements);
processElements.add(digdoc);
processElm.setContent(processElements);
return doc;
}
Aggregations