List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:org.sakaiproject.tool.assessment.qti.asi.Section.java
/** * add section ref//from w w w. ja v a 2 s . c o m * * @param sectionId section id */ public void addSectionRef(String sectionId) { if (log.isDebugEnabled()) { log.debug("addSection(String " + sectionId + ")"); } try { String xpath = basePath; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.newDocument(); Element element = document.createElement(QTIConstantStrings.SECTIONREF); element.setAttribute(QTIConstantStrings.LINKREFID, sectionId); this.addElement(xpath, element); } catch (ParserConfigurationException pce) { log.error("Exception thrown from addSectionRef() : " + pce.getMessage()); pce.printStackTrace(); } }
From source file:org.sakaiproject.tool.assessment.qti.helper.assessment.AssessmentHelperBase.java
/** * Read in assessment XML from input stream * * @param inputStream XML input stream/* w w w . jav a 2s . c o m*/ * * @return assessment XML */ public Assessment readXMLDocument(InputStream inputStream) { if (log.isDebugEnabled()) { log.debug("readDocument(InputStream " + inputStream); } Assessment assessXml = null; try { AuthoringHelper authoringHelper = new AuthoringHelper(getQtiVersion()); assessXml = new Assessment(authoringHelper.readXMLDocument(inputStream).getDocument()); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); } catch (SAXException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } return assessXml; }
From source file:org.sakaiproject.tool.assessment.qti.helper.AuthoringHelper.java
/** * Create an XmlStringBuffer (base class for A,S,I XML classes) * * @param inputStream the input stram// w w w . ja v a 2 s. c o m * * @return an XmlStringBuffer (this is the base class for A,S,I XML classes) */ public XmlStringBuffer readXMLDocument(InputStream inputStream) { Document document = null; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); // builderFactory.setNamespaceAware(true); try { DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); document = documentBuilder.parse(inputStream); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); } catch (SAXException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } return new XmlStringBuffer(document); }
From source file:org.sakaiproject.tool.assessment.qti.helper.AuthoringXml.java
/** * read in XML document from input stream * @param inputStream source for XML document * @return the Document/* w ww .j a va 2s .co m*/ */ public Document readXMLDocument(InputStream inputStream) { if (log.isDebugEnabled()) { log.debug("readDocument(InputStream " + inputStream); } Document document = null; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); try { DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); document = documentBuilder.newDocument(); document = documentBuilder.parse(inputStream); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); } catch (SAXException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } return document; }
From source file:org.sakaiproject.tool.assessment.qti.helper.item.ItemHelperBase.java
/** * Read an item XML document from a stream into an Item XML object * * @param inputStream XML document stream * * @return an Item XML object// ww w . j av a2s .c om */ public Item readXMLDocument(InputStream inputStream) { if (log.isDebugEnabled()) { log.debug("readDocument(InputStream " + inputStream); } Item itemXml = null; try { AuthoringHelper authoringHelper = new AuthoringHelper(getQtiVersion()); itemXml = new Item(authoringHelper.readXMLDocument(inputStream).getDocument(), getQtiVersion()); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); } catch (SAXException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } return itemXml; }
From source file:org.sakaiproject.tool.assessment.qti.helper.section.SectionHelperBase.java
/** * Read a Section XML object from a stream * * @param inputStream the stream/* www . ja v a2 s. c om*/ * * @return the section */ public Section readXMLDocument(InputStream inputStream) { if (log.isDebugEnabled()) { log.debug("readDocument(InputStream " + inputStream); } Section sectionXml = null; try { AuthoringHelper authoringHelper = new AuthoringHelper(getQtiVersion()); sectionXml = new Section(authoringHelper.readXMLDocument(inputStream).getDocument(), getQtiVersion()); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); } catch (SAXException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } return sectionXml; }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java
/** * parse the content/*from w ww.ja v a 2 s.c o m*/ * * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ private final void parseContent() throws ParserConfigurationException, SAXException, IOException { if (log.isDebugEnabled()) { log.debug("parseContent()"); } this.clearCache(); DocumentBuilderFactory dbfi = null; DocumentBuilder builder = null; StringReader sr = null; org.xml.sax.InputSource is = null; try { dbfi = DocumentBuilderFactory.newInstance(); builder = dbfi.newDocumentBuilder(); String s = this.xml.toString(); if (s == null) { log.warn("string value null"); s = ""; } sr = new StringReader(s); is = new org.xml.sax.InputSource(sr); this.document = builder.parse(is); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); throw e; } catch (SAXException e) { log.error(e.getMessage(), e); log.error("DocumentBuilderFactory dbfi = " + dbfi); log.error("StringReader sr = " + sr); log.error("InputSource is = " + is); log.error("StringBuffer xml = " + this.xml); throw e; } catch (IOException e) { log.error(e.getMessage(), e); throw e; } }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java
/** * get nodes//from w w w . j a va 2 s .c o m * * @param xpath * * @return list of nodes */ public final List selectNodes(String xpath) { if (log.isDebugEnabled()) { log.debug("selectNodes(String " + xpath + ")"); } List result = null; try { XPath path = new DOMXPath(xpath); result = path.selectNodes(this.getDocument()); } catch (JaxenException je) { log.error(je.getMessage(), je); } catch (ParserConfigurationException e) { log.error(e.getMessage(), e); } catch (SAXException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } if (result == null) { result = new ArrayList(); } return result; }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java
/** * insert element// ww w .j a v a 2s .c o m * * @param afterNode * @param parentXpath * @param childXpath */ public void insertElement(String afterNode, String parentXpath, String childXpath) { try { String nextXpath = parentXpath + "/" + afterNode; //************************************************************* DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.newDocument(); Element element = document.createElement(childXpath); //************************************************************** Element parent = null; List parentNodes = this.selectNodes(parentXpath); Iterator iteratorNext = parentNodes.iterator(); while (iteratorNext.hasNext()) { parent = (Element) iteratorNext.next(); } if (parent != null) { List nodes = this.selectNodes(nextXpath); Iterator iterator = nodes.iterator(); Element nextSibling = null; while (iterator.hasNext()) { nextSibling = (Element) iterator.next(); } if ((nextSibling != null) && !nextSibling.getOwnerDocument().equals(element.getOwnerDocument())) { element = (Element) parent.getOwnerDocument().importNode(element, true); parent.insertBefore(element, nextSibling); } } } catch (ParserConfigurationException pce) { log.error("Exception thrown from insertElement() : " + pce.getMessage()); pce.printStackTrace(); } }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java
/** * create child/*from w w w . ja v a 2 s . c o m*/ * * @param childXpath * * @return */ protected final Element createChildElement(String childXpath) { int index = childXpath.indexOf("/"); String elementName = childXpath; String subChildXpath = null; Element element = null; Element child = null; if (index > 0) { elementName = childXpath.substring(0, index); subChildXpath = childXpath.substring(index + 1); child = createChildElement(subChildXpath); } try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.newDocument(); element = document.createElement(elementName); if (child != null) { Node importedNode = document.importNode(child, true); element.appendChild(importedNode); } } catch (ParserConfigurationException pce) { log.error("Exception thrown from createChildElement(): " + pce.getMessage()); pce.printStackTrace(); } return element; }