List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:com.krawler.workflow.bizservice.WorkflowServiceImpl.java
@Override public String reloadWorkflow(String processid) throws ServiceException { String result = "{\"success\":false}"; try {//www . j a v a 2s. c o m DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); String path = ConfigReader.getinstance().get("workflowpath") + processid; File fdir = new File(path); File file = new File(fdir + System.getProperty("file.separator") + "bpmn.xml"); Document doc = docBuilder.parse(file); int s; int a; String name = ""; ObjectInfo obj = new ObjectInfo(); ArrayList taskContainer = new ArrayList(); String nodeName = ""; NodeList nodeList = doc.getElementsByTagName("Pool"); for (s = 1; s < nodeList.getLength(); s++) { Node node = nodeList.item(s); ObjectInfo processObj = new ObjectInfo(); processObj.type = "process"; getNodeInfo(node, processObj); NodeList childrenList = node.getChildNodes(); for (int cnt = 0; cnt < childrenList.getLength(); cnt++) { node = childrenList.item(cnt); nodeName = node.getNodeName(); if (nodeName.compareToIgnoreCase("Lanes") == 0) { NodeList laneList = node.getChildNodes(); for (int laneCount = 0; laneCount < laneList.getLength(); laneCount++) { node = laneList.item(laneCount); nodeName = node.getNodeName(); if (nodeName.compareToIgnoreCase("Lane") == 0) { ObjectInfo laneObj = new ObjectInfo(); laneObj.type = "lane"; getNodeInfo(node, laneObj); NodeList laneChildren = node.getChildNodes(); for (int laneChildrencnt = 0; laneChildrencnt < laneChildren .getLength(); laneChildrencnt++) { node = laneChildren.item(laneChildrencnt); nodeName = node.getNodeName(); if (nodeName.compareToIgnoreCase("NodeGraphicsInfos") == 0) { getGraphicsNodeInfo(getActivityNode(node, 1), laneObj); } } taskContainer.add(laneObj); } } } else { if (nodeName.compareToIgnoreCase("NodeGraphicsInfos") == 0) { getGraphicsNodeInfo(getActivityNode(node, 1), processObj); } } } taskContainer.add(processObj); } nodeList = doc.getElementsByTagName("Activities"); for (s = 0; s < nodeList.getLength(); s++) { name = ""; Node node = nodeList.item(s); NodeList childrenList = node.getChildNodes(); for (int cnt = 0; cnt < childrenList.getLength(); cnt++) { node = childrenList.item(cnt); Node activityNode = getActivityNode(node, 0); if (activityNode.getNodeType() == Node.ELEMENT_NODE) { obj = new ObjectInfo(); obj.type = "activity"; getNodeInfo(activityNode, obj); Node graphicsInfoNode = getActivityNode(activityNode, 1); getGraphicsNodeInfo(graphicsInfoNode, obj); taskContainer.add(obj); } } } JSONObject jtemp = new com.krawler.utils.json.base.JSONObject(); for (int j = 0; j < taskContainer.size(); j++) { obj = (ObjectInfo) taskContainer.get(j); JSONObject jobj = new com.krawler.utils.json.base.JSONObject(); jobj.put("Id", obj.objId); jobj.put("name", obj.name); jobj.put("xpos", obj.xpos); jobj.put("ypos", obj.ypos); jobj.put("height", obj.height); jobj.put("width", obj.width); jobj.put("parent", obj.parentId); jobj.put("refId", obj.refId); jobj.put("hasStart", obj.hasStart); jobj.put("hasEnd", obj.hasEnd); jobj.put("startRefId", obj.startRefId); jobj.put("endRefId", obj.endRefId); jobj.put("derivationRule", obj.derivationRule); jobj.put("domEl", obj.domEl); if (obj.type.compareToIgnoreCase("activity") == 0) { jtemp.append("data", jobj); } else if (obj.type.compareToIgnoreCase("process") == 0) { jtemp.append("processes", jobj); } else if (obj.type.compareToIgnoreCase("lane") == 0) { jtemp.append("lanes", jobj); } } NodeList transitionList = doc.getElementsByTagName("Transitions"); for (int i = 0; i < transitionList.getLength(); i++) { Node node = transitionList.item(i); NodeList childrenList = node.getChildNodes(); for (int cnt = 0; cnt < childrenList.getLength(); cnt++) { node = childrenList.item(cnt); if (node.getNodeType() == Node.ELEMENT_NODE) { JSONObject jobj = new com.krawler.utils.json.base.JSONObject(); NamedNodeMap attr = node.getAttributes(); for (int b = 0; b < attr.getLength(); b++) { Node attribute = attr.item(b); name = attribute.getNodeName(); if (name.compareToIgnoreCase("From") == 0) { jobj.put("fromId", attribute.getNodeValue()); } else if (name.compareToIgnoreCase("To") == 0) { jobj.put("toId", attribute.getNodeValue()); } } jtemp.append("Lines", jobj); } } } return jtemp.toString(); } catch (ParserConfigurationException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } catch (SAXException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } catch (JSONException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } }
From source file:com.krawler.workflow.bizservice.WorkflowServiceImpl.java
public String importWorkflow(String processid) throws ServiceException { String result = "{\"success\":false}"; try {//from w w w. j ava2 s.c o m DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); String path = ConfigReader.getinstance().get("workflowpath") + processid; File fdir = new File(path); File file = new File(fdir + System.getProperty("file.separator") + "bpmn.xml"); Document doc = docBuilder.parse(file); int s; int a; String name = ""; ObjectInfo obj = new ObjectInfo(); HashMap<String, ObjectInfo> activityHm = new HashMap<String, ObjectInfo>(); NodeList nodeList = doc.getElementsByTagName("Activity"); for (s = 0; s < nodeList.getLength(); s++) { name = ""; Node node = nodeList.item(s); if (node.getNodeType() == Node.ELEMENT_NODE) { obj = new ObjectInfo(); obj.type = getNodeType(node); getNodeInfo(node, obj); if (obj.type.equals("activity")) { Node graphicsInfoNode = getActivityNode(node, 1); getGraphicsNodeInfo(graphicsInfoNode, obj); } activityHm.put(obj.objId, obj); } } NodeList transitionList = doc.getElementsByTagName("Transitions"); String fromId = ""; String toId = ""; ObjectInfo fromObj; ObjectInfo toObj; ObjectInfo tempObj; JSONObject jobj; JSONObject jtemp = new com.krawler.utils.json.base.JSONObject(); HashMap<String, String> fromConditionHm = new HashMap<String, String>(); MultiMap toConditionHm = new MultiHashMap(); for (int i = 0; i < transitionList.getLength(); i++) { Node node = transitionList.item(i); NodeList childrenList = node.getChildNodes(); for (int cnt = 0; cnt < childrenList.getLength(); cnt++) { node = childrenList.item(cnt); if (node.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap attr = node.getAttributes(); for (int b = 0; b < attr.getLength(); b++) { Node attribute = attr.item(b); name = attribute.getNodeName(); if (name.compareToIgnoreCase("From") == 0) { fromId = attribute.getNodeValue(); } else if (name.compareToIgnoreCase("To") == 0) { toId = attribute.getNodeValue(); } } fromObj = activityHm.get(fromId); toObj = activityHm.get(toId); if (fromObj.type.equals("start")) { tempObj = new ObjectInfo(); tempObj = activityHm.get(toId); tempObj.hasStart = "true"; activityHm.put(toId, tempObj); continue; } if (toObj.type.equals("end")) { tempObj = new ObjectInfo(); tempObj = activityHm.get(fromId); tempObj.hasEnd = "true"; activityHm.put(fromId, tempObj); continue; } if (fromObj.type.equals("activity") && toObj.type.equals("activity")) { jobj = new com.krawler.utils.json.base.JSONObject(); jobj.put("fromId", "flowPanel" + fromId); jobj.put("toId", "flowPanel" + toId); jtemp.append("Lines", jobj); tempObj = new ObjectInfo(); tempObj = activityHm.get(fromId); tempObj.derivationRule = "sequence"; activityHm.put(fromId, tempObj); continue; } if (fromObj.type.equals("activity") && toObj.type.equals("condition")) { fromConditionHm.put(toId, fromId); tempObj = new ObjectInfo(); tempObj = activityHm.get(fromId); tempObj.derivationRule = "evaluation"; activityHm.put(fromId, tempObj); continue; } if (fromObj.type.equals("condition") && toObj.type.equals("activity")) { toConditionHm.put(fromId, toId); continue; } } } } Set keys = activityHm.keySet(); Iterator ite = keys.iterator(); while (ite.hasNext()) { String key = (String) ite.next(); obj = new ObjectInfo(); obj = activityHm.get(key); if (obj.type.equals("activity")) { jobj = new com.krawler.utils.json.base.JSONObject(); jobj.put("Id", "flowPanel" + obj.objId); jobj.put("name", obj.name); jobj.put("xpos", obj.xpos); jobj.put("ypos", obj.ypos); jobj.put("height", obj.height); jobj.put("width", obj.width); jobj.put("parent", obj.parentId); jobj.put("refId", obj.refId); jobj.put("hasStart", obj.hasStart); jobj.put("hasEnd", obj.hasEnd); jobj.put("startRefId", obj.startRefId); jobj.put("endRefId", obj.endRefId); jobj.put("derivationRule", obj.derivationRule); jobj.put("domEl", obj.domEl); jtemp.append("data", jobj); } } keys = fromConditionHm.keySet(); ite = keys.iterator(); Iterator ite1 = null; String key = ""; while (ite.hasNext()) { key = (String) ite.next(); fromId = fromConditionHm.get(key); List toList = (List) toConditionHm.get(key); ite1 = toList.iterator(); while (ite1.hasNext()) { toId = (String) ite1.next(); jobj = new com.krawler.utils.json.base.JSONObject(); jobj.put("fromId", "flowPanel" + fromId); jobj.put("toId", "flowPanel" + toId); jtemp.append("Lines", jobj); } } return jtemp.toString(); } catch (ParserConfigurationException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } catch (SAXException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } catch (JSONException ex) { logger.warn(ex.getMessage(), ex); result = "{\"success\":false}"; throw ServiceException.FAILURE("workflow.reloadWorkflow", ex); } }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to parse the InkML string markup data identified by the inkmlStr given * /*from w ww .ja va2 s . c o m*/ * @param inkmlStr String markup data * @throws InkMLException */ public void parseInkMLString(final String inkmlStrParam) throws InkMLException { final String inkmlStr; if (inkmlStrParam.indexOf("ink") == -1) { // the given welformed inkmlStr does not contain complete <ink> document as string. // wrap it with a false root element, <inkMLFramgment>. It is called as fragment. inkmlStr = "<inkMLFramgment>" + inkmlStrParam + " </inkMLFramgment>"; } else { inkmlStr = inkmlStrParam; } InkMLDOMParser.LOG.fine(inkmlStr); try { final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setIgnoringComments(true); dbFactory.setIgnoringElementContentWhitespace(true); dbFactory.setValidating(false); InkMLDOMParser.LOG.info("Validation using schema is disabled."); final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); this.inkmlDOMDocument = dBuilder.parse(inkmlStr); this.bindData(this.inkMLProcessor.getInk()); } catch (final ParserConfigurationException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final SAXException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final IOException e) { throw new InkMLException("I/O error while parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to parse the InkML file identified by the inkmlFilename given in the parameter and creates data objects. It performs validation with schema. It * must have "ink" as root element with InkML name space specified with xmlns="http://www.w3.org/2003/InkML". The schema location may be specified. If it is * not specified or if relative path of the InkML.xsd file is specified, then the InkML.xsd file path must be added to * CLASSPATH for the parser to locate * it. An example of a typical header is, <ink xmlns="http://www.w3.org/2003/InkML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" * xsi:schemaLocation="http://www.w3.org/2003/InkML C:\project\schema\inkml.xsd"> * /* ww w. jav a2 s .c o m*/ * @param inkmlFileName * @throws InkMLException */ public void parseInkMLFile(final InputStream inputStream) throws InkMLException { // Get the DOM document object by parsing the InkML input file try { final InputSource input = new InputSource(inputStream); // get the DOM document object of the input InkML XML file. final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setIgnoringComments(true); dbFactory.setNamespaceAware(true); dbFactory.setIgnoringElementContentWhitespace(true); dbFactory.setValidating(false); if (this.isSchemaValidationEnabled()) { InkMLDOMParser.LOG.info("Validation using schema is enabled."); dbFactory.setSchema(this.schemaFactory .newSchema(new StreamSource(this.getClass().getResourceAsStream("/schema/inkml.xsd")))); } else { InkMLDOMParser.LOG.info("Validation using schema is disabled."); } final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); dBuilder.setErrorHandler(this); this.inkmlDOMDocument = dBuilder.parse(input); InkMLDOMParser.LOG.info("\nInput InkML XML file parsing is completed.\n"); this.inkMLProcessor.beginInkSession(); this.bindData(this.inkMLProcessor.getInk()); } catch (final ParserConfigurationException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final SAXException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final IOException e) { throw new InkMLException("I/O error while parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } }
From source file:DOMProcessor.java
/** Reads the XML from the given input stream and converts it into a DOM. * @param inStream Input stream containing XML to convert. * @return True if converted successfully. */// w w w . j a v a 2 s . c o m public boolean readXML(InputStream inStream) { // Create a DocumentBuilder using the DocumentBuilderFactory. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; indent = 0; try { db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { System.err.println("Problem finding an XML parser:\n" + e); return false; } // Try to parse the given file and store XML nodes in the DOM. try { dom = db.parse(inStream); } catch (SAXException e) { System.err.println("Problem parsing document: " + e.getMessage()); dom = db.newDocument(); return false; } catch (IOException e) { System.err.println("Problem reading from " + inStream); return false; } return true; }
From source file:DOMProcessor.java
/** Reads the given XML file and converts it into a DOM. * @param fileName Name of XML file to convert. * @return True if converted successfully. *//*from w w w . j a v a 2 s .co m*/ public boolean readXML(String fileName) { // Create a DocumentBuilder using the DocumentBuilderFactory. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; indent = 0; try { db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { System.err.println("Problem finding an XML parser:\n" + e); return false; } // Try to parse the given file and store XML nodes in the DOM. try { dom = db.parse(new File(fileName)); } catch (SAXException e) { System.err.println("Problem parsing document: " + e.getMessage()); dom = db.newDocument(); return false; } catch (IOException e) { System.err.println("Problem reading " + fileName); return false; } return true; }
From source file:net.pms.util.CoverArtArchiveUtil.java
private String getMBID(Tag tag, boolean externalNetwork) { if (tag == null) { return null; }//w w w .ja v a2 s . c om // No need to look up MBID if it's already in the tag String mBID = null; if (AudioUtils.tagSupportsFieldKey(tag, FieldKey.MUSICBRAINZ_RELEASEID)) { mBID = tag.getFirst(FieldKey.MUSICBRAINZ_RELEASEID); if (StringUtil.hasValue(mBID)) { return mBID; } } DocumentBuilder builder = null; try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { LOGGER.error("Error initializing XML parser: {}", e.getMessage()); LOGGER.trace("", e); return null; } final CoverArtArchiveTagInfo tagInfo = new CoverArtArchiveTagInfo(tag); if (!tagInfo.hasInfo()) { LOGGER.trace("Tag has no information - aborting search"); return null; } // Secure exclusive access to search for this tag CoverArtArchiveTagLatch latch = reserveTagLatch(tagInfo); if (latch == null) { // Couldn't reserve exclusive access, giving up LOGGER.error("Could not reserve tag latch for MBID search for \"{}\"", tagInfo); return null; } try { // Check if it's cached first MusicBrainzReleasesResult result = TableMusicBrainzReleases.findMBID(tagInfo); if (result.found) { if (StringUtil.hasValue(result.mBID)) { return result.mBID; } else if (System.currentTimeMillis() - result.modified.getTime() < expireTime) { // If a lookup has been done within expireTime and no result, // return null. Do another lookup after expireTime has passed return null; } } if (!externalNetwork) { LOGGER.warn("Can't look up cover MBID from MusicBrainz since external network is disabled"); LOGGER.info("Either enable external network or disable cover download"); return null; } /* * Rounds are defined as this: * * 1 - Exact release search * 2 - Fuzzy release search * 3 - Exact track search * 4 - Fuzzy track search * 5 - Give up */ int round; if (StringUtil.hasValue(tagInfo.album) || StringUtil.hasValue(tagInfo.artist) || StringUtil.hasValue(tagInfo.artistId)) { round = 1; } else { round = 3; } while (round < 5 && !StringUtil.hasValue(mBID)) { String query; if (round < 3) { query = buildMBReleaseQuery(tagInfo, round > 1); } else { query = buildMBRecordingQuery(tagInfo, round > 3); } if (query != null) { final String url = "http://musicbrainz.org/ws/2/" + query; if (LOGGER.isTraceEnabled()) { LOGGER.trace("Performing release MBID lookup at musicbrainz: \"{}\"", url); } try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestProperty("Accept-Charset", StandardCharsets.UTF_8.name()); int status = connection.getResponseCode(); if (status != 200) { LOGGER.error( "Could not lookup audio cover for \"{}\": musicbrainz.com replied with status code {}", tagInfo.title, status); return null; } Document document; try { document = builder.parse(connection.getInputStream()); } catch (SAXException e) { LOGGER.error("Failed to parse XML for \"{}\": {}", url, e.getMessage()); LOGGER.trace("", e); return null; } ArrayList<ReleaseRecord> releaseList; if (round < 3) { releaseList = parseRelease(document, tagInfo); } else { releaseList = parseRecording(document, tagInfo); } if (releaseList != null && !releaseList.isEmpty()) { // Try to find the best match - this logic can be refined if // matching quality turns out to be to low int maxScore = 0; for (ReleaseRecord release : releaseList) { if (StringUtil.hasValue(tagInfo.artist)) { boolean found = false; for (String s : release.artists) { if (s.equalsIgnoreCase(tagInfo.artist)) { found = true; break; } } if (found) { release.score += 30; } } if (StringUtil.hasValue(tagInfo.album)) { if (release.type == ReleaseType.Album) { release.score += 20; if (release.title.equalsIgnoreCase(tagInfo.album)) { release.score += 30; } } } else if (StringUtil.hasValue(tagInfo.title)) { if ((round > 2 || release.type == ReleaseType.Single) && release.title.equalsIgnoreCase(tagInfo.title)) { release.score += 40; } } if (StringUtil.hasValue(tagInfo.year) && StringUtil.hasValue(release.year)) { if (tagInfo.year.equals(release.year)) { release.score += 20; } } maxScore = Math.max(maxScore, release.score); } for (ReleaseRecord release : releaseList) { if (release.score == maxScore) { mBID = release.id; break; } } } if (StringUtil.hasValue(mBID)) { LOGGER.trace("Music release \"{}\" found with \"{}\"", mBID, url); } else { LOGGER.trace("No music release found with \"{}\"", url); } } catch (IOException e) { LOGGER.debug("Failed to find MBID for \"{}\": {}", query, e.getMessage()); LOGGER.trace("", e); return null; } } round++; } if (StringUtil.hasValue(mBID)) { LOGGER.debug("MusicBrainz release ID \"{}\" found for \"{}\"", mBID, tagInfo); TableMusicBrainzReleases.writeMBID(mBID, tagInfo); return mBID; } else { LOGGER.debug("No MusicBrainz release found for \"{}\"", tagInfo); TableMusicBrainzReleases.writeMBID(null, tagInfo); return null; } } finally { releaseTagLatch(latch); } }
From source file:de.interactive_instruments.ShapeChange.ShapeChangeResult.java
public ShapeChangeResult(Options o) { init();/*from w ww . j a v a 2 s . c om*/ options = o; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(Options.JAXP_SCHEMA_LANGUAGE, Options.W3C_XML_SCHEMA); DocumentBuilder db = dbf.newDocumentBuilder(); document = db.newDocument(); root = document.createElementNS(Options.SCRS_NS, "ShapeChangeResult"); document.appendChild(root); root.setAttribute("resultCode", "0"); root.setAttribute("xmlns:r", Options.SCRS_NS); root.setAttribute("start", (new Date()).toString()); String version = "[dev]"; InputStream stream = getClass().getResourceAsStream("/sc.properties"); if (stream != null) { Properties properties = new Properties(); properties.load(stream); version = properties.getProperty("sc.version"); } root.setAttribute("version", version); messages = document.createElementNS(Options.SCRS_NS, "Messages"); root.appendChild(messages); resultFiles = document.createElementNS(Options.SCRS_NS, "Results"); root.appendChild(resultFiles); } catch (ParserConfigurationException e) { System.err.println("Bootstrap Error: XML parser was unable to be configured."); String m = e.getMessage(); if (m != null) { System.err.println(m); } e.printStackTrace(System.err); System.exit(1); } catch (Exception e) { System.err.println("Bootstrap Error: " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } outputFormat.setProperty("encoding", "UTF-8"); outputFormat.setProperty("indent", "yes"); outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount", "2"); }
From source file:com.silverwrist.venice.core.impl.ConferencingImporter.java
final List importMessages(InputStream xmlstm) throws DataException { try { // create a SAX parser and let it loose on the input data with our listener SAXParserFactory fact = SAXParserFactory.newInstance(); fact.setNamespaceAware(false);//w w w . j a v a 2 s.c o m fact.setValidating(false); SAXParser parser = fact.newSAXParser(); parser.parse(xmlstm, new Listener()); } // end try catch (ParserConfigurationException e) { // configuration error throw new DataException("Error configuring XML parser for message import: " + e.getMessage(), e); } // end catch catch (SAXException e) { // give an error message throw new DataException("Error importing messages: " + e.getMessage(), e); } // end catch catch (IOException e) { // I/O error in parsing! throw new DataException("Error importing messages: " + e.getMessage(), e); } // end catch if (m_events == null) return Collections.EMPTY_LIST; ArrayList rc = new ArrayList(m_events); m_events = null; return Collections.unmodifiableList(rc); }
From source file:ch.entwine.weblounge.contentrepository.impl.AbstractContentRepository.java
/** * Iterates over the existing image styles and determines whether at least one * style has changed or is missing the previews. * //from w w w. j ava2 s .co m * @throws ContentRepositoryException * if preview generation fails */ protected void updatePreviews() throws ContentRepositoryException { // Compile the full list of image styles if (imageStyleTracker == null) { logger.info("Skipping preview generation: image styles are unavailable"); return; } final List<ImageStyle> allStyles = new ArrayList<ImageStyle>(); // Add the global image styles that have the preview flag turned on for (ImageStyle s : imageStyleTracker.getImageStyles()) { allStyles.add(s); } // Add the site's preview image styles as well as for (Module m : getSite().getModules()) { for (ImageStyle s : m.getImageStyles()) { allStyles.add(s); } } // Check whether the image styles still match the current definition. If // not, remove the produced previews and recreate them. boolean styleHasChanged = false; boolean styleIsMissing = false; for (ImageStyle s : allStyles) { File baseDir = ImageStyleUtils.getDirectory(site, s); File definitionFile = new File(baseDir, "style.xml"); // Try and read the file on disk if (definitionFile.isFile()) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; Document doc; ImageStyle style; try { docBuilder = docBuilderFactory.newDocumentBuilder(); doc = docBuilder.parse(definitionFile); style = ImageStyleImpl.fromXml(doc.getFirstChild()); // Is the style still the same? boolean stylesMatch = s.getWidth() == style.getWidth(); stylesMatch = stylesMatch && s.getHeight() == style.getHeight(); stylesMatch = stylesMatch && s.getScalingMode().equals(style.getScalingMode()); stylesMatch = stylesMatch && s.isPreview() == style.isPreview(); styleHasChanged = styleHasChanged || !stylesMatch; } catch (ParserConfigurationException e) { logger.error("Error setting up image style parser: {}", e.getMessage()); } catch (SAXException e) { logger.error("Error parsing image style {}: {}", definitionFile, e.getMessage()); } catch (IOException e) { logger.error("Error reading image style {}: {}", definitionFile, e.getMessage()); } } else { if (s.isPreview()) { logger.debug("No previews found for image style '{}'", s.getIdentifier()); styleIsMissing = true; } } // The current definition is no longer valid if (styleHasChanged) { logger.info("Image style '{}' has changed, removing existing previews from {}", s.getIdentifier(), baseDir); FileUtils.deleteQuietly(baseDir); if (!baseDir.mkdirs()) { logger.error("Error creating image style directory {}", baseDir); continue; } } // Store the new definition if (!definitionFile.isFile() || styleHasChanged) { try { definitionFile.getParentFile().mkdirs(); definitionFile.createNewFile(); FileUtils.copyInputStreamToFile(IOUtils.toInputStream(s.toXml(), "UTF-8"), definitionFile); } catch (IOException e) { logger.error("Error creating image style defintion file at {}", definitionFile, e.getMessage()); continue; } } else { logger.debug("Image style {} still matching the current definition", s.getIdentifier()); } } if (styleHasChanged || styleIsMissing) { if (environment.equals(Development)) { logger.info( "Missing or outdated previews found. Skipping preview generation for current environment 'development'"); return; } logger.info("Triggering creation of missing and outdated previews"); createPreviews(); } else { logger.debug("Preview images for {} are still up to date", site.getIdentifier()); } }