List of usage examples for javax.xml.parsers DocumentBuilderFactory setIgnoringElementContentWhitespace
public void setIgnoringElementContentWhitespace(boolean whitespace)
From source file:gov.nasa.ensemble.core.jscience.csvxml.ProfileLoader.java
private Document loadColumnDefinitions(InputStream stream) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); docBuilderFactory.setIgnoringComments(true); docBuilderFactory.setIgnoringElementContentWhitespace(true); CensoringInputStream fileContentsWithoutCsv = new CensoringInputStream(stream); Document document = docBuilder.parse(new InputSource(fileContentsWithoutCsv)); nCharactersPrecedingData = fileContentsWithoutCsv.getNCharactersPrecedingData(); return document; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to parse the InkML string markup data identified by the inkmlStr given * // w ww . jav a2s .com * @param inkmlStr String markup data * @throws InkMLException */ public void parseInkMLString(final String inkmlStrParam) throws InkMLException { final String inkmlStr; if (inkmlStrParam.indexOf("ink") == -1) { // the given welformed inkmlStr does not contain complete <ink> document as string. // wrap it with a false root element, <inkMLFramgment>. It is called as fragment. inkmlStr = "<inkMLFramgment>" + inkmlStrParam + " </inkMLFramgment>"; } else { inkmlStr = inkmlStrParam; } InkMLDOMParser.LOG.fine(inkmlStr); try { final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setIgnoringComments(true); dbFactory.setIgnoringElementContentWhitespace(true); dbFactory.setValidating(false); InkMLDOMParser.LOG.info("Validation using schema is disabled."); final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); this.inkmlDOMDocument = dBuilder.parse(inkmlStr); this.bindData(this.inkMLProcessor.getInk()); } catch (final ParserConfigurationException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final SAXException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final IOException e) { throw new InkMLException("I/O error while parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to parse the InkML file identified by the inkmlFilename given in the parameter and creates data objects. It performs validation with schema. It * must have "ink" as root element with InkML name space specified with xmlns="http://www.w3.org/2003/InkML". The schema location may be specified. If it is * not specified or if relative path of the InkML.xsd file is specified, then the InkML.xsd file path must be added to * CLASSPATH for the parser to locate * it. An example of a typical header is, <ink xmlns="http://www.w3.org/2003/InkML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" * xsi:schemaLocation="http://www.w3.org/2003/InkML C:\project\schema\inkml.xsd"> * /*from w w w. j av a 2 s.c o m*/ * @param inkmlFileName * @throws InkMLException */ public void parseInkMLFile(final InputStream inputStream) throws InkMLException { // Get the DOM document object by parsing the InkML input file try { final InputSource input = new InputSource(inputStream); // get the DOM document object of the input InkML XML file. final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setIgnoringComments(true); dbFactory.setNamespaceAware(true); dbFactory.setIgnoringElementContentWhitespace(true); dbFactory.setValidating(false); if (this.isSchemaValidationEnabled()) { InkMLDOMParser.LOG.info("Validation using schema is enabled."); dbFactory.setSchema(this.schemaFactory .newSchema(new StreamSource(this.getClass().getResourceAsStream("/schema/inkml.xsd")))); } else { InkMLDOMParser.LOG.info("Validation using schema is disabled."); } final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); dBuilder.setErrorHandler(this); this.inkmlDOMDocument = dBuilder.parse(input); InkMLDOMParser.LOG.info("\nInput InkML XML file parsing is completed.\n"); this.inkMLProcessor.beginInkSession(); this.bindData(this.inkMLProcessor.getInk()); } catch (final ParserConfigurationException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final SAXException e) { throw new InkMLException("Error in parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } catch (final IOException e) { throw new InkMLException("I/O error while parsing Input InkML XML file.\n Message: " + e.getMessage(), e); } }
From source file:nl.b3p.kaartenbalie.service.requesthandler.WMSRequestHandler.java
/** * Gets the data from a specific set of URL's and converts the information * to the format usefull to the REQUEST_TYPE. Once the information is * collected and converted the method calls for a write in the DataWrapper, * which will sent the data to the client requested for this information. * * @param dw DataWrapper object containing the clients request information * @param urls StringBuffer with the urls where kaartenbalie should connect * to to recieve the requested data./*ww w. j ava 2 s . c o m*/ * @param overlay A boolean setting the overlay to true or false. If false * is chosen the images are placed under eachother. * * @return byte[] * * @throws Exception */ protected void getOnlineData(DataWrapper dw, ArrayList urlWrapper, boolean overlay, String REQUEST_TYPE) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedImage[] bi = null; //The list is given in the opposit ranking. Therefore we first need to swap the list. int size = urlWrapper.size(); ArrayList swaplist = new ArrayList(size); for (int i = size - 1; i >= 0; i--) { swaplist.add(urlWrapper.get(i)); log.debug("Outgoing url: " + ((ServiceProviderRequest) urlWrapper.get(i)).getProviderRequestURI()); } urlWrapper = swaplist; /* To save time, this method checks first if the ArrayList contains more then one url * If it contains only one url then the method doesn't have to load the image into the G2D * environment, which saves a lot of time and capacity because it doesn't have to decode * and recode the image. */ long startprocestime = System.currentTimeMillis(); DataMonitoring rr = dw.getRequestReporting(); if (urlWrapper.size() > 1) { if (REQUEST_TYPE.equalsIgnoreCase(OGCConstants.WMS_REQUEST_GetMap)) { /* * Log the time in ms from the start of the clientrequest.. (Reporting) */ Operation o = new Operation(); o.setType(Operation.SERVER_TRANSFER); o.setMsSinceRequestStart(new Long(rr.getMSSinceStart())); ImageManager imagemanager = new ImageManager(urlWrapper, dw); imagemanager.process(); long endprocestime = System.currentTimeMillis(); Long time = new Long(endprocestime - startprocestime); dw.setHeader("X-Kaartenbalie-ImageServerResponseTime", time.toString()); o.setDuration(time); rr.addRequestOperation(o); imagemanager.sendCombinedImages(dw); } else if (REQUEST_TYPE.equalsIgnoreCase(OGCConstants.WMS_REQUEST_GetFeatureInfo)) { /* * Create a DOM document and copy all the information of the several GetFeatureInfo * responses into one document. This document has the same layout as the received * documents and will hold all the information of the specified objects. * After combining these documents, the new document will be sent onto the request. */ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); dbf.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Document destination = builder.newDocument(); Element rootElement = destination.createElement("msGMLOutput"); destination.appendChild(rootElement); rootElement.setAttribute("xmlns:gml", "http://www.opengis.net/gml"); rootElement.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); rootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); Document source = null; for (int i = 0; i < urlWrapper.size(); i++) { ServiceProviderRequest wmsRequest = (ServiceProviderRequest) urlWrapper.get(i); String url = wmsRequest.getProviderRequestURI(); // code below could be used to get bytes received //InputStream is = new URL(url).openStream(); //CountingInputStream cis = new CountingInputStream(is); //source = builder.parse(cis); source = builder.parse(url); //what if url points to non MapServer service? copyElements(source, destination); wmsRequest.setBytesSent(new Long(url.getBytes().length)); wmsRequest.setProviderRequestURI(url); wmsRequest.setMsSinceRequestStart(new Long(rr.getMSSinceStart())); wmsRequest.setBytesReceived(new Long(-1)); //wmsRequest.setBytesReceived(new Long(cis.getByteCount())); wmsRequest.setResponseStatus(new Integer(-1)); rr.addServiceProviderRequest(wmsRequest); } OutputFormat format = new OutputFormat(destination); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(baos, format); serializer.serialize(destination); dw.write(baos); } else if (REQUEST_TYPE.equalsIgnoreCase(OGCConstants.WMS_REQUEST_DescribeLayer)) { //TODO: implement and refactor so there is less code duplication with getFeatureInfo /* DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); dbf.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Document destination = builder.newDocument(); //root element is different Element rootElement = destination.createElement("WMS_DescribeLayerResponse"); destination.appendChild(rootElement); //set version attribute Document source = null; for (int i = 0; i < urlWrapper.size(); i++) { ServiceProviderRequest dlRequest = (ServiceProviderRequest) urlWrapper.get(i); String url = dlRequest.getProviderRequestURI(); source = builder.parse(url); copyElements(source,destination); }*/ throw new Exception(REQUEST_TYPE + " request with more then one service url is not supported yet!"); } } else { //urlWrapper not > 1, so only 1 url or zero urls if (!urlWrapper.isEmpty()) { getOnlineData(dw, (ServiceProviderRequest) urlWrapper.get(0), REQUEST_TYPE); } else { if (REQUEST_TYPE.equalsIgnoreCase(OGCConstants.WMS_REQUEST_GetFeatureInfo)) { log.error(KBConfiguration.FEATUREINFO_EXCEPTION); throw new Exception(KBConfiguration.FEATUREINFO_EXCEPTION); } else if (REQUEST_TYPE.equalsIgnoreCase(OGCConstants.WMS_REQUEST_GetLegendGraphic)) { log.error(KBConfiguration.LEGENDGRAPHIC_EXCEPTION); throw new Exception(KBConfiguration.LEGENDGRAPHIC_EXCEPTION); } } } }
From source file:jef.tools.XMLUtils.java
private static DocumentBuilderFactory initFactory(boolean ignorComments, boolean namespaceAware) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); dbf.setValidating(false); // DTD dbf.setIgnoringComments(ignorComments); dbf.setNamespaceAware(namespaceAware); // dbf.setCoalescing(true);//CDATA // ?Text???/* www . ja v a 2 s . c om*/ try { // dbf.setFeature("http://xml.org/sax/features/namespaces", false); // dbf.setFeature("http://xml.org/sax/features/validation", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } catch (ParserConfigurationException e) { log.warn( "Your xerces implemention is too old to support 'load-dtd-grammar' and 'load-external-dtd' feature. Please upgrade xercesImpl.jar to 2.6.2 or above."); } catch (AbstractMethodError e) { log.warn( "Your xerces implemention is too old to support 'load-dtd-grammar' and 'load-external-dtd' feature. Please upgrade xercesImpl.jar to 2.6.2 or above."); } try { dbf.setAttribute("http://xml.org/sax/features/external-general-entities", false); } catch (IllegalArgumentException e) { log.warn("Your xerces implemention is too old to support 'external-general-entities' attribute."); } try { dbf.setAttribute("http://xml.org/sax/features/external-parameter-entities", false); } catch (IllegalArgumentException e) { log.warn("Your xerces implemention is too old to support 'external-parameter-entities' attribute."); } try { dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } catch (IllegalArgumentException e) { log.warn("Your xerces implemention is too old to support 'load-external-dtd' attribute."); } return dbf; }
From source file:com.twinsoft.convertigo.eclipse.wizards.new_project.NewProjectWizard.java
private Project createFromBlankProject(IProgressMonitor monitor) throws Exception { Project project = null;//from w ww. ja v a 2s . c o m String projectArchivePath = ""; String newProjectName = projectName; String oldProjectName = ""; switch (templateId) { case TEMPLATE_SQL_CONNECTOR: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + SQL_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = SQL_TEMPLATE_PROJECT_FILE_NAME.substring(0, SQL_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_SAP_CONNECTOR: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + SAP_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = SAP_TEMPLATE_PROJECT_FILE_NAME.substring(0, SAP_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_SEQUENCE_CONNECTOR: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + SEQUENCE_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = SEQUENCE_TEMPLATE_PROJECT_FILE_NAME.substring(0, SEQUENCE_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_EAI_HTML_WEB_SITE: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + WEB_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = WEB_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.substring(0, WEB_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_EAI_HTTP: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + HTTP_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = HTTP_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.substring(0, HTTP_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_WEB_HTML_BULL_DKU_7107: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + DKU_PUBLISHER_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = DKU_PUBLISHER_TEMPLATE_PROJECT_FILE_NAME.substring(0, DKU_PUBLISHER_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_WEB_HTML_IBM_3270: case TEMPLATE_WEB_HTML_IBM_5250: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + JAVELIN_PUBLISHER_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = JAVELIN_PUBLISHER_TEMPLATE_PROJECT_FILE_NAME.substring(0, JAVELIN_PUBLISHER_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_EAI_BULL_DKU_7107: case TEMPLATE_EAI_IBM_3270: case TEMPLATE_EAI_IBM_5250: case TEMPLATE_EAI_UNIX_VT220: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + JAVELIN_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = JAVELIN_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.substring(0, JAVELIN_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_EAI_CICS_COMMEAREA: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + CICS_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = CICS_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.substring(0, CICS_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_WEB_SERVICE_REST_REFERENCE: case TEMPLATE_WEB_SERVICE_SWAGGER_REFERENCE: case TEMPLATE_WEB_SERVICE_SOAP_REFERENCE: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + HTTP_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = HTTP_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.substring(0, HTTP_INTEGRATION_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_SITE_CLIPPER: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + SITE_CLIPPER_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = SITE_CLIPPER_TEMPLATE_PROJECT_FILE_NAME.substring(0, SITE_CLIPPER_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; case TEMPLATE_MOBILE_EMPTY_JQUERYMOBILE: projectArchivePath = Engine.TEMPLATES_PATH + "/project/" + JQUERYMOBILE_MOBILE_EMPTY_TEMPLATE_PROJECT_FILE_NAME; oldProjectName = JQUERYMOBILE_MOBILE_EMPTY_TEMPLATE_PROJECT_FILE_NAME.substring(0, JQUERYMOBILE_MOBILE_EMPTY_TEMPLATE_PROJECT_FILE_NAME.indexOf(".car")); break; default: return null; } String temporaryDir = new File(Engine.USER_WORKSPACE_PATH + "/temp").getCanonicalPath(); String tempProjectDir = temporaryDir + "/" + oldProjectName; String newProjectDir = Engine.PROJECTS_PATH + "/" + newProjectName; try { try { File f = null; monitor.setTaskName("Creating new project"); monitor.worked(1); try { // Check if project already exists if (Engine.theApp.databaseObjectsManager.existsProject(newProjectName)) throw new EngineException("Unable to create new project ! A project with the same name (\"" + newProjectName + "\") already exists."); // Create temporary directory if needed f = new File(temporaryDir); if (f.mkdir()) { monitor.setTaskName("Temporary directory created: " + temporaryDir); monitor.worked(1); } } catch (Exception e) { throw new EngineException("Unable to create the temporary directory \"" + temporaryDir + "\".", e); } // Decompress Convertigo archive to temporary directory ZipUtils.expandZip(projectArchivePath, temporaryDir, oldProjectName); monitor.setTaskName("Project archive expanded to temporary directory"); monitor.worked(1); // Rename temporary project directory f = new File(tempProjectDir); if (!f.renameTo(new File(newProjectDir))) { throw new ConvertigoException("Unable to rename the directory path \"" + tempProjectDir + "\" to \"" + newProjectDir + "\"." + "\n This directory already exists or is probably locked by another application."); } } catch (Exception e) { throw new EngineException( "Unable to deploy the project from the file \"" + projectArchivePath + "\".", e); } String xmlFilePath = newProjectDir + "/" + oldProjectName + ".xml"; String newXmlFilePath = newProjectDir + "/" + newProjectName + ".xml"; File xmlFile = new File(xmlFilePath); // load xml content of file in dom Document dom = null; // cration du docBuilderFactory DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setIgnoringElementContentWhitespace(true); docBuilderFactory.setNamespaceAware(true); // cration du docBuilder DocumentBuilder docBuilder; try { docBuilder = docBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new EngineException("Wrong parser configuration.", e); } // parsing du fichier try { dom = docBuilder.parse(xmlFile); } catch (SAXException e) { throw new EngineException("Wrong XML file structure.", e); } catch (IOException e) { throw new EngineException("Could not read source file.", e); } monitor.setTaskName("Xml file parsed"); monitor.worked(1); // set values of elements to configure on the new project String newEmulatorTechnology = ""; String emulatorTechnologyName = ""; String newIbmTerminalType = ""; switch (templateId) { case TEMPLATE_SEQUENCE_CONNECTOR: case TEMPLATE_EAI_HTML_WEB_SITE: case TEMPLATE_EAI_HTTP: break; case TEMPLATE_WEB_HTML_BULL_DKU_7107: case TEMPLATE_EAI_BULL_DKU_7107: newEmulatorTechnology = Session.DKU; emulatorTechnologyName = "BullDKU7107"; //$NON-NLS-1$ break; case TEMPLATE_WEB_HTML_IBM_3270: case TEMPLATE_EAI_IBM_3270: newEmulatorTechnology = Session.SNA; newIbmTerminalType = "IBM-3279"; emulatorTechnologyName = "IBM3270"; //$NON-NLS-1$ break; case TEMPLATE_WEB_HTML_IBM_5250: case TEMPLATE_EAI_IBM_5250: newEmulatorTechnology = Session.AS400; newIbmTerminalType = "IBM-3179"; emulatorTechnologyName = "IBM5250"; //$NON-NLS-1$ break; case TEMPLATE_EAI_UNIX_VT220: newEmulatorTechnology = Session.VT; emulatorTechnologyName = "UnixVT220"; //$NON-NLS-1$ break; default: break; } // rename project in .xml file for all projects Element projectElem = (Element) dom.getDocumentElement().getElementsByTagName("project").item(0); NodeList projectProperties = projectElem.getElementsByTagName("property"); Element property = (Element) XMLUtils.findNodeByAttributeValue(projectProperties, "name", "name"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", newProjectName); monitor.setTaskName("Project renamed"); monitor.worked(1); // empty project version property = (Element) XMLUtils.findNodeByAttributeValue(projectProperties, "name", "version"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", ""); // rename connector in .xml file for all projects String oldConnectorName = "unknown"; String newConnectorName = "NewConnector"; // interactionHub project connector name is by default set to "void" switch (templateId) { case TEMPLATE_MOBILE_EMPTY_JQUERYMOBILE: case TEMPLATE_SEQUENCE_CONNECTOR: newConnectorName = "void"; break; default: newConnectorName = (page2 == null) ? "NewConnector" : page2.getConnectorName(); break; } Element connectorElem = (Element) dom.getDocumentElement().getElementsByTagName("connector").item(0); NodeList connectorProperties = connectorElem.getElementsByTagName("property"); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "name"); oldConnectorName = ((Element) property.getElementsByTagName("java.lang.String").item(0)) .getAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", newConnectorName); monitor.setTaskName("Connector renamed"); monitor.worked(1); // configure connector properties switch (templateId) { case TEMPLATE_WEB_HTML_BULL_DKU_7107: case TEMPLATE_WEB_HTML_IBM_3270: case TEMPLATE_WEB_HTML_IBM_5250: case TEMPLATE_EAI_BULL_DKU_7107: case TEMPLATE_EAI_IBM_3270: case TEMPLATE_EAI_IBM_5250: case TEMPLATE_EAI_UNIX_VT220: // change emulator technology // and change service code property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "serviceCode"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", page7.getServiceCode()); monitor.setTaskName("Connector service code updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "emulatorTechnology"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", newEmulatorTechnology); monitor.setTaskName("Connector emulator technology updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "ibmTerminalType"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", newIbmTerminalType); monitor.setTaskName("Terminal type updated"); monitor.worked(1); // rename emulatorTechnology criteria Element criteriaElem = (Element) dom.getDocumentElement().getElementsByTagName("criteria").item(0); NodeList criteriaProperties = criteriaElem.getElementsByTagName("property"); property = (Element) XMLUtils.findNodeByAttributeValue(criteriaProperties, "name", "name"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", emulatorTechnologyName); monitor.setTaskName("Emulator technology criteria renamed"); monitor.worked(1); break; case TEMPLATE_WEB_SERVICE_REST_REFERENCE: case TEMPLATE_EAI_HTML_WEB_SITE: case TEMPLATE_EAI_HTTP: // change connector server and port, // change https mode // and change proxy server and proxy port property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "server"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", page6.getHttpServer()); monitor.setTaskName("Connector server updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "port"); ((Element) property.getElementsByTagName("java.lang.Integer").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.Integer").item(0)).setAttribute("value", page6.getHttpPort()); monitor.setTaskName("Connector port updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "https"); ((Element) property.getElementsByTagName("java.lang.Boolean").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.Boolean").item(0)).setAttribute("value", Boolean.toString(page6.isBSSL())); monitor.setTaskName("Connector https mode updated"); monitor.worked(1); break; case TEMPLATE_EAI_CICS_COMMEAREA: property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "mainframeName"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", page5.getCtgName()); monitor.setTaskName("Connector mainframe name updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "server"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", page5.getCtgServer()); monitor.setTaskName("Connector server updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "port"); ((Element) property.getElementsByTagName("java.lang.Integer").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.Integer").item(0)).setAttribute("value", page5.getCtgPort()); monitor.setTaskName("Connector port updated"); monitor.worked(1); break; case TEMPLATE_SQL_CONNECTOR: // change emulator technology // and change service code property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "jdbcURL"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSQLConnectorPage.getJdbcURL()); monitor.setTaskName("JDBC URL updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "jdbcDriverClassName"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSQLConnectorPage.getJdbcDriver()); monitor.setTaskName("JDBC driver updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "jdbcUserName"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSQLConnectorPage.getUsername()); monitor.setTaskName("Username updated"); monitor.worked(1); property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "jdbcUserPassword"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSQLConnectorPage.getPassword()); monitor.setTaskName("Password updated"); monitor.worked(1); break; case TEMPLATE_SAP_CONNECTOR: // change emulator technology // and change service code // Application Server Host property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "ashost"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSAPConnectorPage.getAsHost()); monitor.setTaskName("Application Server Host updated"); monitor.worked(1); // System Number property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "systemNumber"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSAPConnectorPage.getSystemNumber()); monitor.setTaskName("System number updated"); monitor.worked(1); // Client property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "client"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSAPConnectorPage.getClient()); monitor.setTaskName("Client updated"); monitor.worked(1); // User property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "user"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSAPConnectorPage.getUser()); monitor.setTaskName("User updated"); monitor.worked(1); // Password property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "password"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSAPConnectorPage.getPassword()); monitor.setTaskName("Password updated"); monitor.worked(1); // Language property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "language"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", configureSAPConnectorPage.getLanguage()); monitor.setTaskName("Language updated"); monitor.worked(1); break; case TEMPLATE_SITE_CLIPPER: property = (Element) XMLUtils.findNodeByAttributeValue(connectorProperties, "name", "trustAllServerCertificates"); ((Element) property.getElementsByTagName("java.lang.Boolean").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.Boolean").item(0)).setAttribute("value", Boolean.toString(page11.isTrustAllServerCertificates())); monitor.setTaskName("Connector certificates policy updated"); monitor.worked(1); break; default: break; } // Configure connector's default transaction properties Element transactionElem = (Element) dom.getDocumentElement().getElementsByTagName("transaction") .item(0); NodeList transactionProperties = transactionElem.getElementsByTagName("property"); switch (templateId) { case TEMPLATE_SITE_CLIPPER: property = (Element) XMLUtils.findNodeByAttributeValue(transactionProperties, "name", "targetURL"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).setAttribute("value", page11.getTargetURL()); monitor.setTaskName("Host url updated"); monitor.worked(1); break; case TEMPLATE_SQL_CONNECTOR: property = (Element) XMLUtils.findNodeByAttributeValue(transactionProperties, "name", "sqlQuery"); ((Element) property.getElementsByTagName("java.lang.String").item(0)).removeAttribute("value"); monitor.setTaskName("SQL queries updated"); monitor.worked(1); break; default: break; } // write the new .xml file // prepare the string source to write String doc = XMLUtils.prettyPrintDOM(dom); // create the output file File newXmlFile = new File(newXmlFilePath); if (!newXmlFile.createNewFile()) { throw new ConvertigoException("Unable to create the .xml file \"" + newProjectName + ".xml\"."); } // write the file to the disk byte data[] = doc.getBytes(); FileOutputStream fos = new FileOutputStream(newXmlFilePath); BufferedOutputStream dest = new BufferedOutputStream(fos, data.length); try { dest.write(data, 0, data.length); } finally { dest.flush(); dest.close(); } monitor.setTaskName("New xml file created and saved"); monitor.worked(1); // delete the old .xml file if (!xmlFile.delete()) { throw new ConvertigoException("Unable to delete the .xml file \"" + oldProjectName + ".xml\"."); } monitor.setTaskName("Old xml file deleted"); monitor.worked(1); try { String xsdInternalPath = newProjectDir + "/" + Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME; File xsdInternalDir = new File(xsdInternalPath).getCanonicalFile(); boolean needConnectorRename = !oldConnectorName.equals(newConnectorName); if (needConnectorRename) { File srcDir = new File(xsdInternalDir, oldConnectorName); File destDir = new File(xsdInternalDir, newConnectorName); if (oldConnectorName.equalsIgnoreCase(newConnectorName)) { File destDirTmp = new File(xsdInternalDir, "tmp" + oldConnectorName).getCanonicalFile(); FileUtils.moveDirectory(srcDir, destDirTmp); srcDir = destDirTmp; } FileUtils.moveDirectory(srcDir, destDir); } for (File connectorDir : xsdInternalDir.listFiles()) { if (connectorDir.isDirectory()) { String connectorName = connectorDir.getName(); for (File transactionXsdFile : connectorDir.listFiles()) { String xsdFilePath = transactionXsdFile.getCanonicalPath(); ProjectUtils.xsdRenameProject(xsdFilePath, oldProjectName, newProjectName); if (needConnectorRename && connectorName.equals(newConnectorName)) { ProjectUtils.xsdRenameConnector(xsdFilePath, oldConnectorName, newConnectorName); } } } } monitor.setTaskName("Schemas updated"); monitor.worked(1); } catch (ConvertigoException e) { Engine.logDatabaseObjectManager.error("An error occured while updating transaction schemas", e); } String projectPath = newProjectDir + "/" + newProjectName; // Import the project from the new .xml file project = Engine.theApp.databaseObjectsManager.importProject(projectPath + ".xml"); // In the case we want to predefine with the new project wizard a SQL query switch (templateId) { case TEMPLATE_SQL_CONNECTOR: try { SqlConnector connector = (SqlConnector) project.getDefaultConnector(); SqlTransaction transaction = connector.getDefaultTransaction(); String sqlQuery = transaction.getSqlQuery(); transaction.setSqlQuery(sqlQuery); CarUtils.exportProject(project, projectPath + ".xml"); } catch (Exception e) { Engine.logDatabaseObjectManager .error("An error occured while initialize SQL project \"" + projectName + "\"", e); } break; } monitor.setTaskName("Project loaded"); monitor.worked(1); monitor.setTaskName("Resources created"); monitor.worked(1); } catch (Exception e) { // Delete everything try { Engine.logBeans.error( "An error occured while creating project, everything will be deleted. Please see Studio logs for more informations.", null); // TODO : see if we can delete oldProjectName : a real project // could exist with this oldProjectName ? // Engine.theApp.databaseObjectsManager.deleteProject(oldProjectName, // false, false); Engine.theApp.databaseObjectsManager.deleteProject(newProjectName, false, false); projectName = null; // avoid load of project in view project = null; } catch (Exception ex) { } throw new Exception("Unable to create project from template", e); } return project; }
From source file:de.interactive_instruments.ShapeChange.Options.java
public void loadConfiguration() throws ShapeChangeAbortException { InputStream configStream = null; if (configFile == null) { // load minimal configuration, if no configuration file has been // provided configFile = "/config/minimal.xml"; configStream = getClass().getResourceAsStream(configFile); if (configStream == null) { configFile = "src/main/resources" + configFile; File file = new File(configFile); if (file.exists()) try { configStream = new FileInputStream(file); } catch (FileNotFoundException e1) { throw new ShapeChangeAbortException("Minimal configuration file not found: " + configFile); }/*from w ww . j a va 2s.c o m*/ else { URL url; String configURL = "http://shapechange.net/resources/config/minimal.xml"; try { url = new URL(configURL); configStream = url.openStream(); } catch (MalformedURLException e) { throw new ShapeChangeAbortException("Minimal configuration file not accessible from: " + configURL + " (malformed URL)"); } catch (IOException e) { throw new ShapeChangeAbortException( "Minimal configuration file not accessible from: " + configURL + " (IO error)"); } } } } else { File file = new File(configFile); if (file == null || !file.exists()) { try { configStream = (new URL(configFile)).openStream(); } catch (MalformedURLException e) { throw new ShapeChangeAbortException( "No configuration file found at " + configFile + " (malformed URL)"); } catch (IOException e) { throw new ShapeChangeAbortException( "No configuration file found at " + configFile + " (IO exception)"); } } else { try { configStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new ShapeChangeAbortException("No configuration file found at " + configFile); } } if (configStream == null) { throw new ShapeChangeAbortException("No configuration file found at " + configFile); } } DocumentBuilder builder = null; ShapeChangeErrorHandler handler = null; try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); factory.setFeature("http://apache.org/xml/features/validation/schema", true); factory.setIgnoringElementContentWhitespace(true); factory.setIgnoringComments(true); factory.setXIncludeAware(true); factory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false); builder = factory.newDocumentBuilder(); handler = new ShapeChangeErrorHandler(); builder.setErrorHandler(handler); } catch (FactoryConfigurationError e) { throw new ShapeChangeAbortException("Unable to get a document builder factory."); } catch (ParserConfigurationException e) { throw new ShapeChangeAbortException("XML Parser was unable to be configured."); } // parse file try { Document document = builder.parse(configStream); if (handler.errorsFound()) { throw new ShapeChangeAbortException("Invalid configuration file."); } // parse input element specific content NodeList nl = document.getElementsByTagName("input"); Element inputElement = (Element) nl.item(0); if (inputElement.hasAttribute("id")) { inputId = inputElement.getAttribute("id").trim(); if (inputId.length() == 0) { inputId = null; } } else { inputId = Options.INPUTELEMENTID; } Map<String, String> inputParameters = new HashMap<String, String>(); nl = inputElement.getElementsByTagName("parameter"); for (int j = 0; j < nl.getLength(); j++) { Element e = (Element) nl.item(j); String key = e.getAttribute("name"); String val = e.getAttribute("value"); inputParameters.put(key, val); } Map<String, String> stereotypeAliases = new HashMap<String, String>(); nl = inputElement.getElementsByTagName("StereotypeAlias"); for (int j = 0; j < nl.getLength(); j++) { Element e = (Element) nl.item(j); String key = e.getAttribute("alias"); String val = e.getAttribute("wellknown"); // case shall be ignored key = key.toLowerCase(); val = val.toLowerCase(); stereotypeAliases.put(key, val); } Map<String, String> tagAliases = new HashMap<String, String>(); nl = inputElement.getElementsByTagName("TagAlias"); for (int j = 0; j < nl.getLength(); j++) { Element e = (Element) nl.item(j); String key = e.getAttribute("alias"); String val = e.getAttribute("wellknown"); // case not to be ignored for tagged values at the moment // key = key.toLowerCase(); // val = val.toLowerCase(); tagAliases.put(key, val); } Map<String, String> descriptorSources = new HashMap<String, String>(); nl = inputElement.getElementsByTagName("DescriptorSource"); for (int j = 0; j < nl.getLength(); j++) { Element e = (Element) nl.item(j); String key = e.getAttribute("descriptor"); String val = e.getAttribute("source"); // case shall be ignored for descriptor and source key = key.toLowerCase(); val = val.toLowerCase(); if (val.equals("sc:extract")) { String s = e.getAttribute("token"); val += "#" + (s == null ? "" : s); } else if (val.equals("tag")) { String s = e.getAttribute("tag"); val += "#" + (s == null ? "" : s); } descriptorSources.put(key, val); } Map<String, PackageInfoConfiguration> packageInfos = parsePackageInfos(inputElement); this.inputConfig = new InputConfiguration(inputId, inputParameters, stereotypeAliases, tagAliases, descriptorSources, packageInfos); // parse dialog specific parameters nl = document.getElementsByTagName("dialog"); if (nl != null && nl.getLength() != 0) { for (int k = 0; k < nl.getLength(); k++) { Node node = nl.item(k); if (node.getNodeType() == Node.ELEMENT_NODE) { Element dialogElement = (Element) node; this.dialogParameters = parseParameters(dialogElement, "parameter"); } } } // parse log specific parameters nl = document.getElementsByTagName("log"); if (nl != null && nl.getLength() != 0) { for (int k = 0; k < nl.getLength(); k++) { Node node = nl.item(k); if (node.getNodeType() == Node.ELEMENT_NODE) { Element logElement = (Element) node; this.logParameters = parseParameters(logElement, "parameter"); } } } // add standard rules, just so that configured rules can be // validated addStandardRules(); // Load transformer configurations (if any are provided in the // configuration file) Map<String, TransformerConfiguration> transformerConfigs = parseTransformerConfigurations(document); // Load target configurations this.targetConfigs = parseTargetConfigurations(document); this.resetFields(); // this.resetUponLoadFlag = false; // TBD discuss if there's a better way to support rule and // requirements matching for the input model // TBD apparently the matching requires all // applicable encoding rules to be known up front for (TargetConfiguration tgtConfig : targetConfigs) { // System.out.println(tgtConfig); String className = tgtConfig.getClassName(); String mode = tgtConfig.getProcessMode().name(); // set targets and their mode; if a target occurs multiple // times, keep the enabled one(s) if (!this.fTargets.containsKey(className)) { addTarget(className, mode); } else { if (this.fTargets.get(className).equals(ProcessMode.disabled)) { // set targets and their mode; if a target occurs // multiple times, keep the enabled one(s) addTarget(className, mode); } } // ensure that we have all the rules from all non-disabled // targets // we repeat this for the same target (if it is not disabled) to // ensure that we get the union of all encoding rules if (!tgtConfig.getProcessMode().equals(ProcessMode.disabled)) { for (ProcessRuleSet prs : tgtConfig.getRuleSets().values()) { String nam = prs.getName(); String ext = prs.getExtendedRuleSetName(); addExtendsEncRule(nam, ext); if (prs.hasAdditionalRules()) { for (String rule : prs.getAdditionalRules()) { addRule(rule, nam); } } } } /* * looks like we also need parameters like defaultEncodingRule * !!! IF THERE ARE DIFFERENT DEFAULT ENCODING RULES FOR * DIFFERENT TARGETS (WITH SAME CLASS) THIS WONT WORK!!! */ for (String paramName : tgtConfig.getParameters().keySet()) { setParameter(className, paramName, tgtConfig.getParameters().get(paramName)); } // in order for the input model load not to produce warnings, // we also need to load the map entries if (tgtConfig instanceof TargetXmlSchemaConfiguration) { TargetXmlSchemaConfiguration config = (TargetXmlSchemaConfiguration) tgtConfig; // add xml schema namespace information for (XmlNamespace xns : config.getXmlNamespaces()) { addNamespace(xns.getNsabr(), xns.getNs(), xns.getLocation()); // if (xns.getLocation() != null) { addSchemaLocation(xns.getNs(), xns.getLocation()); // } } // add xsd map entries for (XsdMapEntry xsdme : config.getXsdMapEntries()) { for (String xsdEncodingRule : xsdme.getEncodingRules()) { String type = xsdme.getType(); String xmlPropertyType = xsdme.getXmlPropertyType(); String xmlElement = xsdme.getXmlElement(); String xmlTypeContent = xsdme.getXmlTypeContent(); String xmlTypeNilReason = xsdme.getXmlTypeNilReason(); String xmlType = xsdme.getXmlType(); String xmlTypeType = xsdme.getXmlTypeType(); String xmlAttribute = xsdme.getXmlAttribute(); String xmlAttributeGroup = xsdme.getXmlAttributeGroup(); if (xmlPropertyType != null) { if (xmlPropertyType.equals("_P_") && xmlElement != null) { addTypeMapEntry(type, xsdEncodingRule, "propertyType", xmlElement); } else if (xmlPropertyType.equals("_MP_") && xmlElement != null) { addTypeMapEntry(type, xsdEncodingRule, "metadataPropertyType", xmlElement); } else { addTypeMapEntry(type, xsdEncodingRule, "direct", xmlPropertyType, xmlTypeType + "/" + xmlTypeContent, xmlTypeNilReason); } } if (xmlElement != null) { addElementMapEntry(type, xsdEncodingRule, "direct", xmlElement); } if (xmlType != null) { addBaseMapEntry(type, xsdEncodingRule, "direct", xmlType, xmlTypeType + "/" + xmlTypeContent); } if (xmlAttribute != null) { addAttributeMapEntry(type, xsdEncodingRule, xmlAttribute); } if (xmlAttributeGroup != null) { addAttributeGroupMapEntry(type, xsdEncodingRule, xmlAttributeGroup); } } } } else { // add map entries for Target (no need to do this for // transformers) for (ProcessMapEntry pme : tgtConfig.getMapEntries()) { addTargetTypeMapEntry(tgtConfig.getClassName(), pme.getType(), pme.getRule(), pme.getTargetType(), pme.getParam()); } } } // create "tree" for (TargetConfiguration tgtConfig : targetConfigs) { for (String inputIdref : tgtConfig.getInputIds()) { if (inputIdref.equals(getInputId())) { this.inputTargetConfigs.add(tgtConfig); } else { transformerConfigs.get(inputIdref).addTarget(tgtConfig); } } } for (TransformerConfiguration trfConfig : transformerConfigs.values()) { String inputIdref = trfConfig.getInputId(); if (inputIdref.equals(getInputId())) { this.inputTransformerConfigs.add(trfConfig); } else { transformerConfigs.get(inputIdref).addTransformer(trfConfig); } } // Determine constraint creation handling parameters: String classTypesToCreateConstraintsFor = parameter("classTypesToCreateConstraintsFor"); if (classTypesToCreateConstraintsFor != null) { classTypesToCreateConstraintsFor = classTypesToCreateConstraintsFor.trim(); if (classTypesToCreateConstraintsFor.length() > 0) { String[] stereotypes = classTypesToCreateConstraintsFor.split("\\W*,\\W*"); this.classTypesToCreateConstraintsFor = new HashSet<Integer>(); for (String stereotype : stereotypes) { String sForCons = stereotype.toLowerCase(); if (sForCons.equals("enumeration")) { this.classTypesToCreateConstraintsFor.add(new Integer(ENUMERATION)); } else if (sForCons.equals("codelist")) { this.classTypesToCreateConstraintsFor.add(new Integer(CODELIST)); } else if (sForCons.equals("schluesseltabelle")) { this.classTypesToCreateConstraintsFor.add(new Integer(OKSTRAKEY)); } else if (sForCons.equals("fachid")) { this.classTypesToCreateConstraintsFor.add(new Integer(OKSTRAFID)); } else if (sForCons.equals("datatype")) { this.classTypesToCreateConstraintsFor.add(new Integer(DATATYPE)); } else if (sForCons.equals("union")) { this.classTypesToCreateConstraintsFor.add(new Integer(UNION)); } else if (sForCons.equals("featureconcept")) { this.classTypesToCreateConstraintsFor.add(new Integer(FEATURECONCEPT)); } else if (sForCons.equals("attributeconcept")) { this.classTypesToCreateConstraintsFor.add(new Integer(ATTRIBUTECONCEPT)); } else if (sForCons.equals("valueconcept")) { this.classTypesToCreateConstraintsFor.add(new Integer(VALUECONCEPT)); } else if (sForCons.equals("interface")) { this.classTypesToCreateConstraintsFor.add(new Integer(MIXIN)); } else if (sForCons.equals("basictype")) { this.classTypesToCreateConstraintsFor.add(new Integer(BASICTYPE)); } else if (sForCons.equals("adeelement")) { this.classTypesToCreateConstraintsFor.add(new Integer(FEATURE)); } else if (sForCons.equals("featuretype")) { this.classTypesToCreateConstraintsFor.add(new Integer(FEATURE)); } else if (sForCons.equals("type")) { this.classTypesToCreateConstraintsFor.add(new Integer(OBJECT)); } else { this.classTypesToCreateConstraintsFor.add(new Integer(UNKNOWN)); } } } } String constraintCreationForProperties = parameter("constraintCreationForProperties"); if (constraintCreationForProperties != null) { if (constraintCreationForProperties.trim().equalsIgnoreCase("false")) { this.constraintCreationForProperties = false; } } /* * TODO add documentation */ String ignoreEncodingRuleTaggedValues = parameter("ignoreEncodingRuleTaggedValues"); if (ignoreEncodingRuleTaggedValues != null) { if (ignoreEncodingRuleTaggedValues.trim().equalsIgnoreCase("true")) { this.ignoreEncodingRuleTaggedValues = true; } } String useStringInterning_value = parameter(PARAM_USE_STRING_INTERNING); if (useStringInterning_value != null && useStringInterning_value.trim().equalsIgnoreCase("true")) { this.useStringInterning = true; } String loadGlobalIds_value = this.parameter(PARAM_LOAD_GLOBAL_IDENTIFIERS); if (loadGlobalIds_value != null && loadGlobalIds_value.trim().equalsIgnoreCase("true")) { this.loadGlobalIds = true; } String language_value = inputConfig.getParameters().get(PARAM_LANGUAGE); if (language_value != null && !language_value.trim().isEmpty()) { this.language = language_value.trim().toLowerCase(); } } catch (SAXException e) { String m = e.getMessage(); if (m != null) { throw new ShapeChangeAbortException( "Error while loading configuration file: " + System.getProperty("line.separator") + m); } else { e.printStackTrace(System.err); throw new ShapeChangeAbortException("Error while loading configuration file: " + System.getProperty("line.separator") + System.err); } } catch (IOException e) { String m = e.getMessage(); if (m != null) { throw new ShapeChangeAbortException( "Error while loading configuration file: " + System.getProperty("line.separator") + m); } else { e.printStackTrace(System.err); throw new ShapeChangeAbortException("Error while loading configuration file: " + System.getProperty("line.separator") + System.err); } } MapEntry nsme = namespace("gml"); if (nsme != null) { GML_NS = nsme.rule; } }
From source file:com.dosse.bwentrain.androidPlayer.MainActivity.java
private Preset loadPreset(String f) { InputStream p = null;/*from w w w . j ava2s . co m*/ Preset x = null; try { if (new File(f).exists()) p = new FileInputStream(f); else p = openFileInput(f); if (p == null) throw new Exception("Can't open " + f); //read xml document DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(p); doc.getDocumentElement().normalize(); //parse it x = new Preset(doc.getDocumentElement()); if (getSharedPreferences("SINE", Context.MODE_PRIVATE).getBoolean("noise_switch", false)) { //if noise is disabled, remove it Envelope e = x.getNoiseEnvelope(); while (e.getPointCount() != 1) e.removePoint(1); e.setVal(0, 0); } } catch (Throwable t) { //corrupt or not a preset file Log.e("SINE", f + " invalid because " + t.toString()); } finally { if (p != null) try { p.close(); } catch (IOException e) { } } return x; }
From source file:net.sourceforge.pmd.lang.xml.ast.XmlParser.java
protected Document parseDocument(Reader reader) throws ParseException { nodeCache.clear();/*from w w w. ja va2s.co m*/ try { String xmlData = IOUtils.toString(reader); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(parserOptions.isNamespaceAware()); dbf.setValidating(parserOptions.isValidating()); dbf.setIgnoringComments(parserOptions.isIgnoringComments()); dbf.setIgnoringElementContentWhitespace(parserOptions.isIgnoringElementContentWhitespace()); dbf.setExpandEntityReferences(parserOptions.isExpandEntityReferences()); dbf.setCoalescing(parserOptions.isCoalescing()); dbf.setXIncludeAware(parserOptions.isXincludeAware()); dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); documentBuilder.setEntityResolver(parserOptions.getEntityResolver()); Document document = documentBuilder.parse(new InputSource(new StringReader(xmlData))); DOMLineNumbers lineNumbers = new DOMLineNumbers(document, xmlData); lineNumbers.determine(); return document; } catch (ParserConfigurationException | SAXException | IOException e) { throw new ParseException(e); } }
From source file:nl.armatiek.xslweb.utils.XMLUtils.java
public static DocumentBuilder getDocumentBuilder(boolean validate, boolean namespaceAware, boolean xincludeAware) throws XSLWebException { try {// w w w . jav a2s .com DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); if (xincludeAware) { docFactory.setFeature("http://apache.org/xml/features/xinclude", true); docFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false); docFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-language", false); docFactory.setXIncludeAware(true); } docFactory.setNamespaceAware(namespaceAware); docFactory.setValidating(validate); docFactory.setExpandEntityReferences(true); if (validate) { docFactory.setFeature("http://apache.org/xml/features/validation/dynamic", true); docFactory.setFeature("http://apache.org/xml/features/validation/schema", true); } docFactory.setIgnoringElementContentWhitespace(true); return docFactory.newDocumentBuilder(); } catch (Exception e) { throw new XSLWebException(e); } }