1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.apache.openoffice.ooxml.viewer.xml; 23 24 import java.io.InputStream; 25 26 import org.apache.openoffice.ooxml.viewer.KeyListener; 27 import org.apache.openoffice.ooxml.viewer.tokenview.TokenView; 28 29 public class XMLTokenViewFactory 30 extends Thread 31 { XMLTokenViewFactory()32 public XMLTokenViewFactory () 33 { 34 maIn = null; 35 start(); 36 } 37 38 39 40 Create(final InputStream aIn)41 public TokenView<TokenType> Create (final InputStream aIn) 42 { 43 TokenView<TokenType> aView = null; 44 synchronized(this) 45 { 46 maIn = aIn; 47 if (maIn != null) 48 { 49 aView = new TokenView<TokenType>(); 50 aView.addKeyListener(new KeyListener()); 51 maCurrentView = aView; 52 53 FillDocument(); 54 //notify(); 55 } 56 } 57 58 return aView; 59 } 60 61 62 63 64 @Override run()65 public void run () 66 { 67 while(true) 68 { 69 FillDocument(); 70 71 synchronized(this) 72 { 73 if (maIn == null) 74 { 75 try 76 { 77 wait(); 78 } 79 catch (InterruptedException e) 80 { 81 e.printStackTrace(); 82 } 83 } 84 } 85 } 86 } 87 88 89 90 FillDocument()91 private void FillDocument () 92 { 93 final InputStream aIn = maIn; 94 maIn = null; 95 if (aIn != null) 96 { 97 new DocumentTokenFormatter(new XMLScanner(aIn), maCurrentView).Parse(); 98 } 99 } 100 101 102 103 104 private InputStream maIn; 105 private TokenView<TokenType> maCurrentView; 106 } 107