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()));
}
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;
}
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);
}
}
};
}
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);
}
}
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);
}
}
Aggregations