001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2004-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.registry.xml;
019:
020: import org.java.plugin.registry.MatchingRule;
021: import org.xml.sax.Attributes;
022: import org.xml.sax.EntityResolver;
023: import org.xml.sax.SAXException;
024:
025: /**
026: * @version $Id$
027: */
028: final class ManifestInfoHandler extends BaseHandler {
029: private ModelManifestInfo manifest = null;
030:
031: ManifestInfoHandler(final EntityResolver anEntityResolver) {
032: super (anEntityResolver);
033: }
034:
035: /**
036: * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
037: * java.lang.String, java.lang.String, org.xml.sax.Attributes)
038: */
039: @Override
040: public void startElement(final String uri, final String localName,
041: final String qName, final Attributes attributes)
042: throws SAXException {
043: if (log.isDebugEnabled()) {
044: log.debug("startElement - [" + uri + "]/[" //$NON-NLS-1$ //$NON-NLS-2$
045: + localName + "]/[" + qName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
046: }
047: String name = qName;
048: if ("plugin".equals(name)) { //$NON-NLS-1$
049: if (manifest != null) {
050: throw new SAXException("unexpected [" + name //$NON-NLS-1$
051: + "] element (manifest already defined)"); //$NON-NLS-1$
052: }
053: manifest = new ModelManifestInfo();
054: manifest.setId(attributes.getValue("id")); //$NON-NLS-1$
055: manifest.setVersion(attributes.getValue("version")); //$NON-NLS-1$
056: manifest.setVendor(attributes.getValue("vendor")); //$NON-NLS-1$
057: } else if ("plugin-fragment".equals(name)) { //$NON-NLS-1$
058: if (manifest != null) {
059: throw new SAXException("unexpected [" + name //$NON-NLS-1$
060: + "] element (manifest already defined)"); //$NON-NLS-1$
061: }
062: manifest = new ModelManifestInfo();
063: manifest.setId(attributes.getValue("id")); //$NON-NLS-1$
064: manifest.setVersion(attributes.getValue("version")); //$NON-NLS-1$
065: manifest.setVendor(attributes.getValue("vendor")); //$NON-NLS-1$
066: manifest.setPluginId(attributes.getValue("plugin-id")); //$NON-NLS-1$
067: if (attributes.getValue("plugin-version") != null) { //$NON-NLS-1$
068: manifest.setPluginVersion(attributes
069: .getValue("plugin-version")); //$NON-NLS-1$
070: }
071: if (attributes.getValue("match") != null) { //$NON-NLS-1$
072: manifest.setMatchingRule(MatchingRule
073: .fromCode(attributes.getValue("match"))); //$NON-NLS-1$
074: } else {
075: manifest.setMatchingRule(MatchingRule.COMPATIBLE);
076: }
077: } else {
078: // ignore all other elements
079: }
080: }
081:
082: /**
083: * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
084: * java.lang.String, java.lang.String)
085: */
086: @Override
087: public void endElement(final String uri, final String localName,
088: final String qName) {
089: if (log.isDebugEnabled()) {
090: log.debug("endElement - [" + uri + "]/[" + localName //$NON-NLS-1$ //$NON-NLS-2$
091: + "]/[" + qName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
092: }
093: // no-op
094: }
095:
096: /**
097: * @see org.xml.sax.ContentHandler#characters(char[], int, int)
098: */
099: @Override
100: public void characters(final char[] ch, final int start,
101: final int length) {
102: // ignore all characters
103: }
104:
105: ModelManifestInfo getResult() {
106: return manifest;
107: }
108: }
|