public BeanInjectionInfo(Class<?> clazz) { LOG.logDebug("Collect bean injection info for " + clazz); try { this.clazz = clazz; clazzAnnotation = clazz.getAnnotation(InjectionSupported.class); if (clazzAnnotation == null) { throw new RuntimeException("Injection not supported in " + clazz); } Group gr0 = new Group(""); groupsList.add(gr0); groupsMap.put(gr0.getName(), gr0); for (String group : clazzAnnotation.groups()) { Group gr = new Group(group); groupsList.add(gr); groupsMap.put(gr.getName(), gr); } BeanLevelInfo root = new BeanLevelInfo(); root.leafClass = clazz; root.init(this); properties = Collections.unmodifiableMap(properties); groupsList = Collections.unmodifiableList(groupsList); groupsMap = null; } catch (Throwable ex) { LOG.logError( "Error bean injection info collection for " + clazz + ": " + ex.getMessage(), ex); throw ex; } }
private void parseDocument() { // get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try { // get a new instance of parser SAXParser sp = spf.newSAXParser(); // parse the file and also register this class for call backs sp.parse(sourceFile, this); } catch (SAXException se) { log.logError(Const.getStackTracker(se)); } catch (ParserConfigurationException pce) { log.logError(Const.getStackTracker(pce)); } catch (IOException ie) { log.logError(Const.getStackTracker(ie)); } }
protected int getDataForRow(TableItem item, Object[] row) { int nrErrors = 0; // Display the correct line item... // String strNr; lineNr++; try { strNr = wFields.getNumberColumn().getValueMeta().getString(new Long(lineNr)); } catch (Exception e) { strNr = Integer.toString(lineNr); } item.setText(0, strNr); for (int c = 0; c < rowMeta.size(); c++) { ValueMetaInterface v = rowMeta.getValueMeta(c); String show; try { show = v.getString(row[c]); if (v.isBinary() && show != null && show.length() > MAX_BINARY_STRING_PREVIEW_SIZE) { // We want to limit the size of the strings during preview to keep all SWT widgets happy. // show = show.substring(0, MAX_BINARY_STRING_PREVIEW_SIZE); } } catch (KettleValueException e) { nrErrors++; if (nrErrors < 25) { log.logError(Const.getStackTracker(e)); } show = null; } catch (ArrayIndexOutOfBoundsException e) { nrErrors++; if (nrErrors < 25) { log.logError(Const.getStackTracker(e)); } show = null; } if (show != null) { item.setText(c + 1, show); } } return nrErrors; }
protected String findString( String packageName, Locale locale, String key, Object[] parameters, Class<?> resourceClass) throws MissingResourceException { try { ResourceBundle bundle = getBundle(locale, packageName + "." + BUNDLE_NAME, resourceClass); String unformattedString = bundle.getString(key); String string = MessageFormat.format(unformattedString, parameters); return string; } catch (IllegalArgumentException e) { String message = "Format problem with key=[" + key + "], locale=[" + locale + "], package=" + packageName + " : " + e.toString(); log.logError(message); log.logError(Const.getStackTracker(e)); throw new MissingResourceException(message, packageName, key); } }
@Override public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException { if (!(object instanceof CommandLineOption[])) { return; } CommandLineOption[] options = (CommandLineOption[]) object; StringBuilder optionRepname = getCommandLineOption(options, "rep").getArgument(); StringBuilder optionFilename = getCommandLineOption(options, "file").getArgument(); StringBuilder optionUsername = getCommandLineOption(options, "user").getArgument(); StringBuilder optionPassword = getCommandLineOption(options, "pass").getArgument(); if (!Utils.isEmpty(optionRepname) && Utils.isEmpty(optionFilename)) { RepositoryMeta repositoryMeta = repositoryConnectController.getRepositoryMetaByName(optionRepname.toString()); if (repositoryMeta != null && !Utils.isEmpty(optionUsername) && !Utils.isEmpty(optionPassword)) { repositoryConnectController.connectToRepository( repositoryMeta, optionUsername.toString(), optionPassword.toString()); } else if (repositoryMeta != null) { repositoryConnectController.connectToRepository(repositoryMeta, null, null); } if (!repositoryConnectController.isConnected()) { String msg = BaseMessages.getString(PKG, "Repository.NoConnected.Message"); log.logError(msg); // "No repositories defined on this system." MessageBox mb = new MessageBox(getSpoon().getShell(), SWT.OK | SWT.ICON_ERROR); mb.setMessage( BaseMessages.getString( PKG, "Repository.NoConnected.Message", optionRepname.toString())); mb.setText(BaseMessages.getString(PKG, "Repository.NoConnected.Message.Title")); mb.open(); } } else if (Utils.isEmpty(optionFilename)) { RepositoryMeta repositoryMeta = repositoryConnectController.getDefaultRepositoryMeta(); if (repositoryMeta != null) { if (repositoryMeta.getId().equals("KettleFileRepository")) { repositoryConnectController.connectToRepository(repositoryMeta); } else { new RepositoryDialog(getSpoon().getShell(), repositoryConnectController) .openLogin(repositoryMeta); } } } }
// Event Handlers public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // set the _counter level position[_counter + 1] += 1; _counter++; try { if (!rootFound) { XMLInputSaxFieldPosition el = null; try { el = (XMLInputSaxFieldPosition) pathToRootElement.get(counter); } catch (IndexOutOfBoundsException e) { throw new SAXException(e); } if ((counter == _counter) && qName.equalsIgnoreCase(el.getName())) { if (el.getType() == XMLInputSaxFieldPosition.XML_ELEMENT_ATT) { String att1 = attributes.getValue(el.getAttribute()); // must throw exception String att2 = el.getAttributeValue(); if (att1.equals(att2)) { _pathToRootElement.add( new XMLInputSaxFieldPosition( qName, el.getAttribute(), el.getAttributeValue())); // to test with clone if (counter == pathToRootElement.size() - 1) { for (int i = 0; i < attributes.getLength(); i++) { XMLInputSaxFieldPosition tempP = new XMLInputSaxFieldPosition( attributes.getQName(i), XMLInputSaxFieldPosition.XML_ATTRIBUTE, i + 1); _pathToRootElement.add(tempP); XMLInputSaxFieldPosition[] path = new XMLInputSaxFieldPosition[_pathToRootElement.size()]; _pathToRootElement.toArray(path); _pathToRootElement.remove(_pathToRootElement.size() - 1); XMLInputSaxField tempF = new XMLInputSaxField(tempP.getName(), path); if (!fields.contains(tempF)) { fields.add(tempF); } } } counterUp(); } else { _pathToRootElement.add( new XMLInputSaxFieldPosition( qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1)); } } else { _pathToRootElement.add( new XMLInputSaxFieldPosition( qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1)); counterUp(); } } else { _pathToRootElement.add( new XMLInputSaxFieldPosition( qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1)); } } else { XMLInputSaxField temp = null; if (attributes.getValue(meta.getDefiningAttribute(qName)) == null) { _pathToRootElement.add( new XMLInputSaxFieldPosition( qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1)); XMLInputSaxFieldPosition[] path = new XMLInputSaxFieldPosition[_pathToRootElement.size()]; _pathToRootElement.toArray(path); temp = new XMLInputSaxField(naming(path), path); } else { String attribute = meta.getDefiningAttribute(qName); _pathToRootElement.add( new XMLInputSaxFieldPosition(qName, attribute, attributes.getValue(attribute))); XMLInputSaxFieldPosition[] path = new XMLInputSaxFieldPosition[_pathToRootElement.size()]; _pathToRootElement.toArray(path); temp = new XMLInputSaxField(naming(path), path); } if (!fields.contains(temp)) { fields.add(temp); } } } catch (KettleValueException e) { log.logError(Const.getStackTracker(e)); throw new SAXException( _counter + "," + counter + ((XMLInputSaxFieldPosition) _pathToRootElement.get(_pathToRootElement.size() - 1)) .toString(), e); } }
public boolean validate() { boolean retval = false; FileObject xmlfile = null; FileObject DTDfile = null; ByteArrayInputStream ba = null; try { if (xmlfilename != null && ((getDTDFilename() != null && !isInternDTD()) || (isInternDTD()))) { xmlfile = KettleVFS.getFileObject(getXMLFilename()); if (xmlfile.exists()) { URL xmlFile = new File(KettleVFS.getFilename(xmlfile)).toURI().toURL(); StringBuffer xmlStringbuffer = new StringBuffer(""); BufferedReader xmlBufferedReader = null; InputStreamReader is = null; try { // open XML File is = new InputStreamReader(xmlFile.openStream()); xmlBufferedReader = new BufferedReader(is); char[] buffertXML = new char[1024]; int LenXML = -1; while ((LenXML = xmlBufferedReader.read(buffertXML)) != -1) { xmlStringbuffer.append(buffertXML, 0, LenXML); } } finally { if (is != null) { is.close(); } if (xmlBufferedReader != null) { xmlBufferedReader.close(); } } // Prepare parsing ... DocumentBuilderFactory DocBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder DocBuilder = DocBuilderFactory.newDocumentBuilder(); // Let's try to get XML document encoding DocBuilderFactory.setValidating(false); ba = new ByteArrayInputStream(xmlStringbuffer.toString().getBytes("UTF-8")); Document xmlDocDTD = DocBuilder.parse(ba); if (ba != null) { ba.close(); } String encoding = null; if (xmlDocDTD.getXmlEncoding() == null) { encoding = "UTF-8"; } else { encoding = xmlDocDTD.getXmlEncoding(); } int xmlStartDTD = xmlStringbuffer.indexOf("<!DOCTYPE"); if (isInternDTD()) { // DTD find in the XML document if (xmlStartDTD != -1) { log.logBasic( BaseMessages.getString( PKG, "JobEntryDTDValidator.ERRORDTDFound.Label", getXMLFilename())); } else { setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.ERRORDTDNotFound.Label", getXMLFilename())); } } else { // DTD in external document // If we find an intern declaration, we remove it DTDfile = KettleVFS.getFileObject(getDTDFilename()); if (DTDfile.exists()) { if (xmlStartDTD != -1) { int EndDTD = xmlStringbuffer.indexOf(">", xmlStartDTD); // String DocTypeDTD = xmlStringbuffer.substring(xmlStartDTD, EndDTD + 1); xmlStringbuffer.replace(xmlStartDTD, EndDTD + 1, ""); } String xmlRootnodeDTD = xmlDocDTD.getDocumentElement().getNodeName(); String RefDTD = "<?xml version='" + xmlDocDTD.getXmlVersion() + "' encoding='" + encoding + "'?>\n<!DOCTYPE " + xmlRootnodeDTD + " SYSTEM '" + KettleVFS.getFilename(DTDfile) + "'>\n"; int xmloffsetDTD = xmlStringbuffer.indexOf("<" + xmlRootnodeDTD); xmlStringbuffer.replace(0, xmloffsetDTD, RefDTD); } else { log.logError( BaseMessages.getString(PKG, "JobEntryDTDValidator.ERRORDTDFileNotExists.Subject"), BaseMessages.getString( PKG, "JobEntryDTDValidator.ERRORDTDFileNotExists.Msg", getDTDFilename())); } } if (!(isInternDTD() && xmlStartDTD == -1 || (!isInternDTD() && !DTDfile.exists()))) { // Let's parse now ... MyErrorHandler error = new MyErrorHandler(); DocBuilderFactory.setValidating(true); DocBuilder = DocBuilderFactory.newDocumentBuilder(); DocBuilder.setErrorHandler(error); ba = new ByteArrayInputStream(xmlStringbuffer.toString().getBytes(encoding)); xmlDocDTD = DocBuilder.parse(ba); if (error.errorMessage == null) { log.logBasic( BaseMessages.getString(PKG, "JobEntryDTDValidator.DTDValidatorOK.Subject"), BaseMessages.getString( PKG, "JobEntryDTDValidator.DTDValidatorOK.Label", getXMLFilename())); // Everything is OK retval = true; } else { // Invalid DTD setNrErrors(error.nrErrors); setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.DTDValidatorKO", getXMLFilename(), error.nrErrors, error.errorMessage)); } } } else { if (!xmlfile.exists()) { setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.FileDoesNotExist.Label", getXMLFilename())); } } } else { setErrorMessage(BaseMessages.getString(PKG, "JobEntryDTDValidator.AllFilesNotNull.Label")); } } catch (Exception e) { setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.ErrorDTDValidator.Label", getXMLFilename(), getDTDFilename(), e.getMessage())); } finally { try { if (xmlfile != null) { xmlfile.close(); } if (DTDfile != null) { DTDfile.close(); } if (ba != null) { ba.close(); } } catch (IOException e) { // Ignore close errors } } return retval; }
public void query(boolean specifyQuery) throws KettleException { if (getBinding() == null) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.Exception.CanNotGetBiding")); } try { if (!specifyQuery) { // check if we can query this Object DescribeSObjectResult describeSObjectResult = getBinding().describeSObject(getModule()); if (describeSObjectResult == null) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInput.ErrorGettingObject")); } if (!describeSObjectResult.isQueryable()) { throw new KettleException( BaseMessages.getString(PKG, "SalesforceInputDialog.ObjectNotQueryable", module)); } if (this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_UPDATED || this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_DELETED) { // The object must be replicateable if (!describeSObjectResult.isReplicateable()) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.ObjectNotReplicateable", getModule())); } } } if (getSQL() != null && log.isDetailed()) { log.logDetailed( BaseMessages.getString(PKG, "SalesforceInput.Log.SQLString") + " : " + getSQL()); } switch (this.recordsFilter) { case SalesforceConnectionUtils.RECORDS_FILTER_UPDATED: // Updated records ... GetUpdatedResult updatedRecords = getBinding().getUpdated(getModule(), this.startDate, this.endDate); if (updatedRecords.getIds() != null) { int nr = updatedRecords.getIds().length; if (nr > 0) { String[] ids = updatedRecords.getIds(); // We can pass a maximum of 2000 object IDs if (nr > SalesforceConnectionUtils.MAX_UPDATED_OBJECTS_IDS) { this.sObjects = new SObject[nr]; List<String> list = new ArrayList<String>(); int desPos = 0; for (int i = 0; i < nr; i++) { list.add(updatedRecords.getIds(i)); if (i % SalesforceConnectionUtils.MAX_UPDATED_OBJECTS_IDS == 0 || i == nr - 1) { SObject[] s = getBinding() .retrieve( this.fieldsList, getModule(), list.toArray(new String[list.size()])); System.arraycopy(s, 0, this.sObjects, desPos, s.length); desPos += s.length; s = null; list = new ArrayList<String>(); } } } else { this.sObjects = getBinding().retrieve(this.fieldsList, getModule(), ids); } if (this.sObjects != null) { this.queryResultSize = this.sObjects.length; } } } break; case SalesforceConnectionUtils.RECORDS_FILTER_DELETED: // Deleted records ... GetDeletedResult deletedRecordsResult = getBinding().getDeleted(getModule(), this.startDate, this.endDate); DeletedRecord[] deletedRecords = deletedRecordsResult.getDeletedRecords(); if (log.isDebug()) { log.logDebug( toString(), BaseMessages.getString( PKG, "SalesforceConnection.DeletedRecordsFound", String.valueOf(deletedRecords == null ? 0 : deletedRecords.length))); } if (deletedRecords != null && deletedRecords.length > 0) { getDeletedList = new HashMap<String, Date>(); for (DeletedRecord dr : deletedRecords) { getDeletedList.put(dr.getId(), dr.getDeletedDate().getTime()); } this.qr = getBinding().queryAll(getSQL()); this.sObjects = getQueryResult().getRecords(); if (this.sObjects != null) { this.queryResultSize = this.sObjects.length; } } break; default: // return query result this.qr = isQueryAll() ? getBinding().queryAll(getSQL()) : getBinding().query(getSQL()); this.sObjects = getQueryResult().getRecords(); this.queryResultSize = getQueryResult().getSize(); break; } if (this.sObjects != null) { this.recordsCount = this.sObjects.length; } } catch (Exception e) { log.logError(Const.getStackTracker(e)); throw new KettleException( BaseMessages.getString(PKG, "SalesforceConnection.Exception.Query"), e); } }
@Override public void showError(String title, String message, Exception e) { log.logError(message, e); }