List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:org.eclipse.winery.common.ModelUtilities.java
public static Element buildPropertiesElement(Map<String, String> properties, String propNS) { Document document = null;//from w w w .j a va 2s .com try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException e) { System.out.println(e.getMessage()); } Element root = document.createElement("Properties"); root.setAttribute("xmlns", propNS); for (Entry<String, String> entry : properties.entrySet()) { if (null != entry.getKey() && null != entry.getValue()) { Element ele = document.createElementNS(propNS, entry.getKey()); ele.setTextContent(entry.getValue()); root.appendChild(ele); } } return root; }
From source file:org.eclipse.winery.repository.resources.artifacts.GenericArtifactsResource.java
private void storeProperties(ArtifactTemplateResource artifactTemplateResource, TOSCAComponentId typeId, String name) {//from w w w . ja va 2s .co m // We generate the properties by hand instead of using JAX-B as using JAX-B causes issues at org.eclipse.winery.common.ModelUtilities.getPropertiesKV(TEntityTemplate): // getAny() does not always return "w3c.dom.element" anymore DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { GenericArtifactsResource.logger.error(e.getMessage(), e); return; } Document doc = builder.newDocument(); Element root = doc.createElementNS(this.NS_OPENTOSCA_WAR_TYPE, "WSProperties"); doc.appendChild(root); Element element = doc.createElementNS(this.NS_OPENTOSCA_WAR_TYPE, "ServiceEndpoint"); Text text = doc.createTextNode("/services/" + name + "Port"); element.appendChild(text); root.appendChild(element); element = doc.createElementNS(this.NS_OPENTOSCA_WAR_TYPE, "PortType"); text = doc.createTextNode("{" + typeId.getNamespace().getDecoded() + "}" + name); element.appendChild(text); root.appendChild(element); element = doc.createElementNS(this.NS_OPENTOSCA_WAR_TYPE, "InvocationType"); text = doc.createTextNode("SOAP/HTTP"); element.appendChild(text); root.appendChild(element); Properties properties = new Properties(); properties.setAny(root); PropertiesResource propertiesResource = artifactTemplateResource.getPropertiesResource(); propertiesResource.setProperties(properties); }
From source file:org.eclipse.winery.repository.rest.resources.artifacts.GenericArtifactsResource.java
private void storeProperties(ArtifactTemplateId artifactTemplateId, DefinitionsChildId typeId, String name) { // We generate the properties by hand instead of using JAX-B as using JAX-B causes issues at org.eclipse.winery.common.ModelUtilities.getPropertiesKV(TEntityTemplate): // getAny() does not always return "w3c.dom.element" anymore DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;//from w w w.ja va2s . c om try { builder = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { GenericArtifactsResource.LOGGER.error(e.getMessage(), e); return; } Document doc = builder.newDocument(); String namespace = QNames.QNAME_ARTIFACT_TYPE_WAR.getNamespaceURI(); Element root = doc.createElementNS(namespace, "WSProperties"); doc.appendChild(root); Element element = doc.createElementNS(namespace, "ServiceEndpoint"); Text text = doc.createTextNode("/services/" + name + "Port"); element.appendChild(text); root.appendChild(element); element = doc.createElementNS(namespace, "PortType"); text = doc.createTextNode("{" + typeId.getNamespace().getDecoded() + "}" + name); element.appendChild(text); root.appendChild(element); element = doc.createElementNS(namespace, "InvocationType"); text = doc.createTextNode("SOAP/HTTP"); element.appendChild(text); root.appendChild(element); Properties properties = new Properties(); properties.setAny(root); final IRepository repository = RepositoryFactory.getRepository(); final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId); artifactTemplate.setProperties(properties); try { repository.setElement(artifactTemplateId, artifactTemplate); } catch (IOException e) { throw new WebApplicationException(e); } }
From source file:org.ecoinformatics.seek.ecogrid.EcogridWriter.java
/** * After generate docid for data file, the original metadata need to replace * the distribution url by new value. Currently we just consider eml as * metadata.//from w w w . j a va 2s . c om * * @param originalMetadata * @param newURL * @param newMetadataID * @return * @throws Exception */ private String replaceDistributionURLAndPackageID(String originalMetadata, String newURL, String newMetadataID) throws Exception { String newMetadata = null; if (originalMetadata != null) { DocumentBuilder parser = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // factory.setNamespaceAware(true); parser = factory.newDocumentBuilder(); if (parser == null) { throw new Exception("Could not create Document parser in " + "EcogridWriter"); } } catch (ParserConfigurationException pce) { throw new Exception("Could not create Document parser in " + "EcogridWriter: " + pce.getMessage()); } log.debug("after generate dom parser"); Document doc = null; StringReader reader = new StringReader(originalMetadata); InputSource in = new InputSource(reader); log.debug("after generate inputsource"); doc = parser.parse(in); log.debug("after parsing inputsource"); // we assuming the metadata only have one entity String tablePath = Eml200Parser.TABLEENTITY + "/" + DISTRIBUTIONPATH; NodeList tableNodeList = XPathAPI.selectNodeList(doc, tablePath); String rasterPath = Eml200Parser.SPATIALRASTERENTITY + "/" + DISTRIBUTIONPATH; NodeList rasterNodeList = XPathAPI.selectNodeList(doc, rasterPath); String vectorPath = Eml200Parser.SPATIALVECTORENTITY + "/" + DISTRIBUTIONPATH; NodeList vectorNodeList = XPathAPI.selectNodeList(doc, vectorPath); String procedurePath = Eml200Parser.STOREDPROCEDUREENTITY + "/" + DISTRIBUTIONPATH; NodeList procedureNodeList = XPathAPI.selectNodeList(doc, procedurePath); String viewPath = Eml200Parser.VIEWENTITY + "/" + DISTRIBUTIONPATH; NodeList viewNodeList = XPathAPI.selectNodeList(doc, viewPath); String otherEntityPath = Eml200Parser.OTHERENTITY + "/" + DISTRIBUTIONPATH; NodeList otherEntityNodeList = XPathAPI.selectNodeList(doc, otherEntityPath); if (tableNodeList != null && tableNodeList.getLength() != 0) { // have tableEntity log.debug("in data table path for replacement"); setNewValueForNode(tableNodeList, newURL); } else if (rasterNodeList != null && rasterNodeList.getLength() != 0) { setNewValueForNode(rasterNodeList, newURL); } else if (vectorNodeList != null && vectorNodeList.getLength() != 0) { setNewValueForNode(vectorNodeList, newURL); } else if (procedureNodeList != null && procedureNodeList.getLength() != 0) { setNewValueForNode(procedureNodeList, newURL); } else if (viewNodeList != null && viewNodeList.getLength() != 0) { setNewValueForNode(viewNodeList, newURL); } else if (otherEntityNodeList != null && otherEntityNodeList.getLength() != 0) { setNewValueForNode(otherEntityNodeList, newURL); } //replace package id String packagePath = "/*[local-name() = '" + Eml200Parser.EML + "']/@" + Eml200Parser.PACKAGEID; NodeList packageIDNodeList = XPathAPI.selectNodeList(doc, packagePath); setNewValueForAttribute(packageIDNodeList, newMetadataID); // serialize the DOM tree StringWriter writer = new StringWriter(); XMLSerializer serializer = new XMLSerializer(); serializer.setOutputCharStream(writer); // serializer.setOutputByteStream(System.out); serializer.serialize(doc); newMetadata = writer.toString(); // writer.write(newMetadata); log.debug("The new metadata with new data reference is \n" + newMetadata); } return newMetadata; }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
protected Document createDoc() { DocumentBuilder docBuilder = null; try {//from www . ja va 2s . co m docBuilder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { LOG.error(e.getMessage()); return null; } Document doc = docBuilder.newDocument(); return doc; }
From source file:org.exoplatform.services.document.impl.MSXPPTDocumentReader.java
public Properties getProperties(InputStream is) throws IOException, DocumentReadException { try {//w ww . j av a 2 s . c om ZipInputStream zis = new ZipInputStream(is); try { ZipEntry ze = zis.getNextEntry(); while (ze != null && !ze.getName().equals(PPTX_CORE_NAME)) { ze = zis.getNextEntry(); } if (ze == null) return new Properties(); MSPPTXMetaHandler metaHandler = new MSPPTXMetaHandler(); XMLReader xmlReader = SAXHelper.newXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/validation", false); xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); xmlReader.setFeature("http://xml.org/sax/features/namespaces", true); xmlReader.setContentHandler(metaHandler); xmlReader.parse(new InputSource(zis)); return metaHandler.getProperties(); } finally { zis.close(); } } catch (ParserConfigurationException e) { throw new DocumentReadException(e.getMessage(), e); } catch (SAXException e) { throw new DocumentReadException(e.getMessage(), e); } finally { if (is != null) try { is.close(); } catch (IOException e) { if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } } }
From source file:org.exoplatform.utils.ExoDocumentUtils.java
/** * Get the list of folders in a drive, from the HTTP response.<br/> * The response's body is an XM document that is parsed to extract the * information of the folders. <br/> * If <i>isGroupDrive = true</i> , each folder's name is improved to be less * technical, by calling <i>ExoFile#createNaturalName()</i> * /* w ww.j a va 2 s.c om*/ * @param response the HttpResponse from where to extract the list of folders * @param isGroupDrive if <i>true</i> the file's natural name will be created * @return an ArrayList of ExoFile or an empty ArrayList if a problem happens */ public static ArrayList<ExoFile> getDrives(HttpResponse response, boolean isGroupDrive) { // Initialize the blogEntries MutableArray that we declared in the // header ArrayList<ExoFile> folderArray = new ArrayList<ExoFile>(); try { Document obj_doc = null; DocumentBuilderFactory doc_build_fact = null; DocumentBuilder doc_builder = null; doc_build_fact = DocumentBuilderFactory.newInstance(); doc_builder = doc_build_fact.newDocumentBuilder(); InputStream is = ExoConnectionUtils.sendRequest(response); if (is != null) { obj_doc = doc_builder.parse(is); NodeList obj_nod_list = null; if (null != obj_doc) { obj_nod_list = obj_doc.getElementsByTagName("Folder"); for (int i = 0; i < obj_nod_list.getLength(); i++) { Node itemNode = obj_nod_list.item(i); if (itemNode.getNodeType() == Node.ELEMENT_NODE) { Element itemElement = (Element) itemNode; ExoFile file = new ExoFile(); file.name = itemElement.getAttribute("name"); // if (Config.GD_INFO_LOGS_ENABLED) Log.i(" Public file name", file.name); file.workspaceName = itemElement.getAttribute("workspaceName"); file.driveName = file.name; file.currentFolder = itemElement.getAttribute("currentFolder"); if (file.currentFolder == null) file.currentFolder = ""; file.isFolder = true; // create the folder's natural name only for folders // in the group drive if (isGroupDrive) file.createNaturalName(); /* * If file name is "Public", get path for it. */ if (file.name.equals("Public")) { file.path = getRootDriverPath(file); } folderArray.add(file); } } } } } catch (ParserConfigurationException e) { Log.e(" ParserConfigurationException ", e.getMessage()); folderArray = null; } catch (SAXException e) { Log.e(" SAXException ", e.getMessage()); folderArray = null; } catch (IOException e) { Log.e(" IOException ", e.getMessage()); folderArray = null; } return folderArray; }
From source file:org.extensiblecatalog.ncip.v2.aleph.AlephLookupItemService.java
/** * Handles a NCIP LookupItem service by returning data from Aleph. * * @param initData//from w w w .j ava 2 s . c o m * the LookupItemInitiationData * @param serviceManager * provides access to remote services * @return LookupItemResponseData */ @Override public LookupItemResponseData performService(LookupItemInitiationData initData, ServiceContext serviceContext, RemoteServiceManager serviceManager) throws ServiceException { final LookupItemResponseData responseData = new LookupItemResponseData(); boolean itemIdIsEmpty = initData.getItemId().getItemIdentifierValue().isEmpty(); if (itemIdIsEmpty) { Problem p = new Problem(new ProblemType("Item id is undefined."), null, null); responseData.setProblems(Arrays.asList(p)); } else { AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager; try { AlephItem alephItem = alephRemoteServiceManager.lookupItem(initData); // update NCIP response data with aleph item data if (alephItem != null) { updateResponseData(initData, responseData, alephItem); } else { Problem p = new Problem(Version1LookupItemProcessingError.UNKNOWN_ITEM, "", "Item " + initData.getItemId().getItemIdentifierValue() + " was not found."); responseData.setProblems(Arrays.asList(p)); } } catch (IOException ie) { Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(), "Are you connected to the Internet/Intranet?"); responseData.setProblems(Arrays.asList(p)); } catch (SAXException se) { Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (AlephException ae) { Problem p = new Problem(new ProblemType(ae.getShortMessage()), null, ae.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (ParserConfigurationException pce) { Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null, pce.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (Exception e) { Problem p = new Problem(new ProblemType("Unknown processing exception error."), null, StringUtils.join(e.getStackTrace(), "\n")); responseData.setProblems(Arrays.asList(p)); } } return responseData; }
From source file:org.extensiblecatalog.ncip.v2.aleph.AlephLookupUserService.java
@Override public LookupUserResponseData performService(LookupUserInitiationData initData, ServiceContext serviceContext, RemoteServiceManager serviceManager) throws ServiceException { final LookupUserResponseData responseData = new LookupUserResponseData(); String patronId = null;/* w ww . ja va2 s .co m*/ String password = null; boolean authenticationIncluded = false; if (initData.getUserId() != null) patronId = initData.getUserId().getUserIdentifierValue(); else { for (AuthenticationInput authInput : initData.getAuthenticationInputs()) { if (authInput.getAuthenticationInputType().getValue() .equals(Version1AuthenticationInputType.USER_ID.getValue())) { patronId = authInput.getAuthenticationInputData(); } else if (authInput.getAuthenticationInputType().getValue() .equals(Version1AuthenticationInputType.PASSWORD.getValue())) { password = authInput.getAuthenticationInputData(); } } authenticationIncluded = true; } boolean userIdIsEmpty = patronId.isEmpty(); boolean authIsSetAndPwIsEmpty = initData.getAuthenticationInputs() != null && initData.getAuthenticationInputs().size() > 0 && (password == null || password.isEmpty()); if (userIdIsEmpty || authIsSetAndPwIsEmpty) { List<Problem> problems = new ArrayList<Problem>(); if (!authenticationIncluded) { Problem p = new Problem(new ProblemType("User Id is undefined."), null, null, "Element UserIdentifierValue is empty."); problems.add(p); } else { if (userIdIsEmpty) { Problem p = new Problem(new ProblemType("User Id is undefined."), null, null, "Set AuthenticationInputType to \"" + Version1AuthenticationInputType.USER_ID.getValue() + "\" to specify user id input."); problems.add(p); } if (authIsSetAndPwIsEmpty) { Problem p = new Problem(new ProblemType("Password is undefined."), null, "Can't authenticate without password specified.", "Set AuthenticationInputType to \"" + Version1AuthenticationInputType.PASSWORD.getValue() + "\" to specify password input."); problems.add(p); } } responseData.setProblems(problems); } else { if (authenticationIncluded) { // Just authenticate patronId with password input through X-Services .. AgencyId suppliedAgencyId; AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager; if (initData.getInitiationHeader() != null && initData.getInitiationHeader().getToAgencyId() != null) suppliedAgencyId = initData.getInitiationHeader().getToAgencyId().getAgencyId(); else suppliedAgencyId = new AgencyId(alephRemoteServiceManager.getDefaultAgencyId()); try { String username = alephRemoteServiceManager.authenticateUser(suppliedAgencyId, patronId, password); // Later is UserId from initData copied to responseData - we need to overwrite AuthInputs initData.setUserId(createUserId(suppliedAgencyId, username)); AlephRestDlfUser alephUser = alephRemoteServiceManager.lookupUser(username, initData); updateResponseData(initData, responseData, alephUser, alephRemoteServiceManager); } catch (IOException ie) { Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(), "Are you connected to the Internet/Intranet?"); responseData.setProblems(Arrays.asList(p)); } catch (SAXException se) { Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (AlephException ae) { Problem p = new Problem(new ProblemType("Processing AlephException error."), null, ae.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (ParserConfigurationException pce) { Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null, pce.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (Exception e) { Problem p = new Problem(new ProblemType("Unknown processing exception error."), null, StringUtils.join(e.getStackTrace(), "\n")); responseData.setProblems(Arrays.asList(p)); } } else { // Regular lookup User .. AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager; AlephRestDlfUser alephUser = null; try { alephUser = alephRemoteServiceManager.lookupUser(patronId, initData); updateResponseData(initData, responseData, alephUser, alephRemoteServiceManager); } catch (MalformedURLException mue) { Problem p = new Problem(new ProblemType("Processing MalformedURLException error."), null, mue.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (IOException ie) { Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(), "Are you connected to the Internet/Intranet?"); responseData.setProblems(Arrays.asList(p)); } catch (SAXException se) { Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (AlephException ae) { Problem p = new Problem(new ProblemType("Processing AlephException error."), null, ae.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (Exception e) { Problem p = new Problem(new ProblemType("Unknown processing exception error."), null, e.getMessage()); responseData.setProblems(Arrays.asList(p)); } } } return responseData; }
From source file:org.extensiblecatalog.ncip.v2.aleph.AlephRenewItemService.java
@Override public RenewItemResponseData performService(RenewItemInitiationData initData, ServiceContext serviceContext, RemoteServiceManager serviceManager) throws ServiceException { final RenewItemResponseData responseData = new RenewItemResponseData(); boolean itemIdIsEmpty = initData.getItemId() == null || initData.getItemId().getItemIdentifierValue().isEmpty(); boolean userIdIsEmpty = initData.getUserId() == null || initData.getUserId().getUserIdentifierValue().isEmpty(); if (itemIdIsEmpty || userIdIsEmpty) { List<Problem> problems = new ArrayList<Problem>(); if (itemIdIsEmpty) { Problem p = new Problem(new ProblemType("Item id is undefined."), null, null, "Cannot renew unknown item."); problems.add(p);//from ww w .j a v a 2 s. c om } if (userIdIsEmpty) { Problem p = new Problem(new ProblemType("User Id is undefined."), null, null, "Cannot renew item for unknown user."); problems.add(p); } responseData.setProblems(problems); } else { AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager; try { AlephRenewItem renewItem = alephRemoteServiceManager.renewItem(initData); if (renewItem.getProblem() == null) { updateResponseData(responseData, initData, renewItem); } else responseData.setProblems(Arrays.asList(renewItem.getProblem())); } catch (IOException ie) { Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(), "Are you connected to the Internet/Intranet?"); responseData.setProblems(Arrays.asList(p)); } catch (SAXException se) { Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (AlephException ae) { Problem p = new Problem(new ProblemType("Processing AlephException error."), null, ae.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (ParserConfigurationException pce) { Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null, pce.getMessage()); responseData.setProblems(Arrays.asList(p)); } catch (Exception e) { Problem p = new Problem(new ProblemType("Unknown processing exception error."), null, StringUtils.join(e.getStackTrace(), "\n")); responseData.setProblems(Arrays.asList(p)); } } return responseData; }