Ignore:
Timestamp:
2014-03-10T02:33:20+01:00 (6 years ago)
Author:
Don-vip
Message:

refactor duplicated code - impacts some plugins (reverter, roadsigns, cmdline)

Location:
trunk/src/org/openstreetmap/josm/io
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r6889 r6906  
    2424import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2525import org.openstreetmap.josm.tools.CheckParameterUtil;
     26import org.openstreetmap.josm.tools.XmlParsingException;
    2627import org.xml.sax.Attributes;
    2728import org.xml.sax.InputSource;
     
    7172     * @param diffUploadResponse the response. Must not be null.
    7273     * @param progressMonitor a progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
    73      * @throws IllegalArgumentException thrown if diffUploadRequest is null
    74      * @throws OsmDataParsingException thrown if the diffUploadRequest can't be parsed successfully
     74     * @throws IllegalArgumentException if diffUploadRequest is null
     75     * @throws XmlParsingException if the diffUploadRequest can't be parsed successfully
    7576     *
    7677     */
    77     public  void parse(String diffUploadResponse, ProgressMonitor progressMonitor) throws OsmDataParsingException {
     78    public  void parse(String diffUploadResponse, ProgressMonitor progressMonitor) throws XmlParsingException {
    7879        if (progressMonitor == null) {
    7980            progressMonitor = NullProgressMonitor.INSTANCE;
     
    8586            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser());
    8687        } catch(IOException e) {
    87             throw new OsmDataParsingException(e);
     88            throw new XmlParsingException(e);
    8889        } catch(ParserConfigurationException e) {
    89             throw new OsmDataParsingException(e);
    90         } catch(OsmDataParsingException e) {
     90            throw new XmlParsingException(e);
     91        } catch(XmlParsingException e) {
    9192            throw e;
    9293        } catch(SAXException e) {
    93             throw new OsmDataParsingException(e);
     94            throw new XmlParsingException(e);
    9495        } finally {
    9596            progressMonitor.finishTask();
     
    147148        }
    148149
    149         protected void throwException(String msg) throws OsmDataParsingException{
    150             throw new OsmDataParsingException(msg).rememberLocation(locator);
     150        protected void throwException(String msg) throws XmlParsingException {
     151            throw new XmlParsingException(msg).rememberLocation(locator);
    151152        }
    152153
     
    173174                }
    174175            } catch (NumberFormatException e) {
    175                 throw new OsmDataParsingException(e).rememberLocation(locator);
     176                throw new XmlParsingException(e).rememberLocation(locator);
    176177            }
    177178        }
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r6889 r6906  
    3939import org.openstreetmap.josm.tools.CheckParameterUtil;
    4040import org.openstreetmap.josm.tools.Utils;
     41import org.openstreetmap.josm.tools.XmlParsingException;
    4142import org.xml.sax.Attributes;
    4243import org.xml.sax.InputSource;
     
    535536        } catch(OsmTransferException e) {
    536537            throw e;
    537         } catch(OsmDataParsingException e) {
     538        } catch(XmlParsingException e) {
    538539            throw new OsmTransferException(e);
    539540        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java

    r6552 r6906  
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
    2020import org.openstreetmap.josm.tools.Utils;
     21import org.openstreetmap.josm.tools.XmlParsingException;
    2122import org.xml.sax.Attributes;
    2223import org.xml.sax.InputSource;
     
    3839        private ChangesetDataSet.ChangesetModificationType currentModificationType;
    3940
    40         protected void throwException(String message) throws OsmDataParsingException {
    41             throw new OsmDataParsingException(message).rememberLocation(locator);
     41        protected void throwException(String message) throws XmlParsingException {
     42            throw new XmlParsingException(message).rememberLocation(locator);
    4243        }
    4344
    44         protected void throwException(Exception e) throws OsmDataParsingException {
    45             throw new OsmDataParsingException(e).rememberLocation(locator);
     45        protected void throwException(Exception e) throws XmlParsingException {
     46            throw new XmlParsingException(e).rememberLocation(locator);
    4647        }
    4748
     
    128129     * @param progressMonitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null
    129130     * @return the parsed data
    130      * @throws OsmDataParsingException thrown if something went wrong. Check for chained
     131     * @throws XmlParsingException if something went wrong. Check for chained
    131132     * exceptions.
    132133     */
    133     public ChangesetDataSet parse(ProgressMonitor progressMonitor) throws OsmDataParsingException {
     134    public ChangesetDataSet parse(ProgressMonitor progressMonitor) throws XmlParsingException {
    134135        if (progressMonitor == null) {
    135136            progressMonitor = NullProgressMonitor.INSTANCE;
     
    139140            progressMonitor.indeterminateSubTask(tr("Parsing changeset content ..."));
    140141            SAXParserFactory.newInstance().newSAXParser().parse(source, new Parser());
    141         } catch(OsmDataParsingException e){
     142        } catch(XmlParsingException e) {
    142143            throw e;
    143144        } catch (ParserConfigurationException e) {
    144             throw new OsmDataParsingException(e);
     145            throw new XmlParsingException(e);
    145146        } catch(SAXException e) {
    146             throw new OsmDataParsingException(e);
     147            throw new XmlParsingException(e);
    147148        } catch(IOException e) {
    148             throw new OsmDataParsingException(e);
     149            throw new XmlParsingException(e);
    149150        } finally {
    150151            progressMonitor.finishTask();
     
    157158     *
    158159     * @return the parsed data
    159      * @throws OsmDataParsingException thrown if something went wrong. Check for chained
     160     * @throws XmlParsingException if something went wrong. Check for chained
    160161     * exceptions.
    161162     */
    162     public ChangesetDataSet parse() throws OsmDataParsingException {
     163    public ChangesetDataSet parse() throws XmlParsingException {
    163164        return parse(null);
    164165    }
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r6787 r6906  
    1919import org.openstreetmap.josm.tools.DateUtils;
    2020import org.openstreetmap.josm.tools.Utils;
     21import org.openstreetmap.josm.tools.XmlParsingException;
    2122import org.xml.sax.Attributes;
    2223import org.xml.sax.InputSource;
     
    4647    }
    4748
     49    /**
     50     * Returns the parsed changesets.
     51     * @return the parsed changesets
     52     */
    4853    public List<Changeset> getChangesets() {
    4954        return changesets;
     
    5863        }
    5964
    60         protected void throwException(String msg) throws OsmDataParsingException{
    61             throw new OsmDataParsingException(msg).rememberLocation(locator);
    62         }
    63         /**
    64          * The current changeset
    65          */
     65        protected void throwException(String msg) throws XmlParsingException {
     66            throw new XmlParsingException(msg).rememberLocation(locator);
     67        }
     68
     69        /** The current changeset */
    6670        private Changeset current = null;
    6771
    68         protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws OsmDataParsingException {
     72        protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws XmlParsingException {
    6973            // -- id
    7074            String value = atts.getValue("id");
     
    186190        }
    187191
    188         protected User createUser(String uid, String name) throws OsmDataParsingException {
     192        protected User createUser(String uid, String name) throws XmlParsingException {
    189193            if (uid == null) {
    190194                if (name == null)
  • trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

    r6830 r6906  
    1818import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
     20import org.openstreetmap.josm.tools.XmlParsingException;
    2021
    2122/**
     
    182183            OsmChangesetContentParser parser = new OsmChangesetContentParser(in);
    183184            return parser.parse(monitor.createSubTaskMonitor(1, true));
    184         } catch(OsmDataParsingException e) {
     185        } catch(XmlParsingException e) {
    185186            throw new OsmTransferException(e);
    186187        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r6889 r6906  
    1919import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2020import org.openstreetmap.josm.tools.DateUtils;
     21import org.openstreetmap.josm.tools.XmlParsingException;
    2122import org.w3c.dom.Document;
    2223import org.w3c.dom.Node;
     
    3334     * @param document The XML contents
    3435     * @return The user info
    35      * @throws OsmDataParsingException if parsing goes wrong
     36     * @throws XmlParsingException if parsing goes wrong
    3637     */
    37     public static UserInfo buildFromXML(Document document) throws OsmDataParsingException {
     38    public static UserInfo buildFromXML(Document document) throws XmlParsingException {
    3839        try {
    3940            XPathFactory factory = XPathFactory.newInstance();
     
    4243            Node xmlNode = (Node)xpath.compile("/osm/user[1]").evaluate(document, XPathConstants.NODE);
    4344            if ( xmlNode== null)
    44                 throw new OsmDataParsingException(tr("XML tag <user> is missing."));
     45                throw new XmlParsingException(tr("XML tag <user> is missing."));
    4546
    4647            // -- id
    4748            String v = getAttribute(xmlNode, "id");
    4849            if (v == null)
    49                 throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "id", "user"));
     50                throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "id", "user"));
    5051            try {
    5152                userInfo.setId(Integer.parseInt(v));
    5253            } catch(NumberFormatException e) {
    53                 throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "id", "user", v));
     54                throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "id", "user", v));
    5455            }
    5556            // -- display name
     
    7172                v = getAttribute(xmlNode, "lat");
    7273                if (v == null)
    73                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lat", "home"));
     74                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lat", "home"));
    7475                double lat;
    7576                try {
    7677                    lat = Double.parseDouble(v);
    7778                } catch(NumberFormatException e) {
    78                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lat", "home", v));
     79                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lat", "home", v));
    7980                }
    8081
    8182                v = getAttribute(xmlNode, "lon");
    8283                if (v == null)
    83                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lon", "home"));
     84                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lon", "home"));
    8485                double lon;
    8586                try {
    8687                    lon = Double.parseDouble(v);
    8788                } catch(NumberFormatException e) {
    88                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lon", "home", v));
     89                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lon", "home", v));
    8990                }
    9091
    9192                v = getAttribute(xmlNode, "zoom");
    9293                if (v == null)
    93                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "zoom", "home"));
     94                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "zoom", "home"));
    9495                int zoom;
    9596                try {
    9697                    zoom = Integer.parseInt(v);
    9798                } catch(NumberFormatException e) {
    98                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "zoom", "home", v));
     99                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "zoom", "home", v));
    99100                }
    100101                userInfo.setHome(new LatLon(lat,lon));
     
    117118                v = getAttribute(xmlNode, "unread");
    118119                if (v == null)
    119                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received"));
     120                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received"));
    120121                try {
    121122                    userInfo.setUnreadMessages(Integer.parseInt(v));
    122123                } catch(NumberFormatException e) {
    123                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v), e);
     124                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v), e);
    124125                }
    125126            }
     
    127128            return userInfo;
    128129        } catch(XPathException e) {
    129             throw new OsmDataParsingException(e);
     130            throw new XmlParsingException(e);
    130131        }
    131132    }
Note: See TracChangeset for help on using the changeset viewer.