Search in sources :

Example 16 with SAXException

use of org.xml.sax.SAXException in project tomcat by apache.

the class JasperInitializer method onStartup.

@Override
public void onStartup(Set<Class<?>> types, ServletContext context) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug(Localizer.getMessage(MSG + ".onStartup", context.getServletContextName()));
    }
    // Setup a simple default Instance Manager
    if (context.getAttribute(InstanceManager.class.getName()) == null) {
        context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    }
    boolean validate = Boolean.parseBoolean(context.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
    String blockExternalString = context.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }
    // scan the application for TLDs
    TldScanner scanner = newTldScanner(context, true, validate, blockExternal);
    try {
        scanner.scan();
    } catch (IOException | SAXException e) {
        throw new ServletException(e);
    }
    // add any listeners defined in TLDs
    for (String listener : scanner.getListeners()) {
        context.addListener(listener);
    }
    context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME, new TldCache(context, scanner.getUriTldResourcePathMap(), scanner.getTldResourcePathTaglibXmlMap()));
}
Also used : ServletException(javax.servlet.ServletException) TldCache(org.apache.jasper.compiler.TldCache) InstanceManager(org.apache.tomcat.InstanceManager) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) IOException(java.io.IOException) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) SAXException(org.xml.sax.SAXException)

Example 17 with SAXException

use of org.xml.sax.SAXException in project checkstyle by checkstyle.

the class XmlUtil method getRawXml.

public static Document getRawXml(String fileName, String code, String unserializedSource) throws ParserConfigurationException {
    try {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        factory.setNamespaceAware(true);
        final DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new InputSource(new StringReader(code)));
    } catch (IOException | SAXException ex) {
        Assert.fail(fileName + " has invalid xml (" + ex.getMessage() + "): " + unserializedSource);
    }
    return null;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 18 with SAXException

use of org.xml.sax.SAXException in project cogtool by cogtool.

the class ProjectController method createPasteAction.

// Action for Paste
protected IListenerAction createPasteAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            try {
                // Check for CogTool objects to paste
                Collection<Object> objects = CogToolClipboard.fetchCogToolObjects(project);
                // designs and tasks only
                int numObjectsPasted = 0;
                if ((objects != null) && (objects.size() > 0)) {
                    // Paste tasks as children of the selected TaskGroup
                    AUndertaking[] selectedTasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
                    TaskGroup taskParent = seln.getSelectedTaskParent();
                    int index;
                    // index at which new pasted Tasks will be placed.
                    if (taskParent != null) {
                        AUndertaking last = selectedTasks[selectedTasks.length - 1];
                        index = taskParent.getUndertakings().indexOf(last) + 1;
                    } else {
                        index = findLastSelectedRoot(selectedTasks);
                    }
                    // Create undo support
                    String presentationName = PASTE;
                    CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.Paste);
                    // If task applications are pasted, they will have
                    // null Design fields; they should "arrive" after
                    // the Design being pasted at the same time!
                    Design newDesign = null;
                    // Existing tasks are to be re-used if the paste
                    // is within the same project as the copy/cut.
                    Map<AUndertaking, AUndertaking> reuseTasks = null;
                    Iterator<Object> objIt = objects.iterator();
                    while (objIt.hasNext()) {
                        Object o = objIt.next();
                        // unique name and create and place the design.
                        if (o instanceof Design) {
                            newDesign = (Design) o;
                            makeDesignNameUnique(newDesign);
                            // Add an undo step after creating/placing
                            ProjectCmd.addNewDesign(project, newDesign, seln.getSelectedDesign(), presentationName, editSeq);
                            numObjectsPasted++;
                        } else // or to the Project.  Create and place.
                        if (o instanceof AUndertaking) {
                            AUndertaking task = (AUndertaking) o;
                            // project or pasting copied tasks
                            if (reuseTasks == null) {
                                pasteTask(task, taskParent, index++, editSeq, presentationName);
                                numObjectsPasted++;
                            } else {
                                // In this case, a copied design is
                                // being pasted into the same project.
                                // Map each undertaking to the
                                // corresponding one in the current project
                                mapProjectTasks(task, project, reuseTasks, editSeq, presentationName);
                            }
                        } else // along when copying an Design.
                        if (o instanceof TaskApplication) {
                            TaskApplication taskApp = (TaskApplication) o;
                            if (reuseTasks != null) {
                                AUndertaking reuseTask = reuseTasks.get(taskApp.getTask());
                                if (reuseTask != null) {
                                    taskApp.setTask(reuseTask);
                                }
                            }
                            // The undo edit for adding the Design will
                            // remove and restore the task-applications;
                            // simply add to the project.
                            project.setTaskApplication(taskApp);
                        } else if (o instanceof CogToolClipboard.ProjectScope) {
                            CogToolClipboard.ProjectScope projectScope = (CogToolClipboard.ProjectScope) o;
                            // a copied design into the same project
                            if (projectScope.getProject() != null) {
                                reuseTasks = new HashMap<AUndertaking, AUndertaking>();
                            }
                        }
                    }
                    // Done with undo/redo steps; add the compound change
                    // to the undo manager.
                    editSeq.end();
                    undoMgr.addEdit(editSeq);
                    interaction.setStatusMessage(numObjectsPasted + " " + pasteComplete);
                } else {
                    interaction.setStatusMessage(nothingPasted);
                }
                return true;
            } catch (IOException e) {
                throw new RcvrClipboardException(e);
            } catch (SAXException e) {
                throw new RcvrClipboardException(e);
            } catch (ParserConfigurationException e) {
                throw new RcvrClipboardException(e);
            } catch (ClipboardUtil.ClipboardException e) {
                throw new RcvrClipboardException(e);
            }
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) HashMap(java.util.HashMap) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SAXException(org.xml.sax.SAXException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ClipboardUtil(edu.cmu.cs.hcii.cogtool.util.ClipboardUtil) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 19 with SAXException

use of org.xml.sax.SAXException in project checkstyle by checkstyle.

the class PackageNamesLoaderTest method testPackagesWithSaxException.

@Test
@SuppressWarnings("unchecked")
public void testPackagesWithSaxException() throws Exception {
    final URLConnection mockConnection = Mockito.mock(URLConnection.class);
    when(mockConnection.getInputStream()).thenReturn(new ByteArrayInputStream(EMPTY_BYTE_ARRAY));
    final URL url = getMockUrl(mockConnection);
    final Enumeration<URL> enumeration = mock(Enumeration.class);
    when(enumeration.hasMoreElements()).thenReturn(true);
    when(enumeration.nextElement()).thenReturn(url);
    final ClassLoader classLoader = mock(ClassLoader.class);
    when(classLoader.getResources("checkstyle_packages.xml")).thenReturn(enumeration);
    try {
        PackageNamesLoader.getPackageNames(classLoader);
        fail("CheckstyleException is expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getCause() instanceof SAXException);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) URLConnection(java.net.URLConnection) URL(java.net.URL) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 20 with SAXException

use of org.xml.sax.SAXException in project cogtool by cogtool.

the class BalsamiqButtonAPIConverter method parseBalsamiqFile.

/** Helper function used by importDesign.
	 * This method is used to parse the tags of each .bmml file in the 
	 * directory. The file represents a {@link File} in the directory.
     * 
     * @param  inputFile the specified directory or file
     * @see              the new design in the project window.
     */
public void parseBalsamiqFile(File inputFile) throws IOException {
    String fileName = inputFile.getName();
    int lastIndex = fileName.lastIndexOf(".");
    fileName = (lastIndex == -1) ? fileName : fileName.substring(0, lastIndex);
    /* Check to make sure that this frame has not been created yet. Cycles 
		 * by transitions may exist in the design and these files do not need 
		 * to be parsed more than once. */
    if (!visitedFramesNames.contains(fileName)) {
        visitedFramesNames.add(fileName);
        // Create a Xerces DOM Parser. A DOM Parser can parse an XML file
        // and create a tree representation of it. This same parser method
        // is used in ImportCogTool.java to import from CogTool XML.
        DOMParser parser = new DOMParser();
        InputStream fis = new FileInputStream(inputFile);
        Reader input = new InputStreamReader(fis, "UTF-8");
        // Parse the Document and traverse the DOM
        try {
            parser.parse(new InputSource(input));
        } catch (SAXException e) {
            throw new RcvrImportException("Not a valid XML file to parse.");
        }
        //Traverse the xml tags in the tree beginning at the root, the document
        Document document = parser.getDocument();
        parseFrame(document, fileName);
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) DOMParser(com.sun.org.apache.xerces.internal.parsers.DOMParser) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)1084 IOException (java.io.IOException)653 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)387 Document (org.w3c.dom.Document)258 DocumentBuilder (javax.xml.parsers.DocumentBuilder)213 InputSource (org.xml.sax.InputSource)205 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)158 InputStream (java.io.InputStream)141 Element (org.w3c.dom.Element)115 File (java.io.File)109 NodeList (org.w3c.dom.NodeList)106 SAXParseException (org.xml.sax.SAXParseException)104 Node (org.w3c.dom.Node)91 StringReader (java.io.StringReader)83 TransformerException (javax.xml.transform.TransformerException)82 ByteArrayInputStream (java.io.ByteArrayInputStream)81 SAXParser (javax.xml.parsers.SAXParser)76 ArrayList (java.util.ArrayList)71 FileInputStream (java.io.FileInputStream)64 XMLReader (org.xml.sax.XMLReader)56