/** * Parse the an xml file * @param is the inputsource to parse * @param handler the SAX event handler to use * @throws SAXException if an error occurs during parsing * @throws IOException if an error occurs reading from the InputSource * @throws ParserConfigurationException if there is an error in the config */ public static void parse(InputSource is, DefaultHandler handler) throws SAXException, IOException, ParserConfigurationException { parse(is, handler, true); }
/** * Parse the an xml file * @param is the inputsource to parse * @param handler the SAX event handler to use * @throws SAXException if an error occurs during parsing * @throws IOException if an error occurs reading from the InputSource * @throws ParserConfigurationException if there is an error in the config */ public static void parse(InputSource is, DefaultHandler handler) throws SAXException, IOException, ParserConfigurationException { parse(is, handler, true); }
/** * Read the template tracks from an XML stream Reader. * @param reader contains the template tracks in XML format * @param uosw the objectstore for the userprofile database */ public static void unmarshal(Reader reader, ObjectStoreWriter uosw) { try { TemplateTrackHandler ttHandler = new TemplateTrackHandler(uosw); SAXParser.parse(new InputSource(reader), ttHandler); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } }
/** * Unmarshal the Items from the input XML file, and write them to the writer. * * @param in a Reader containing the XML text input * @throws Exception if an error occurs */ public void process(Reader in) throws Exception { start = System.currentTimeMillis(); time = start; times = new long[20]; for (int i = 0; i < 20; i++) { times[i] = -1; } SAXParser.parse(new InputSource(in), new FullDataXmlHandler()); }
/** * Unmarshal the Items from the input XML file, and write them to the writer. * * @param in a Reader containing the XML text input * @throws Exception if an error occurs */ public void process(Reader in) throws Exception { start = System.currentTimeMillis(); time = start; times = new long[20]; for (int i = 0; i < 20; i++) { times[i] = -1; } SAXParser.parse(new InputSource(in), new FullDataXmlHandler()); }
/** * Parse saved queries from a Reader. * * @param reader the saved bags * @param userId an Integer * @return list of queries */ public static List<Map<String, String>> unmarshal(final Reader reader, Integer userId) { final List<Map<String, String>> sharedBags = new ArrayList<Map<String, String>>(); try { SAXParser.parse(new InputSource(reader), new SharedBagHandler(sharedBags)); } catch (Exception e) { throw new RuntimeException(e); } return sharedBags; } }
/** * Read the template tracks from an XML stream Reader. * @param reader contains the template tracks in XML format * @param uosw the objectstore for the userprofile database */ public static void unmarshal(Reader reader, ObjectStoreWriter uosw) { try { TemplateTrackHandler ttHandler = new TemplateTrackHandler(uosw); SAXParser.parse(new InputSource(reader), ttHandler); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } }
/** * Parse saved queries from a Reader. * * @param reader the saved bags * @param userId an Integer * @return list of queries */ public static List<Map<String, String>> unmarshal(final Reader reader, Integer userId) { final List<Map<String, String>> sharedBags = new ArrayList<Map<String, String>>(); try { SAXParser.parse(new InputSource(reader), new SharedBagHandler(sharedBags)); } catch (Exception e) { throw new RuntimeException(e); } return sharedBags; } }
/** * Parse TemplateQuerys from XML * @param reader the saved queries * @param savedBags Map from bag name to bag * @param version the version of the XML, an attribute on the profile manager * @return a Map from query name to SavedQuery */ public static Map<String, SavedQuery> unmarshal( Reader reader, @SuppressWarnings("rawtypes") Map savedBags, int version) { Map<String, SavedQuery> queries = new LinkedHashMap<String, SavedQuery>(); try { SAXParser.parse(new InputSource(reader), new SavedQueryHandler(queries, savedBags, version)); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return queries; } }
/** * Read a ProfileManager from an XML stream Reader * @param reader contains the ProfileManager XML * @param profileManager the ProfileManager to store the unmarshalled Profiles to * @param osw ObjectStoreWriter used to resolve object ids and write bags * correspond to object in old bags. * @param abortOnError if true, throw an exception if there is a problem. If false, log the * problem and continue if possible (used by read-userprofile-xml). */ public static void unmarshal(Reader reader, ProfileManager profileManager, ObjectStoreWriter osw, boolean abortOnError) { try { ProfileManagerHandler profileManagerHandler = new ProfileManagerHandler(profileManager, osw, abortOnError); SAXParser.parse(new InputSource(reader), profileManagerHandler); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * Read a ProfileManager from an XML stream Reader * @param reader contains the ProfileManager XML * @param profileManager the ProfileManager to store the unmarshalled Profiles to * @param osw ObjectStoreWriter used to resolve object ids and write bags * correspond to object in old bags. * @param abortOnError if true, throw an exception if there is a problem. If false, log the * problem and continue if possible (used by read-userprofile-xml). */ public static void unmarshal(Reader reader, ProfileManager profileManager, ObjectStoreWriter osw, boolean abortOnError) { try { ProfileManagerHandler profileManagerHandler = new ProfileManagerHandler(profileManager, osw, abortOnError); SAXParser.parse(new InputSource(reader), profileManagerHandler); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * Parse TemplateQuerys from XML * @param reader the saved queries * @param savedBags Map from bag name to bag * @param version the version of the XML, an attribute on the profile manager * @return a Map from query name to SavedQuery */ public static Map<String, SavedQuery> unmarshal( Reader reader, @SuppressWarnings("rawtypes") Map savedBags, int version) { Map<String, SavedQuery> queries = new LinkedHashMap<String, SavedQuery>(); try { SAXParser.parse(new InputSource(reader), new SavedQueryHandler(queries, savedBags, version)); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return queries; } }
/** * Read the bag query configuration from the given stream. * @param model the Model to use to check the bag types * @param is the InputStream * @return the BagQueryConfig object for this webapp * @throws Exception if there is a problem parsing the bag-queries.xml */ public static BagQueryConfig readBagQueryConfig(Model model, InputStream is) throws Exception { BagQueryHandler handler = new BagQueryHandler(model); SAXParser.parse(new InputSource(is), handler); return handler.getBagQueryConfig(); } }
/** * Read the bag query configuration from the given stream. * @param model the Model to use to check the bag types * @param is the InputStream * @return the BagQueryConfig object for this webapp * @throws Exception if there is a problem parsing the bag-queries.xml */ public static BagQueryConfig readBagQueryConfig(Model model, InputStream is) throws Exception { BagQueryHandler handler = new BagQueryHandler(model); SAXParser.parse(new InputSource(is), handler); return handler.getBagQueryConfig(); } }
/** * Parse Tags from XML and write them to the userprofile object store * @param pm a ProfileManager used to get UserProfile objects for a given username * @param userName the user whose tags are being unmarshalled * @param reader the saved Tags * @return number of new tags created */ public int unmarshal(ProfileManager pm, String userName, Reader reader) { TagHandler handler = new TagHandler(pm, userName); try { SAXParser.parse(new InputSource(reader), handler); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return handler.getCount(); } }
/** * Parse a InterMine Full XML file * * @param is the InputStream to parse * @return a list of Items * @throws Exception if there is an error while parsing */ public static List<Item> parse(InputStream is) throws Exception { if (is == null) { throw new NullPointerException("InputStream cannot be null"); } FullHandler handler = new FullHandler(); SAXParser.parse(new InputSource(is), handler); return handler.getItems(); }
/** * Parse a InterMine Full XML file * * @param is the InputStream to parse * @return a list of Items * @throws Exception if there is an error while parsing */ public static List<Item> parse(InputStream is) throws Exception { if (is == null) { throw new NullPointerException("InputStream cannot be null"); } FullHandler handler = new FullHandler(); SAXParser.parse(new InputSource(is), handler); return handler.getItems(); }
/** * Parse Tags from XML and write them to the userprofile object store * @param pm a ProfileManager used to get UserProfile objects for a given username * @param userName the user whose tags are being unmarshalled * @param reader the saved Tags * @return number of new tags created */ public int unmarshal(ProfileManager pm, String userName, Reader reader) { TagHandler handler = new TagHandler(pm, userName); try { SAXParser.parse(new InputSource(reader), handler); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return handler.getCount(); } }
public void testParse() throws Exception { Model model = Model.getInstanceByName("testmodel"); InputStream is = getClass().getClassLoader().getResourceAsStream("TagHandlerTest.xml"); if (is == null) { throw new IllegalArgumentException("is was null"); } TagHandler handler = new TagHandler(pm, username); SAXParser.parse(new InputSource(is), handler); int count = handler.getCount(); assertEquals(20, count); } }
public void testParse() throws Exception { Model model = Model.getInstanceByName("testmodel"); InputStream is = getClass().getClassLoader().getResourceAsStream("BagQueryHandlerTest.xml"); if (is == null) { throw new IllegalArgumentException("is was null"); } BagQueryHandler handler = new BagQueryHandler(model); SAXParser.parse(new InputSource(is), handler); Map actual = handler.getBagQueries(); System.out.println("bagQueries: " + actual); assertNotNull(actual.get("Employee")); assertEquals(1, ((List) actual.get("Employee")).size()); }