From 1089eac8affc946c57d072be563d2fa3de9a9e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Tue, 14 Jan 2014 22:19:46 +0000 Subject: [PATCH] - improved dealing with predefined vocabulary in parser --- .../exmo/align/parser/SyntaxElement.java | 18 +++++++++++------- .../inrialpes/exmo/align/parser/XMLParser.java | 9 ++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java index c140e98b..7c7698e1 100644 --- a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java +++ b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java @@ -4,7 +4,7 @@ * Copyright (C) 2006 Digital Enterprise Research Insitute (DERI) Innsbruck * Copyright (C) 2005 Digital Enterprise Research Insitute (DERI) Galway * Sourceforge version 1.6 - 2008 - then OmwgElement - * Copyright (C) INRIA, 2008-2010, 2012 + * Copyright (C) INRIA, 2008-2010, 2012, 2014 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -211,14 +211,18 @@ public enum SyntaxElement { * @throws NullPointerException * if the string is null */ - public static SyntaxElement getElementByName(final String s) { - if (s == null) { - throw new NullPointerException("The string must not be null"); + public static SyntaxElement getElementByName( final String s ) { + if ( s == null ) throw new NullPointerException("The string must not be null"); + for ( SyntaxElement e : SyntaxElement.values() ) { + if ( s.equals( e.getName() ) ) return e; } + return null; + } + + public static SyntaxElement getSyntaxElement( final Namespace ns, final String s ) { + if ( s == null ) throw new NullPointerException("The string must not be null"); for ( SyntaxElement e : SyntaxElement.values() ) { - if ( s.equals( e.getName() ) ) { - return e; - } + if ( ns == e.getNamespace() && s.equals( e.getName() ) ) return e; } return null; } diff --git a/src/fr/inrialpes/exmo/align/parser/XMLParser.java b/src/fr/inrialpes/exmo/align/parser/XMLParser.java index 9d48978d..bd8d94cb 100644 --- a/src/fr/inrialpes/exmo/align/parser/XMLParser.java +++ b/src/fr/inrialpes/exmo/align/parser/XMLParser.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2003-2005, 2007-2013 + * Copyright (C) INRIA, 2003-2005, 2007-2014 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -330,9 +330,6 @@ public class XMLParser extends DefaultHandler { curronto = onto1; } else if (pName.equals("uri2")) { // Legacy } else if (pName.equals("uri1")) { // Legacy - } else if (pName.equals( SyntaxElement.TYPE.name )) { - } else if (pName.equals( SyntaxElement.LEVEL.name )) { - } else if (pName.equals( SyntaxElement.XML.name )) { } else if (pName.equals( SyntaxElement.ALIGNMENT.name )) { alignLevel = parseLevel; parseLevel = 2; // for embeded (RDF is usually 1) @@ -344,7 +341,9 @@ public class XMLParser extends DefaultHandler { alignment.setExtension( Namespace.ALIGNMENT.uri, Annotations.ID, about ); }; } else { - logger.warn( "Unknown element name : {}", pName ); + // This should avoid all the stuff before + if ( SyntaxElement.getSyntaxElement( Namespace.ALIGNMENT, pName ) == null ) + logger.warn( "Unknown element name : {}", pName ); }; } else if ( namespaceURI.equals( Namespace.SOAP_ENV.prefix )) { //"http://schemas.xmlsoap.org/soap/envelope/")) { // Ignore SOAP namespace -- GitLab