use of javax.xml.parsers.SAXParser in project ACS by ACS-Community.
the class WDALImpl method validateXML.
/**
* Check that everything conforms to the schema in given xml. This check
* will be done by parser used in DAL.
*
* @param xml
*
* @throws AcsJCDBXMLErrorEx
*/
public void validateXML(String xml) throws AcsJCDBXMLErrorEx {
try {
XMLHandler dalSolver = new XMLHandler(true, logger);
SAXParser saxParser = dalImpl.getSaxParser();
saxParser.parse(new InputSource(new StringReader(xml)), dalSolver);
if (dalSolver.m_errorString != null) {
logger.log(AcsLogLevel.NOTICE, dalSolver.m_errorString);
AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx();
e2.setErrorString(dalSolver.m_errorString);
throw e2;
}
} catch (AcsJCDBXMLErrorEx e) {
throw e;
} catch (Throwable t) {
t.printStackTrace();
AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx(t);
throw e2;
//CDBXMLErrorEx xmlErr = new CDBXMLErrorEx(t.toString());
//throw xmlErr;
}
}
use of javax.xml.parsers.SAXParser in project ACS by ACS-Community.
the class CDBDefault method main.
public static void main(String[] args) {
try {
strIOR = null;
if (args.length < 2) {
System.out.println("Usage: cmd <idl_type> <instance_name> [-d ior -h]");
return;
}
m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("CDBDefault", true);
String in_type = args[0];
String in_name = args[1];
curl_allComponents = "MACI/Components";
curl = curl_allComponents + "/" + in_name;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-d")) {
if (i < args.length - 1) {
strIOR = args[++i];
}
}
if (args[i].equals("-h")) {
System.out.println("Usage: cmd idl_type instance_name [-d ior -h]");
return;
}
}
if (strIOR == null) {
strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
}
// create and initialize the ORB
orb = ORB.init(new String[0], null);
WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
String xml = wdal.get_DAO(curl_allComponents);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
XMLHandler xmlSolver = new XMLHandler(false, m_logger);
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
if (xmlSolver.m_errorString != null) {
String info = "XML parser error: " + xmlSolver.m_errorString;
AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
//XMLerror xmlErr = new XMLerror(info);
throw cdbxmlErr;
}
setDefault(xmlSolver.m_rootNode, in_type, in_name);
} catch (AcsJCDBXMLErrorEx e) {
m_logger.log(AcsLogLevel.NOTICE, "Xml Error", e);
e.printStackTrace();
} catch (Exception e) {
m_logger.log(AcsLogLevel.NOTICE, "Error", e);
e.printStackTrace();
}
}
use of javax.xml.parsers.SAXParser in project spring-security-oauth by spring-projects.
the class SparklrServiceImpl method getSparklrPhotoIds.
public List<String> getSparklrPhotoIds() throws SparklrException {
try {
InputStream photosXML = new ByteArrayInputStream(sparklrRestTemplate.getForObject(URI.create(sparklrPhotoListURL), byte[].class));
final List<String> photoIds = new ArrayList<String>();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
parserFactory.setXIncludeAware(false);
parserFactory.setNamespaceAware(false);
SAXParser parser = parserFactory.newSAXParser();
parser.parse(photosXML, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ("photo".equals(qName)) {
photoIds.add(attributes.getValue("id"));
}
}
});
return photoIds;
} catch (IOException e) {
throw new IllegalStateException(e);
} catch (SAXException e) {
throw new IllegalStateException(e);
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
}
use of javax.xml.parsers.SAXParser in project ACS by ACS-Community.
the class XSDElementTypeResolver method initializeParser.
protected void initializeParser() throws ParserConfigurationException, SAXException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
SAXParser saxParser = factory.newSAXParser();
parser = saxParser.getParser();
String schemas = DALImpl.getSchemas(root, logger);
if (schemas == null)
schemas = "";
// do urn to file mapping for schemas
Map<String, File> schemaName2File = new HashMap<String, File>();
StringTokenizer tokenizer = new StringTokenizer(schemas);
while (tokenizer.hasMoreTokens()) {
String urn = tokenizer.nextToken();
String fileName = tokenizer.nextToken();
schemaName2File.put(getXSDElementName(urn) + ".xsd", new File(fileName));
}
uriResolver = new DALURIResolver(schemaName2File, logger);
}
use of javax.xml.parsers.SAXParser in project newsrob by marianokamp.
the class GRAnsweredBadRequestException method getStateChangesFromGR.
private Collection<StateChange> getStateChangesFromGR(long lastUpdated) throws IOException, ParserConfigurationException, SAXException, GRTokenExpiredException, GRAnsweredBadRequestException {
Timing t = new Timing("EntriesRetriever.getStateChangesFromGR()", context);
String url = getGoogleHost() + "/reader/api/0/stream/items/ids";
// &s=deleted/user/-/state/com.google/starred";
url += "?s=user/-/state/com.google/starred";
url += "&s=user/-/state/com.google/read";
url += "&s=" + NEWSROB_PINNED_STATE;
// &s=deleted/user/-/state/com.google/read";
url += "&n=10000&ot=" + lastUpdated;
NewsRobHttpClient httpClient = NewsRobHttpClient.newInstance(false, context);
try {
HttpRequestBase req = createGRRequest(httpClient, url);
HttpResponse response = executeGRRequest(httpClient, req, true);
throwExceptionWhenNotStatusOK(response);
final List<StateChange> stateChanges = new ArrayList<StateChange>(25);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser parser = saxParserFactory.newSAXParser();
DefaultHandler handler = new SimpleStringExtractorHandler() {
private String currentAtomId;
// cache
String googleUserId = null;
@Override
public void receivedString(String localName, String fqn, String s) {
if ("number".equals(localName)) {
long l = Long.parseLong(s);
currentAtomId = TAG_GR_ITEM + U.longToHex(l);
} else if ("string".equals(localName)) {
boolean delete = s.startsWith("delete");
int state = -1;
if (s.endsWith("read"))
state = EntriesRetriever.StateChange.STATE_READ;
else if (s.endsWith("starred"))
state = EntriesRetriever.StateChange.STATE_STARRED;
if (state > -1) {
EntriesRetriever.StateChange sc = new EntriesRetriever.StateChange(currentAtomId, state, delete ? EntriesRetriever.StateChange.OPERATION_REMOVE : EntriesRetriever.StateChange.OPERATION_ADD);
stateChanges.add(sc);
}
}
}
};
parser.parse(NewsRobHttpClient.getUngzippedContent(response.getEntity(), context), handler);
PL.log("Entries Retriever: Number of state changes=" + stateChanges.size(), context);
if (NewsRob.isDebuggingEnabled(context))
PL.log("State Changes: " + stateChanges, context);
return stateChanges;
} finally {
httpClient.close();
t.stop();
}
}
Aggregations