use of javax.xml.parsers.ParserConfigurationException 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 javax.xml.parsers.ParserConfigurationException 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 javax.xml.parsers.ParserConfigurationException in project android_frameworks_base by AOSPA.
the class OMAParser method parse.
public MOTree parse(String text, String urn) throws IOException, SAXException {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new InputSource(new StringReader(text)), this);
return new MOTree(mRoot, urn);
} catch (ParserConfigurationException pce) {
throw new SAXException(pce);
}
}
use of javax.xml.parsers.ParserConfigurationException in project GNS by MobilityFirst.
the class HostConfigParser method parseFile.
private void parseFile(String filename) throws HostConfigParseException {
String confPath = getConfPath();
if (confPath == null) {
return;
}
Document doc = null;
try {
InputStream is = Files.newInputStream(Paths.get(confPath, folder, filename + fileExtension));
//InputStream is = ClassLoader.getSystemResourceAsStream(filename + ".xml");
//File fXmlFile = new File(filename);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(is);
} catch (IOException | ParserConfigurationException | SAXException e) {
throw new HostConfigParseException("Problem creating XML document " + e);
}
// //optional, but recommended
// //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
// doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("host");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String idString = eElement.getAttribute(ID);
String hostname = eElement.getAttribute(HOSTNAME);
String latString = eElement.getAttribute(LAT);
String lonString = eElement.getAttribute(LON);
if (idString.isEmpty() || hostname.isEmpty()) {
throw new HostConfigParseException("Missing id or hostname attribute!");
}
//int id = Integer.parseInt(idString);
Point2D location = null;
if (!lonString.isEmpty() && !latString.isEmpty()) {
location = new Point2D.Double(Double.parseDouble(lonString), Double.parseDouble(latString));
}
if (location == null) {
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(hostname);
} catch (UnknownHostException e) {
throw new HostConfigParseException("Problem looking up IP address " + e);
}
String ip = inetAddress.getHostAddress();
// and take a guess at the location (lat, long) of this host
location = GEOLocator.lookupIPLocation(ip);
}
hosts.add(new HostInfo(idString, hostname, location));
}
}
keyname = getSingleElementAttribute(doc, KEYNAME, "name");
username = getSingleElementAttribute(doc, USERNAME, "name");
hostType = getSingleElementAttribute(doc, HOSTTYPE, "name");
installPath = getSingleElementAttribute(doc, INSTALLPATH, "name");
// if last character is a / remove it
if (installPath != null && !installPath.isEmpty()) {
installPath = installPath.trim();
if (installPath.endsWith(System.getProperty("file.separator"))) {
installPath = installPath.substring(0, installPath.length() - 1);
}
}
String dataStoreTypeName = getSingleElementAttribute(doc, DATASTORE, "name");
if (username == null) {
// for backwards compatibility
username = getSingleElementAttribute(doc, USERNAME_OLD, "name");
if (username != null) {
System.out.println("!!!Use of deprecated element tag " + USERNAME_OLD + ". Fix this!!!");
}
}
if (keyname == null || username == null || hostType == null || dataStoreTypeName == null) {
throw new HostConfigParseException("Missing " + KEYNAME + " or " + USERNAME + " or " + HOSTTYPE + " or " + DATASTORE + " tag");
}
dataStoreType = DataStoreType.valueOf(dataStoreTypeName);
}
use of javax.xml.parsers.ParserConfigurationException in project intellij-community by JetBrains.
the class ImportedToGeneralTestEventsConverter method parseTestResults.
public static void parseTestResults(Reader reader, final DefaultHandler contentHandler) throws IOException {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new InputSource(reader), contentHandler);
} catch (ParserConfigurationException | SAXException e) {
throw new IOException(e);
} finally {
reader.close();
}
}
Aggregations