use of org.xml.sax.SAXException in project checkstyle by checkstyle.
the class PackageNamesLoader method getPackageNames.
/**
* Returns the set of package names, compiled from all
* checkstyle_packages.xml files found on the given class loaders
* classpath.
* @param classLoader the class loader for loading the
* checkstyle_packages.xml files.
* @return the set of package names.
* @throws CheckstyleException if an error occurs.
*/
public static Set<String> getPackageNames(ClassLoader classLoader) throws CheckstyleException {
final Set<String> result;
try {
//create the loader outside the loop to prevent PackageObjectFactory
//being created anew for each file
final PackageNamesLoader namesLoader = new PackageNamesLoader();
final Enumeration<URL> packageFiles = classLoader.getResources(CHECKSTYLE_PACKAGES);
while (packageFiles.hasMoreElements()) {
final URL packageFile = packageFiles.nextElement();
InputStream stream = null;
try {
stream = new BufferedInputStream(packageFile.openStream());
final InputSource source = new InputSource(stream);
namesLoader.parseInputSource(source);
} catch (IOException ex) {
throw new CheckstyleException("unable to open " + packageFile, ex);
} finally {
Closeables.closeQuietly(stream);
}
}
result = namesLoader.packageNames;
} catch (IOException ex) {
throw new CheckstyleException("unable to get package file resources", ex);
} catch (ParserConfigurationException | SAXException ex) {
throw new CheckstyleException("unable to open one of package files", ex);
}
return result;
}
use of org.xml.sax.SAXException in project cogtool by cogtool.
the class ObjectPersister method load.
// registerForPersistence
/**
* Load an Object from a file. This method assumes that all error checking
* and prompting/correction for the validity of the file has already
* been completed.
*
* @param src the File location of the saved Object
* @return a new instantiated Object
* @throws java.io.IOException if any file operation fails or the SAX XML
* parser fails
*/
public Object load(File src) throws IOException {
// See if an object is already loaded for the given file
String canonicalFileName = src.getCanonicalPath();
PersistInfo info = getInfoByName(canonicalFileName);
if (info != null) {
return info.obj;
}
// Attempt to create a file of 3x size in the temp directory
// to hold the expanded XML serialization.
File sizeCheckFile = File.createTempFile(tmpFilePrefix, ".size", tmpDir);
try {
checkDiskSpace(sizeCheckFile, 3 * src.length(), "Not enough temp space on disk to open file: " + src);
} finally {
sizeCheckFile.delete();
}
// If we're here, no exception was thrown; create checkpoint directory
File chkptFile = createTempDirectory();
// Open file as ZipFile and decompress
ZipFile zip = null;
try {
zip = new ZipFile(src);
// Unzip the file to the checkpoint directory
ZipUtil.unzip(zip, chkptFile);
} catch (ZipException ex) {
IOException newE = new IOException("load encountered zip compression error");
newE.initCause(ex);
throw newE;
} finally {
if (zip != null) {
zip.close();
}
}
// Load object from the expanded XML serialization
ObjectLoader l = new ObjectLoader();
Object obj = null;
Reader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(new File(chkptFile, PERSIST_FILE)), "UTF-8");
Collection<?> objSet = l.load(new InputSource(reader), null);
// There should be only one top-level object
Iterator<?> objs = objSet.iterator();
if (objs.hasNext()) {
obj = objs.next();
}
// Register this file for future lookup, both by object
// and by file name
info = new PersistInfo(obj, chkptFile, src);
objInfos.put(obj, info);
fileInfos.put(canonicalFileName, info);
} catch (ParserConfigurationException e) {
IOException newE = new IOException("load encountered parser error");
newE.initCause(e);
throw newE;
} catch (SAXException e) {
IOException newE = new IOException("load encountered SAX error");
newE.initCause(e);
throw newE;
} finally {
if (reader != null) {
reader.close();
}
}
return obj;
}
use of org.xml.sax.SAXException in project cogtool by cogtool.
the class DesignEditorController method createPasteAction.
protected IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(L10N.get("UNDO.Paste", "Paste"), DesignEditorLID.Paste);
Set<DeviceType> devTypes = design.getDeviceTypes();
int numPasted = 0;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof Frame) {
Frame frame = (Frame) o;
makeFrameNameUnique(frame);
// Find an unoccupied starting position
// by cascading.
DoublePoint origin = frame.getFrameOrigin();
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
// Union devices
Iterator<InputDevice> frameDevices = frame.getInputDevices().iterator();
while (frameDevices.hasNext()) {
InputDevice inputDevice = frameDevices.next();
DeviceType devType = inputDevice.getDeviceType();
if (!devTypes.contains(devType)) {
DesignCmd.addDevice(design, devType);
}
}
Iterator<DeviceType> designDevTypes = devTypes.iterator();
while (designDevTypes.hasNext()) {
DeviceType devType = designDevTypes.next();
if (frame.getInputDevice(devType) == null) {
frame.addInputDevice(devType);
}
}
addFrame(frame, editSequence);
numPasted++;
} else if (o instanceof Transition) {
Transition t = (Transition) o;
DeviceType device = t.getAction().getDefaultDeviceType();
if (!devTypes.contains(device)) {
DesignCmd.addDevice(design, device);
}
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
numPasted++;
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return true;
}
};
}
use of org.xml.sax.SAXException in project cogtool by cogtool.
the class FrameEditorController method createPasteAction.
// createSetFrameTemplateAction
/**
* The paste action for inserting copied information.
* Currently no checks are made to ensure that the paste is valid XML.
* @return
*/
private IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
if (CogToolClipboard.hasCogToolObjects()) {
// Get the XML text from the clipboard
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PASTE, FrameEditorLID.Paste);
int numPasted = DesignEditorCmd.pasteElements(design, model, objects, demoStateMgr, editSequence);
if (numPasted > 0) {
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
}
return true;
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return false;
}
};
}
use of org.xml.sax.SAXException in project darkFunction-Editor by darkFunction.
the class JarvWriter method checkSchema.
/// TODO: Change exception type
private void checkSchema() throws IOException {
if (this.tag == null) {
return;
}
// should use this.namespace
try {
verifierHandler.startElement(getDefaultNamespace(), this.tag, this.tag, attrs);
if (this.text != null) {
verifierHandler.characters(this.text.toCharArray(), 0, this.text.length());
}
verifierHandler.endElement(getDefaultNamespace(), this.tag, this.tag);
} catch (SAXException se) {
throw new IOException("Need to wrap the SAX exception in start element: " + se);
}
this.attrs.clear();
this.tag = null;
this.text = null;
}
Aggregations