use of org.xml.sax.InputSource in project OpenMEAP by OpenMEAP.
the class RESTAppMgmtClient method connectionOpen.
public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
ConnectionOpenResponse response = null;
Hashtable postData = new Hashtable();
postData.put(UrlParamConstants.ACTION, "connection-open-request");
postData.put(UrlParamConstants.DEVICE_UUID, request.getApplication().getInstallation().getUuid());
postData.put(UrlParamConstants.APP_NAME, request.getApplication().getName());
postData.put(UrlParamConstants.APP_VERSION, request.getApplication().getVersionId());
postData.put(UrlParamConstants.APPARCH_HASH, StringUtils.orEmpty(request.getApplication().getHashValue()));
postData.put(UrlParamConstants.SLIC_VERSION, request.getSlic().getVersionId());
HttpResponse httpResponse = null;
InputSource responseInputSource = null;
String responseText = null;
try {
httpResponse = requester.postData(serviceUrl, postData);
if (httpResponse.getStatusCode() != 200) {
throw new WebServiceException(WebServiceException.TypeEnum.CLIENT, "Posting to the service resulted in a " + httpResponse.getStatusCode() + " status code");
}
responseText = Utils.readInputStream(httpResponse.getResponseBody(), "UTF-8");
} catch (Exception e) {
throw new WebServiceException(WebServiceException.TypeEnum.CLIENT, StringUtils.isEmpty(e.getMessage()) ? e.getMessage() : "There's a problem connecting. Check your network or try again later", e);
}
// now we parse the response into a ConnectionOpenResponse object
if (responseText != null) {
Result result = new Result();
JSONObjectBuilder builder = new JSONObjectBuilder();
try {
result = (Result) builder.fromJSON(new JSONObject(responseText), result);
if (result.getError() != null) {
throw new WebServiceException(WebServiceException.TypeEnum.fromValue(result.getError().getCode().value()), result.getError().getMessage());
}
} catch (JSONException e) {
throw new WebServiceException(WebServiceException.TypeEnum.CLIENT, "Unable to parse service response content.");
}
response = result.getConnectionOpenResponse();
}
return response;
}
use of org.xml.sax.InputSource in project atlas by alibaba.
the class Configuration method readXmlConfig.
/**
* read args from xml
**/
void readXmlConfig(File xmlConfigFile) throws IOException, ParserConfigurationException, SAXException {
if (!xmlConfigFile.exists()) {
return;
}
System.out.printf("reading config file, %s\n", xmlConfigFile.getAbsolutePath());
BufferedInputStream input = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
input = new BufferedInputStream(new FileInputStream(xmlConfigFile));
InputSource source = new InputSource(input);
factory.setNamespaceAware(false);
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(source);
NodeList issues = document.getElementsByTagName(TAG_ISSUE);
for (int i = 0, count = issues.getLength(); i < count; i++) {
Node node = issues.item(i);
Element element = (Element) node;
String id = element.getAttribute(ATTR_ID);
if (id.length() == 0) {
System.err.println("Invalid config file: Missing required issue id attribute");
continue;
}
if (id.equals(PROPERTY_ISSUE)) {
readPropertyFromXml(node);
} else if (id.equals(DEX_ISSUE)) {
readDexPatternsFromXml(node);
} else if (id.equals(SO_ISSUE)) {
readLibPatternsFromXml(node);
} else if (id.equals(RES_ISSUE)) {
readResPatternsFromXml(node);
} else if (id.equals(PACKAGE_CONFIG_ISSUE)) {
readPackageConfigFromXml(node);
} else if (id.equals(SIGN_ISSUE)) {
if (mUseSignAPk) {
readSignFromXml(node);
}
} else {
System.err.println("unknown issue " + id);
}
}
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
System.exit(-1);
}
}
}
}
use of org.xml.sax.InputSource in project Openfire by igniterealtime.
the class UserSchemaValidator method validateAndParse.
/**
* Perform a validate and a parse of the specified source document.
* Validating is done with the specified schemafiles.
*
* @return A Document when the validation s successful.
*/
Document validateAndParse() {
ValidatorErrorHandler handler = new ValidatorErrorHandler();
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setXIncludeAware(true);
documentBuilderFactory.setValidating(false);
// We don't want xml:base and xml:lang attributes in the output.
documentBuilderFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
documentBuilderFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-language", false);
if (schemaSources.length > 0) {
Log.info("Checking Schema's");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(handler);
Schema schema = schemaFactory.newSchema(schemaSources);
documentBuilderFactory.setSchema(schema);
Log.info("Start validating document");
} else {
Log.info("Loading document");
}
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
handler.reset();
// Communicate some info about the Xincludes in the imported file. These imports should be resolvable by the server.
documentBuilder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
Log.info(String.format("resolved Entity:%s %s", (publicId != null ? publicId : ""), systemId));
return null;
}
});
documentBuilder.setErrorHandler(handler);
Document result = documentBuilder.parse(source);
if (result != null && handler.isValid()) {
return result;
} else {
Log.warn(String.format("document is invalid. %1$d errors found.", handler.getNrOfErrors()));
return null;
}
} catch (Exception e) {
Log.warn(String.format("document validation failed. %1$d errors found.", handler.getNrOfErrors()));
Log.debug("", e);
return null;
}
}
use of org.xml.sax.InputSource in project jmonkeyengine by jMonkeyEngine.
the class SceneMaterialLoader method load.
public MaterialList load(AssetManager assetManager, String folderName, InputStream in) throws IOException {
try {
this.assetManager = assetManager;
this.folderName = folderName;
reset();
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
InputStreamReader r = null;
try {
r = new InputStreamReader(in);
xr.parse(new InputSource(r));
} finally {
if (r != null) {
r.close();
}
}
return materialList;
} catch (SAXException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
} catch (ParserConfigurationException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
}
}
use of org.xml.sax.InputSource in project OpenNotebook by jaltekruse.
the class OldReader method readFile.
public Document readFile(InputStreamReader file) throws SAXException, IOException {
attributeNameInError = null;
attributeValueInError = null;
objectWithError = null;
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(this);
reader.setErrorHandler(this);
reader.parse(new InputSource(file));
if (doc == null) {
if (DEBUG) {
System.out.println("error 1");
}
throw new IOException("improper document format");
}
if (hadAttributeError) {
if (DEBUG) {
System.out.println("error 2");
}
throw new IOException("improper document format, error with attribute '" + attributeNameInError + "' with a value of '" + attributeValueInError + "'" + " in object '" + objectWithError + "'");
}
return doc;
}
Aggregations